Copy link to clipboard
Copied
So I have this piece of code which allows for a score to be displayed in my game
var plScore:int = 0;
score_txt.text = plScore.toString();
It then updates by 1 when the player collects an item
plScore +=1;
score_txt.text = plScore.toString();
It works fine however I want to know what "toString()" is and how it works in the context of this set of code as all I really know is that it allows for the numbers to be displayed as text in the level but I am unsure how it does it.
Copy link to clipboard
Copied
it's just converting file type from (in your code, an int to a string). casting does the same:
var plScore:int=0;
score_txt.text=String(plScore);
Copy link to clipboard
Copied
Ah ok thanks. Could you please briefly explain how "string" works int the context of this code, like how does it allow for the numbers to be displayed as text?
Copy link to clipboard
Copied
i don't understand what you are asking but maybe this will help.
you could try:
score_txt.text = plScore;
and read the ensuing error message. perhaps that will help you understand why casting or using toString is needed.
or you may have a more profound question about why adobe engineers/developers chose to have textfields display strings only. or maybe you don't understand 'typing' and need some help with a more basic understanding of programming principles. like i stated in the first sentence, i don't understand what you're asking.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now