Game Development Community

okay, what's the secrete to displaying variables?

by Brandon Store89 · in Torque Game Builder · 02/10/2009 (8:11 pm) · 3 replies

I've been having a hard time with displaying score. I have looked at tutorials and couldn't find help. I made a text object, the text says "Score:" and its class name is "score" here is my code its in its own file called score.cs and it is executed in the main.cs (I always check that first when I have a problem lol)


function score::onLevelLoaded(%this, %scenegraph)
{
$score = 0;
%this.owner.text = "Score:" SPC $score;
}

As you can see I am not even at the step to update the score, I've been trying for 2 days just for the game to display the value 0. I'm in C++ class at school, and I know Torque Script isn't C++ but doing it like this seems like the simplest logical way to do it, yet its obviously the wrong way. So am I simply off by a line or two of code? Or did I have the wrong idea, right from the start? And I do believe in learning by figuring out, so if you want to hint at what to do, rather then coming out and saying it blunt, by all means I don't mind. =D Thanks in advance

-brandon

#1
02/10/2009 (9:30 pm)
Is "score" a behavior or is it a class?

If it is just a regular class, then you can remove ".owner" from your text assignment:

%this.text = "Score:" SPC $score;

Welcome to the forums, btw!
#2
02/10/2009 (10:01 pm)
its a class not a behavior. I removed the ".owner" but my 0 variable still isn't appearing next to it :/ right now my code for score is this

function score::onLevelLoaded(%this, %scenegraph)
{
$score = 0;
%this.text = "Score:" SPC $score;
}

is their anything els I should add to this? Is their a GUI I need to make? and thanks for your help so far and welcoming me to the forums =D, I appreciate it

-brandon
#3
02/10/2009 (10:15 pm)
AHHHHH nevermind, you were right. I made a rookie mistake from the start. I checked my main.cs and I did type in the execute script line almost perfect lol

exec(".gameScripts/score.cs");

changed it to

exec("./gameScripts/score.cs");

okay so anyway, making that tweak to my function that you suggested did work, it now displays 0. Thanks a lot!!!

-brandon