PDA

View Full Version : Nathan's Gaming Tutorial - Problems



Chavs
December 29th, 2005, 12:24 PM
Hello,

First off to start with, its a great tutorial, don't get me wrong! But I am having a problems that I would like to be resolved!

The scoring bit isnt going down too neatly, when I do the code you have written, it keeps on adding 5. Not in the right way.

e.g.
score.text = 0, coins give an extra 5 points, but it shows up like:
055555, rather than 25.

Also, the fact that the variable is set to as score.text makes me curious, as shouldnt it be a numerical variable rather than text?

TheCanadian
December 29th, 2005, 02:36 PM
I haven't actually read the tutorial but I think I may know your problems.

In Flash, the operator for addition (+) is also the operator for concatenation. Thus:

5+5 will give you 10
"5"+"5" will give you 55
"5"+5 will give you 55

Since the addition and concatenation operators are the same, if Flash finds a string literal in one such operation it will assume that you are trying to concatenate the expressions together. The solution to this would be to use the Number function. This will tell flash to convert the passed expression to it's numerical representation:

Number("5")+Number("5") will give you 10

For more info on this function, see the help file.






score is a variable holding a reference to a TextField. text is a property of this text field (and all text fields for that matter). It allows you to get or set the text in text field, as a string. And herein lies your first problem which is, hopefully, explained above.