Author Topic: Coding, Advanced Lesson?  (Read 1728 times)

How loud do you read aloud Rky?
This is the sort of thing you don't ask me.

Well I got what some of the symbols mean. I forget what they are called and I am to tired to look it up.
% means local variable
$ Means Global

Am I correct on that?

I am going to try to get a vehicle to play an animation when you click. That will be my first thing I do by hand.

% means local variable
$ Means Global

Yes sir, do you know the difference between local and global variables though?

Your biggest tool will be the console. You can find everything out with the console, I mean EVERYTHING.

To find out what happens when you do something, for example, if you want to find out what happens when you click on a vehicle you would do:
Open Console
trace(1);
Close the console
click the vehicle
Open Console
trace(0);

You will then have a list of all functions that were called in the time trace was on.
You will see a list on function names with a bunch of numbers in parentheses. This is a good time to realize that that's what almost everything in Torque is; a number. When you define something like %player = %client.player %player is just storing a number. But we use variables because these numbers aren't always the same.

So, how do you find out what these numbers you got from trace are? you use dump();
Say a number was 7260 and you wanted to find out what that number was; you would use 7260.dump(); This would then echo all of the object's dynamic fields and functions. If that doesn't help you figure out what it is do something like echo(7260.getClassName());

Echo will also help you work things out; you can do anything you do in scripts in the console. so if you want to find out whether or not your string manipulation or something is working correctly, you could just copy it from your script, slap it in the console and use some echos to work things out. You can the modify it until it does work.

Also, you can start typing in the name of a function and press TAB and it will scroll through a list of functions that you begin with what you have type; this can help you find a function.

tl;dr The console is your best friend, use trace(1); trace(0); %foo.dump(); and echo("Hello, World!");
« Last Edit: June 26, 2009, 08:56:27 AM by MrPickle »

When I code, I'm usually reading it out loud to myself and translating pieces of it.
Me too :O

Unless you're me.

At any rate, coding is logic-based. Your example is an example of why you have issues because you don't see the logic.
When I code, I'm usually reading it out loud to myself and translating pieces of it.
That's what I do when i get errors. I read it out then i figure out that a brace is missing or something.

Sorry for the bump. I researched and did alot of things. I think I got a good feel on how Torquescript works. Now, what should I make as my first script script.


Here's an example of coding in torosion.

And yes, I know there are errors in it.

Why do have both hasSTDs and STDAmt?  Just use STDAmt and set it to 0 if the person doesn't have STDs.

Your biggest tool will be the console.

Aww, I thought you were the biggest tool. :cookieMonster:

Didn't really take too much time on it, just doing it for an example :P

I am thinking of some kind of reload mod. A simple one. Make a weapons reload once it runs out of ammo. I just don't know how I would get it to work with the image state.