Game Development Community

Help with a simple TS example.

by Russell Buxton · in Technical Issues · 01/01/2008 (12:00 pm) · 4 replies

Hello...I am new to TS and i'm trying to learn some very basic concepts.
I have gone through some of the tutorials"Fish Game" and "Shooter".I got alot out of them but i'm still unsure about some things.I have made a new project to practice on learning how functions and variables work and how to get and pass them between functions.My level has three shapes that are simple static sprites I made in PS.I have enabled mouse events in the "game.cs" and on all three of the objects in their class scripts.These are my class script files...
function triangle_class::onLevelLoaded(%this)
{
%this.setUseMouseEvents(true);
$value=0;
}

function triangle_class::onMouseUP(%this)
{
if($value>=10)
{
$value=0;
echo("You clicked the triangle!");
echo($value);
%TV = %this.triangle_value;
echo(%TV);
}
else if($value<10)
{
$value+=2;
echo("You clicked the triangle!");
echo($value);
} 
}
This script is the same for all three objects except for the lines about %TV and $value initialized to 0.The triangle_value is a dynamic field I added to the triangle in the editor but it's not getting processed for some reason.Everything else is working.You can click on objects and see $value get 2 added to it each time until 10 where it will reset to 0.
Ok...some questions:(1)Are all variables with the prefix "%" local to this class script?If not, whats the method for passing them to other class member functions?(2)How could I pass the $value to the other classes or objects in the scenegraph?As an example:when I click the triangle have it pass $value to square class,then square class to octogon class so that "echo($value) would return 6, all with just one click?(3)I would like to add a "text" object in the editor and pass variables to it instead of the console so I don't have to keep opening and closing it.(4)I noticed in the tutorials that functions are done differently sometimes.As an example...
"function class_name::onLevelLoaded(%this)"...as oppossed to just "function name()".Whats the difference between the two?Ok...enough for now...:).I'll keep at it in the meantime.Thanx for any help.

#1
01/01/2008 (2:14 pm)
1: % is used for local variables.
2: $ is a global variable
3: Make a GUI Text type object, then do a command GUIObject.settext("whatever you want");
4: if a class name is listed, it's class based, meaning that objects have their own set of commands.
Example

Cat::Speak(){
echo("meow");
}

Dog::Speak(){
echo("woof");
}

Speak(){
echo("unable to speak");
}


if you have a cat object named fluffy, in script you can do fluffy.speak(); to get a response that only objects based off Cat can do.
#2
01/01/2008 (2:47 pm)
Thanx Ramen...Ok that clears up why what I was trying to do was not working.What if in the example above I wanted to know what value a variable in say an object in "Cat" class had from within "Dog"s class script.Would it have to be a global variable or is there another way?Maybe someone would be kind enough to post some example code of three or four different class objects passing a variable back and forth several timeswith different methods.This would help me very much in learning how functions are created and called from class to class.Thanx for any help...it is much appreciated.
#3
01/01/2008 (3:44 pm)
Thanx Ramen...Ok that clears up why what I was trying to do was not working.What if in the example above I wanted to know what value a variable in say an object in "Cat" class had from within "Dog"s class script.Would it have to be a global variable or is there another way?Maybe someone would be kind enough to post some example code of three or four different class objects passing a variable back and forth several timeswith different methods.This would help me very much in learning how functions are created and called from class to class.Thanx for any help...it is much appreciated.
#4
01/01/2008 (5:09 pm)
LOL..oh crap.I guess noone else noticed either.Look at the first line of code in my first post.I forgot to put "%scenegraph" in.I knew i was'nt crazy!What I was doing was actually right.Man I spent all day looking at it till I noticed...LOL.I still havent been able to go from class to class with functions but i'm closer now than I was.