Newgrounds.com — Everything, By Everyone.

Checking login status…

USERNAME:

PASSWORD:

Logging in…

Logged in as:
.
Logging out…
Inbox My Account Log Out


Forum Topic: Scoring

(97 views • 19 replies)

This topic is 1 page long.

<< < > >>
Crying

pancake0Dean

Reply To Post Reply & Quote

Posted at: 6/24/08 05:25 PM

pancake0Dean LIGHT LEVEL 05

Sign-Up: 04/17/05

Posts: 190

AID ME! (please)

ok so I've got a scoring "engine" in, a dynamic text box with numbers in that change depending on items picked up, right? But I want the game "stop" after a certain amount of points are obtained. So I tried this code:

if(score = 60){
_root.gotoAndStop(2)
}

But I guess that doesn't work. The score variable name is score... if you didn't guess.

Thanks! =D


None

2-3-ryan-5

Reply To Post Reply & Quote

Posted at: 6/24/08 05:31 PM

2-3-ryan-5 LIGHT LEVEL 05

Sign-Up: 02/10/08

Posts: 109

try this:

if (score >= 59) {
_root.gotoAndStop(2)
}

see if that helps

Flash ROCKES!!!!!! My E-mail

BBS Signature

None

Gutya

Reply To Post Reply & Quote

Posted at: 6/24/08 05:34 PM

Gutya FAB LEVEL 07

Sign-Up: 11/27/06

Posts: 777

Your problem lies here:

if (scoring = 60) {

= is used for assigning values.

== is used for comparing values.

Therefore you should be using:

if (scoring == 60) {

None

pancake0Dean

Reply To Post Reply & Quote

Posted at: 6/24/08 05:36 PM

pancake0Dean LIGHT LEVEL 05

Sign-Up: 04/17/05

Posts: 190

At 6/24/08 05:31 PM, 2-3-ryan-5 wrote: try this:

if (score >= 59) {
_root.gotoAndStop(2)
}

see if that helps

Nope nothing.

Thanks for trying though. Any other ideas?


None

Gutya

Reply To Post Reply & Quote

Posted at: 6/24/08 05:37 PM

Gutya FAB LEVEL 07

Sign-Up: 11/27/06

Posts: 777

Sorry about that, for some reason I used 'scoring' instead of 'score'.


None

pancake0Dean

Reply To Post Reply & Quote

Posted at: 6/24/08 05:47 PM

pancake0Dean LIGHT LEVEL 05

Sign-Up: 04/17/05

Posts: 190

Still not working :S

I think maybe I'm doing something wrong.

This is in my first frame:
score = 0

if(_root.score == 60){
_root.gotoAndStop(2)
}

Then a button which has:
on(release){
_root.score += 20;
}

And I've got the dynamic text box.

Anything?


None

OneWhoListens

Reply To Post Reply & Quote

Posted at: 6/24/08 05:52 PM

OneWhoListens LIGHT LEVEL 19

Sign-Up: 08/23/06

Posts: 1,266

At 6/24/08 05:47 PM, pancake0Dean wrote: Still not working :S

I think maybe I'm doing something wrong.

This is in my first frame:
score = 0

if(_root.score == 60){
_root.gotoAndStop(2)
}

Then a button which has:
on(release){
_root.score += 20;
}

And I've got the dynamic text box.

Anything?

I'm assuming you're putting semicolons at the end of each command, and just leaving it off when you're typing on the forums, right?
Like:
_root.gotoAndStop(2);
Adding ";".
Also after score=0.
Just thought I'd check.


None

pancake0Dean

Reply To Post Reply & Quote

Posted at: 6/24/08 05:56 PM

pancake0Dean LIGHT LEVEL 05

Sign-Up: 04/17/05

Posts: 190

At 6/24/08 05:52 PM, OneWhoListens wrote:
At 6/24/08 05:47 PM, pancake0Dean wrote: Still not working :S

I think maybe I'm doing something wrong.

This is in my first frame:
score = 0

if(_root.score == 60){
_root.gotoAndStop(2)
}

Then a button which has:
on(release){
_root.score += 20;
}

And I've got the dynamic text box.

Anything?
I'm assuming you're putting semicolons at the end of each command, and just leaving it off when you're typing on the forums, right?
Like:
_root.gotoAndStop(2);
Adding ";".
Also after score=0.
Just thought I'd check.

Haha Yeah, I've got the ";" in.

Would have thrown up an error if it didn't, wouldn't it?

Instead for me just nothing happens...


Goofy

zrb

Reply To Post Reply & Quote

Posted at: 6/24/08 05:57 PM

zrb LIGHT LEVEL 09

Sign-Up: 08/08/06

Posts: 3,821

if(_root.score == 60){

Take out the "_root" because the variable is in the frame you put that if statement.

I can speak french :3 || As :Main || As3: Main || Animation: Main || Flash Tutorials ||

BBS Signature

None

OneWhoListens

Reply To Post Reply & Quote

Posted at: 6/24/08 05:59 PM

OneWhoListens LIGHT LEVEL 19

Sign-Up: 08/23/06

Posts: 1,266

Alright, then, two things. One, is the dynamic textbox set to pick up _root.score or just score. I'm not sure if it makes a difference but it could and makes for cleaner code anyway.
And two, try tracing _root.score and see what you get. Does it change?


None

pancake0Dean

Reply To Post Reply & Quote

Posted at: 6/24/08 06:08 PM

pancake0Dean LIGHT LEVEL 05

Sign-Up: 04/17/05

Posts: 190

I've tried taking out and adding "_root"s and no luck. I might just give up on this plan. It wasn't a very crucial part of the game, was just interested.

Feel free to keep trying to help though.


None

OneWhoListens

Reply To Post Reply & Quote

Posted at: 6/24/08 06:14 PM

OneWhoListens LIGHT LEVEL 19

Sign-Up: 08/23/06

Posts: 1,266

Grrr...I hate it when things should work but don't. I know how you feel. Did you try tracing it? What did it come up with?


None

pancake0Dean

Reply To Post Reply & Quote

Posted at: 6/24/08 06:24 PM

pancake0Dean LIGHT LEVEL 05

Sign-Up: 04/17/05

Posts: 190

I traced score and it's working fine. It must be something in this bit of code:

if(_root.score == 60){
_root.gotoAndStop(2);
}


None

OneWhoListens

Reply To Post Reply & Quote

Posted at: 6/24/08 06:48 PM

OneWhoListens LIGHT LEVEL 19

Sign-Up: 08/23/06

Posts: 1,266

At 6/24/08 06:24 PM, pancake0Dean wrote: I traced score and it's working fine. It must be something in this bit of code:

if(_root.score == 60){
_root.gotoAndStop(2);
}

Try putting a random line of code that you know works inside the statement. Even another trace would work. This would at least let you see which part isn't working, the equation test or the command.


None

putzpie

Reply To Post Reply & Quote

Posted at: 6/24/08 07:05 PM

putzpie NEUTRAL LEVEL 08

Sign-Up: 11/25/07

Posts: 2,171

try making score a global instead. (if it isn't already)
So when you declare it just make it

_global.score = 0;

and change the "_root"s to "_global"
if score is already a global, then just change the _root to _global

My site
Click here to proceed to decapitate small children with wii remotes
If you didn't start out on the PSX, you're not a gamer >:(

BBS Signature

None

pancake0Dean

Reply To Post Reply & Quote

Posted at: 6/24/08 07:06 PM

pancake0Dean LIGHT LEVEL 05

Sign-Up: 04/17/05

Posts: 190

I added a trace in the middle and nothing. So it's definatly that bit.

if(_root.score == "60"){
trace ("Hello");
_root.gotoAndStop(2);
}

The "Hello" doesn't show up...


None

putzpie

Reply To Post Reply & Quote

Posted at: 6/24/08 07:10 PM

putzpie NEUTRAL LEVEL 08

Sign-Up: 11/25/07

Posts: 2,171

At 6/24/08 07:06 PM, pancake0Dean wrote: I added a trace in the middle and nothing. So it's definatly that bit.

if(_root.score == "60"){
trace ("Hello");
_root.gotoAndStop(2);
}

The "Hello" doesn't show up...

Try changing score to a global (like I already said) and then make it check "_global.score" instead of _root.

My site
Click here to proceed to decapitate small children with wii remotes
If you didn't start out on the PSX, you're not a gamer >:(

BBS Signature

None

OneWhoListens

Reply To Post Reply & Quote

Posted at: 6/24/08 07:10 PM

OneWhoListens LIGHT LEVEL 19

Sign-Up: 08/23/06

Posts: 1,266

Hmm...thinking here. Try adjusting it so that it reacts at 20 instead of 60, see if it works. I don't know what that will tell us exactly, but it will refine it a bit, and we seem to be getting closer.


None

Coronus42

Reply To Post Reply & Quote

Posted at: 6/24/08 07:15 PM

Coronus42 NEUTRAL LEVEL 07

Sign-Up: 05/04/08

Posts: 10

At 6/24/08 05:47 PM, pancake0Dean wrote: Still not working :S

I think maybe I'm doing something wrong.

This is in my first frame:
score = 0

if(_root.score == 60){
_root.gotoAndStop(2)
}

Then a button which has:
on(release){
_root.score += 20;
}

And I've got the dynamic text box.

Anything?

My only question is this: Is the score checking code reachable after the frame loads? If it's just sitting on the frame code outside of a function or event handler it's not going to be run through again. I'd do something like this:

button1.onRelease = function():Void {
addScore(20);
}
function addScore(s:Number):Void {
score += s;
if(score >= 60) {
gotoAndStop(2);
}
}

Happy

Bezman

Reply To Post Reply & Quote

Posted at: 6/25/08 08:06 AM

Bezman FAB LEVEL 29

Sign-Up: 08/16/01

Posts: 2,601

At 6/24/08 07:15 PM, Coronus42 wrote: If it's just sitting on the frame code outside of a function or event handler it's not going to be run through again. I'd do something like this:

That's the answer. Code on a frame is only run when the frame loads.

To have some code that runs ever frame, I personally make a shape off-stage, make it an mc then give it the code

onClipEvent(enterFrame){
  //put the score-checking code or anything else that should happen every frame here
}

Simple, but effective.

I still use the original AS though (still using Flash MX), so assuming you're more up-to-date than I, Coronus' method may be better.


All times are Eastern Daylight Time (GMT -4) | Current Time: 04:07 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!