Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-07-2012, 02:07 PM   #1
szymek.k3
Member
 
Join Date: Feb 2012
Posts: 61
Default [AS3] assigning game score to a dynamic text

Hello
In my game I want to add score, I have created a variable named score and succesfully added the score number in the main game loop. I traced it to see if it increases and it does.

Now I want to show the score to the user and I created a new movieclip named "xScore", in it I made a dynamic text box and given it an instance name - "gameScore".
In my game class I declared the gameScore variable:
Code:
public var gameScore:xScore;
Then created the text box in the game constructor:
Code:
gameScore = new xScore();
			gameScore.x=10;
			gameScore.y=10;
			addChild(gameScore);
Finally I tried to show the score varaible in my main game loop:
Attempt 1:
Code:
gameScore.text=score;
Attempt 2:
Code:
gameScore.text=score.toString();
None worked and I don't get any errors, the random number i typed in the dynamic text box doesn't change, I also tried to leave it blank, which didn't work either.

Last edited by szymek.k3; 04-08-2012 at 11:27 AM.
szymek.k3 is offline   Reply With Quote
Old 04-07-2012, 03:10 PM   #2
Biodiscus
Immma firing Ninnnnjaaa
 
Join Date: Aug 2011
Posts: 95
Default

Try:
ActionScript Code:
gameScore.text = ""+score; //Or gameScore.text = String(score);
Biodiscus is offline   Reply With Quote
Old 04-07-2012, 03:28 PM   #3
szymek.k3
Member
 
Join Date: Feb 2012
Posts: 61
Default

Even when I put in:
Code:
gameScore.text ="Score: "+score;
The "Score:" didn't show, so I'm guessing there must be something wrong when I'm creating the dynamic text.
szymek.k3 is offline   Reply With Quote
Old 04-08-2012, 08:28 AM   #4
Biodiscus
Immma firing Ninnnnjaaa
 
Join Date: Aug 2011
Posts: 95
Default

How do you make the gameScore? And how do you make the score variables?
Biodiscus is offline   Reply With Quote
Old 04-08-2012, 11:26 AM   #5
szymek.k3
Member
 
Join Date: Feb 2012
Posts: 61
Default

My first post explains gameScore:
Quote:
Originally Posted by szymek.k3 View Post
Hello
In my game I want to add score, I have created a variable named score and succesfully added the score number in the main game loop. I traced it to see if it increases and it does.

Now I want to show the score to the user and I created a new movieclip named "xScore", in it I made a dynamic text box and given it an instance name - "gameScore".
In my game class I declared the gameScore variable:
Code:
public var gameScore:xScore;
Then created the text box in the game constructor:
Code:
gameScore = new xScore();
			gameScore.x=10;
			gameScore.y=10;
			addChild(gameScore);
Finally I tried to show the score varaible in my main game loop:
Attempt 1:
Code:
gameScore.text=score;
Attempt 2:
Code:
gameScore.text=score.toString();
None worked and I don't get any errors, the random number i typed in the dynamic text box doesn't change, I also tried to leave it blank, which didn't work either.
This is how I made the score variable:

Game Class:
Code:
public var score;
Game Constructor:
Code:
score=0;
Main Game loop:
Code:
score+=1;
         trace(score);
This all works fine until I have to show this variable to the user using dynamic text.
szymek.k3 is offline   Reply With Quote
Old 04-10-2012, 10:08 AM   #6
szymek.k3
Member
 
Join Date: Feb 2012
Posts: 61
Default

Any help is greatly appreciated!
szymek.k3 is offline   Reply With Quote
Old 04-10-2012, 10:04 PM   #7
szymek.k3
Member
 
Join Date: Feb 2012
Posts: 61
Default

I solved it! Well with a little hint from somebody

I had to change the way I displayed the text - not through a movieclip.

Game Class
Code:
public var gameScore:TextField = new TextField();
Game Constructor
Code:
addChild(gameScore);
Main Game Loop
Code:
gameScore.text ="Score: "+score;
szymek.k3 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:39 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.