Game Development Community

New to Torque Game Builder. Help would be appreciated.

by Elliot C. · in Torque Game Builder · 10/17/2009 (9:30 pm) · 13 replies

Alright, like my title confirms, I am new to Torque. I'm using Torque for school purposes, and I have a few questions. I'm sorry to rush in with these amateur questions.

1. The very first thing I was wondering, is how I would declare or call a String. I am familiar with "$" meaning a string, however, I noticed that it only functions under "True" or "False". I was wondering if there was a way that I could set it under multiple different words. Ex: $Object = "alive";

2. Another thing that stumped me, was binding keyboard functions. Although I did find a tutorial explaining to write: "moveMap.bindCmd(keyboard, etc. etc.);", I'm not exactly sure how this works.

3. Is it possible to make an object have the exact properties of a different object through scripting?
Before this, I have been working with Visual Basics. In this, you can do something like:
Object.Picture = Object2.Picture
Object.X = Object2.X
Object.Y = Object2.Y

Instead of writing numbers for each change. Is that (or something like that) possible?

Thanks for reading, Again I'm sorry for bothering you guys.

#1
10/17/2009 (9:41 pm)
In the links to the documentation there is a section called "TGB Scripting Language Documentation". These links will answer all of your questions.
#2
10/18/2009 (3:29 pm)
Thanks! That really helped for my last two questions, but I'm still clueless to how to set a string to different words (My first question). "TGB Scrpting Language Documentation" only seems to tell me what "$" means, and what they do, but doesn't tell me how to use them for multiple words. Is there anything I am missing?
#3
10/18/2009 (7:05 pm)
Hi,

I know that the documentation can be really confusing and hard to find (incomplete).

Just like in Visual Basic you don't need to declare the variable and give it a type.
%MyString = "my string";

You can do operations like

%MyString = "This is" SPC %MyString;

If you want to do a test you need to tell it that it is a string test.

%Level = "First";
if (%Level $= "First")

and same for switch:

switch$(%Level) {

  case "First":

  case "Second":

}

I don't know if this was what you asked for but I hope it gave you something...
#4
10/18/2009 (7:55 pm)
Well, I'm not even sure if that's what I need, but here's what I'm trying to do:

I'm creating a game with a character selection menu. On the menu, there are three characters the player may choose from. There is probably an easier way to do this, but this is what I am trying to do;

If the player picks the first character, I was thinking I could set a variable as a string so that: $Character = "character1";
If the player picks the second character, It would be: $Character= "character2"; and so on and so forth.

I have tried that, but it doesn't seem to function. The only things that it works for are "True"; and "False";

Maybe there is a completely different way to do it, but at the moment, Torque and it's scripting language is completely alien to me. I'm sorry for asking so much.
#5
10/18/2009 (8:18 pm)
It is hard to understand what's going wrong without seeing your code.
How does the player select the character? GUI?
How do you detect the players selection?
How do you set your variable?
#6
10/18/2009 (8:22 pm)
Elliot,

$Character = "Bob"; should work fine, but note:

Where you're putting the $ in that statement doesn't make it a string, it makes it GLOBAL in scope.
$Character = "Character1";
echo($Character);
Should print out "Character1" to your output.
When you say it only works for True and False, it makes me think your issue is likely in TESTING the string. Here is where you need a '$' in there.
If you test like this:
$Character = "CharacterName";
if($Character == "CharacterName")
     dosomestuff();
It will ALWAYS be true unless you ask if it == "True" (i.e. all strings but "True" evaluate as 0 when tested with ==).
echo(0 == "Character1");
prints a "1". True.
What you want is to test like this:
$Character = "CharacterName";
if($Character $= "CharacterName")
     dosomestuff();
That'll test the two strings ok... in a case insensitive fashion.
Safer still for strings is
$Character = "CharacterName";
if(!strcmp($Character,"CharacterName"))
     dosomestuff();
#7
10/18/2009 (8:27 pm)
btw,

inside a function (or outside of one within a script file) all of the above can be done with "%Character" instead of "$Character". You use '%' for LOCAL variables that you won't need later or elsewhere.

Something as everywhere as your character's name is probably a good thing to have global though (unless you're one of those "good" programmers that worries about things like encapsulation and data hiding... bleh.)

Hope that helps!

-Tim
#8
10/18/2009 (9:06 pm)
Sorry I'm editing out this post. For I don't know how to delete it. ><
#9
10/18/2009 (9:27 pm)
Tim,
Thanks for the advice, it did help, but it didn't clarify everything.
I quickly made a very small level in an attempt to explain my problem in a simple way. (Note that I don't know how to post code in those lists... I am new to this forum as well..)

function player::onLevelLoaded(%this, %scenegraph)
{
$Thing = "Up";
moveMap.bindCmd(keyboard, "space", "moveObject();","");
}

function moveObject ()
{
if ($Thing $= "Up";)
{
object.Position = "-23, -66";
}
if ($Thing $= "Down";)
{
object.Position = "-18, 55";
}
if ($Thing $= "Side";)
{
object.Position = "76 -13";
}
}

Now in the game builder, I placed an object in the middle of the screen. I called it "object" respectivly. When I press the space key, the object should position itself either at the top, bottom, or side of the screen, depending on $Thing. Unfortunalty, this does not work. At the top where I declared "$Thing = "Up";", I changed Up to Down and Side, and tested it all three times, but all it seemed to do was always move to the top of the screen. Never to the bottom or the side.

I'm beginning to have the feeling I'm doing something completely and utterly wrong. I was trying to use what I know with Visual Basics to apply here, but it doesn't seem to work that way. I hope you understand this, but if not, then that would be my fault. I am only a student just beginning to learn, so I have many things I do not know.
#10
10/18/2009 (9:52 pm)
is object the name of an object in the world? Otherwise it will not go anywhere.

Generally, you can find this kind of issues automatically by just opening the console or what I would recommend: invest in torsion and run it through debug there.
#11
10/19/2009 (12:44 am)
Hey,

in "if ($Thing $= "Up";)"

You really need to NOT have the ';' at the end within the ')'...

That'll break it for sure... (I'm surprised it compiles?)

Check when you run (or use Torsion for crying out loud!!) that there's no red when you check out the console after running your game. '~' is your friend.

-T
#12
10/19/2009 (5:19 pm)
@ Tim,

You were absolutely right! Thanks! That semi-colon was the problem. I will attempt to invest in Torsion like Marc suggested.

That finishes all my questions for the moment.

Thanks to everyone who helped out. I appreciate the help alot.
#13
10/20/2009 (12:10 pm)
also, whenever you need to test for multiple things or something, its better to use a "Switch" sentence instead of a lot of "ifs".

in your case:
Switch$(%character)
{
    case "char1":
        //do something
    case "char2":
        //do something
    ...
    case "char_n":
        //do something
}