View Full Version : Simple Dynamic Text Problem
Sythen
July 6th, 2009, 10:45 PM
Hey guys,
I'm new to the Kirupa forums, so hey :) x
I'm working on a small flash based game called "Nini" and so far everything's going great. Till I hit a snag. Basically, I have a dynamic text field with the var of "total". I have also put text in this with the number "0". Then, I have a small button (blue rabbit) that has the following code:
on (release) {
_root.total = _root.total + 10;
}
So, the total value in the dynamic text field should change from 0, to 10, and every time it's pressed increase by 10 correct? Then why after three presses of the button do I get:
0101010...
rather than...
30...
This is really beginning to bug me, if anyone could help me out, that would be great.
I have published the problem to an swf and html: www.scottbaker.eu/Nini/Nini2.html
Thanks,
Scott.
flyingmonkey456
July 6th, 2009, 11:01 PM
Hey guys,
I'm new to the Kirupa forums, so hey :) x
I'm working on a small flash based game called "Nini" and so far everything's going great. Till I hit a snag. Basically, I have a dynamic text field with the var of "total". I have also put text in this with the number "0". Then, I have a small button (blue rabbit) that has the following code:
on (release) {
_root.total = _root.total + 10;
}
So, the total value in the dynamic text field should change from 0, to 10, and every time it's pressed increase by 10 correct? Then why after three presses of the button do I get:
0101010...
rather than...
30...
This is really beginning to bug me, if anyone could help me out, that would be great.
I have published the problem to an swf and html: www.scottbaker.eu/Nini/Nini2.html
Thanks,
Scott.
are you using quotes somewhere? because that would turn it into a string and cause your problem. also, use _root.total += 10, it's less likely to get screwed up.
bluemagica
July 6th, 2009, 11:04 PM
clear the var field, and give the textbox a instance name instead! say, "tbox", now do the following:
on (release) {
_root.total+=10;
_root.tbox.text = ""+_root.total;
}
Your actual problem is, the variable is being treated as a string, and "+" operator attaches strings, so its attaching "10" as string each time to the end of the previously existing string, instead of adding it as a number!
therobot
July 6th, 2009, 11:06 PM
umm. because the textfield needs a string.
try keeping a separate variable for your score.
[code]
var score:Number = 0;
// put this code on yr button!
on(release){
_root.score = _root.score + 10;
// you can also write:
//_root.score += 10;
// now update your textfield based on the value of the variable score!
_root.myTextField.text = _root.score;
}
Sythen
July 6th, 2009, 11:11 PM
Wow! thanks very much for the quick reply guys. :D x
EDIT: I've tried it all, and now I just get NaN in the box.. :S
flyingmonkey456
July 6th, 2009, 11:12 PM
i did it and it worked fine. in the frame, i put var output = 0;. a made a text field and set the variable to _root.output. then i created a rectangle and turned it into a mc and put the following code in it:
on(release){
_root.output += 10;
}
it worked exactly as you want it to. try to copy what i just said.
Sythen
July 6th, 2009, 11:20 PM
That did the trick! Thank you very much,
Alright, I have one last question, say if I had 5 gears on the screen,
how do I make the button (the blue bunny) make a check to see if
the player has picked up all of the gears?
Scott.
bluemagica
July 6th, 2009, 11:22 PM
Have a counter variable initialised to 5! each time player picks up the gear, subtract 1 from it, then you just have to check if its greater than or equal to 0!
flyingmonkey456
July 6th, 2009, 11:25 PM
That did the trick! Thank you very much,
Alright, I have one last question, say if I had 5 gears on the screen,
how do I make the button (the blue bunny) make a check to see if
the player has picked up all of the gears?
Scott.
have a variable called collected_gears and every time a gear is picked up, add 1 to that. have another variable called total_gears and set that to 5, or how ever many gears are on the screen in that particular level. keep checking if they're equal with an if statement and put the code you want to happen when all the gears are collected there.
Sythen
July 6th, 2009, 11:30 PM
Than you all so much! I can finally continue on with creating Nani, thank you again!
Scott.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.