Author Topic: Need help learning torque  (Read 1959 times)

I heard that looking at a script "helps" you learn torque, but where can I really start for beginners? I only know python and it isn't compared to torque. If a script is helpful, can you recommend me one or post it below. THANKS A LOT

I just looked at add-ons and online tutorials.

Looking at the default add-ons specifically (jeep, gun...) is a great way to start.

Looking at small scripts actually helps, since you can try to figure how it works, and what it does.

First off, the syntax is completely different. Almost nothing you know from python can be applied to torquescript, just because of how wonky a language it is. Things like recursion, function calling and the likes exist in torque but are done differently due to the syntax differences.

So I suggest forgetting everything you think you know about programming languages because pretty much none of it will hold true in torquescript compared to python.

First off, the syntax is completely different. Almost nothing you know from python can be applied to torquescript, just because of how wonky a language it is. Things like recursion, function calling and the likes exist in torque but are done differently due to the syntax differences.

So I suggest forgetting everything you think you know about programming languages because pretty much none of it will hold true in torquescript compared to python.

Did you read what I put? I know that already.

Look for Iban's tutorials for the syntax basics.

Did you read what I put? I know that already.
I'm saying it's worse than you think.

How do you make a minigame, I'd understand that

Code: [Select]
function BuildMinigame()
{
if(isObject(Mini))
{
for(%i = 0;%i < ClientGroup.getCount();%i++)
{
%subClient = ClientGroup.getObject(%i);
Mini.removeMember(%subClient);
}

Mini.delete();
}
else
{
for(%i = 0;%i < ClientGroup.getCount();%i++)
{
%subClient = ClientGroup.getObject(%i);
%subClient.minigame = NULL;
}
}

I mean what? What does %i mean is it just a variable and what does the ++ do. Should I start on something different or does someone want to break down what it means

Look for Iban's tutorials for the syntax basics.

I tried that, (I even took notes). Some of it, I can't grasp the concept, like tick. What does tick mean! Things like that get left out of the explanation.


I'm saying it's worse than you think.

Oh okay sorry,

%i++ adds one to the variable

for example:

Code: [Select]
function serverCmdAddsomething(%client)
{
%someVariable++;
}

would add 1 to someVariable everytime serverCmdAddsomething was used.
« Last Edit: July 19, 2014, 01:53:51 AM by Darksaber2213 »

I tried that, (I even took notes). Some of it, I can't grasp the concept, like tick. What does tick mean! Things like that get left out of the explanation.

It sounds like a variable name or a function name. What was the context? It can mean whatever the author of the code wants it to mean.

Also, we have some great tutorials over here: http://scatteredspace.com/forum/index.php?board=58.0

%i++ adds one to the variable

for example:

Code: [Select]
function serverCmdAddsomething(%client)
{
%someVariable++;
}

would add 1 to someVariable everytime serverCmdAddsomething was used.

Thanks!

It sounds like a variable name or a function name. What was the context? It can mean whatever the author of the code wants it to mean.

Also, we have some great tutorials over here: http://scatteredspace.com/forum/index.php?board=58.0

And I'll look into that more thoroughly maybe next week because I can use the school's tablet to take notes (also it's night time xd). Please look forward for more posts from me on this section.

would add 1 to someVariable everytime serverCmdAddsomething was used.
No it wouldn't, you're using a local variable so it will be 1 after ++ every time, and gone after the command is finished.

No it wouldn't, you're using a local variable so it will be 1 after ++ every time, and gone after the command is finished.
Yeah. For that situation, you would want to use a global variable to make it go up ever time you called it. ($ are global variables and % are local).

More stuff on variables:
Most of the time, you will use a local variable (%) in a function. The function uses this variable until the function stops running. However, if you want to keep that variable every time you run the function, you should use a global ($).
When using a local variable, it doesn't really matter what you name it at the beginning,  as long as you use that same name throughout the entire function. For example:

%a = 12; echo(%a);
returns 12 (obviously, but that's not my point.)
%b = 12; echo(%b); it really doesn't matter what you name it, but you have to use the same name throughout the function.
Yes, I know you can change the name of the variable during the function and then use that, but for basic purposes, we're not going to cover that.

Here's a tutorial on for loops:

A for loop repeats a statement or block of code for a set number of iterations. - From the official GarageGames website.
You will want to use a for loop every time you want to repeat a certain operation with a different number.
Here's a basic explanation:

for(starting condition; ending condition; by how much)

Using a for loop, you will want to start at a number to go to a number by using different increments or decrements. (going up or going down).
A really simple for loop that uses numbers 0 - 2:
for(%i = 0; %i < 3; %i++)
As stated above, every %i doesn't need to actually be an I. You could name it %atutle, or practically anything you want as long as it doesn't contain numbers or weird characters (like !, ^, &, etc.)

The for loop above tells us to start at the starting index, where %i is stated as 0. It then repeats the loop by one (++) until it reaches the middle index (less than 3.)
for(%i = 0; %i < 3; %i++)
echo(%i);

Shows us this:
0
1
2
So, in your code, you use for(%i = 0; %i < ClientGroup.getCount(); %i++).
This tells us to start at 0, going by 1 until we reach the count of the ClientGroup (which is basically the number of clients in the server).
When using anything with .getCount(); the object you're doing getCount() on has a .getObject() method, which allows us to see the objects that are part of that group.
For example:
Code: [Select]
Group
{
    Object
}
If we used group.getObject() it would allow us to get all of the children (objects) of the parents (Groups). So, ClientGroup.getObject(%i); is telling us to get every object of the clientGroup because you looped through it with a for loop.
Also, you can change the way for loops go up/down, using mathematical functions. For example, using %i += 10 on the last index would allow us to run the for loop, but going up 10 every time instead of 1. Like so:
for(%i = 0; %i < 100; %i += 10)
echo(%i);

Shows us:
0
10
20
30
40
50
60
70
80
90

If you need any other help, click here for the Torque3D website for more references.

Also, in your buildMinigame() code, setting the %object.minigame to NULL actually makes the minigame output "NULL", not an actual NULL (I think), so you would want to use %object.minigame = "";
« Last Edit: July 19, 2014, 09:15:36 AM by Cruxeis »

« Last Edit: July 19, 2014, 06:38:27 PM by chubaka452 »