Poll

Is this a good idea?

Awesome idea.
Good idea.
Okay idea.
Bad idea.
Horrible idea.

Author Topic: Suggestion AND Request: Scripting Tut..  (Read 2136 times)

Spaces and tabs have no effect on the script.

One exception...

echo("The noob");


Inside a string(a string of text) spaces matter.


{ } start and end a "set" of instructions

Code: (Torque) [Select]
%client = findplayerbyname("kal");
if(%client.getplayername() $= "Kalphiter")
{
    echo("Welcome, "@ %client.getplayername());
}

else
{
    echo("Welcome, person I don't know");
}

Is exactly the same as
Code: (Torque) [Select]
%client = findplayerbyname("kal");
if(%client.getplayername() $= "Kalphiter")
    echo("Welcome, "@ %client.getplayername());

else
    echo("Welcome, person I don't know");

You can only omit brackets if there's only one instruction.

Cool, I am still confused though, I don't know what a "string" is. You said it was a string of text, is that like a line of text or something similar to that?

{ and } seperate functions and datablocks. If you want to play and sound when you shoot without retyping everything, you put this at the top

Code: [Select]
datablock AudioProfile(AcerfireSound)
{
   filename    = "./Acerfire.WAV";
   description = AudioDefault3d;
   preload = true;
};
That is now named AcerfireSound

Now, when I make my vehicle shoot, I want that sound to play.

Code: [Select]
Fshootonclick=1;
Fshootonclick_Hold=1;
Fshootonclick_ShootDelay=100;
Fshootonclick_ReShootDelay=100;
Fshootonclick_ProjectileCount=1;
Fshootonclick_RequiredSlot=0;
Fshootonclick_Sound=AcerfireSound;

At the bottom line it says AcerfireSound, this will play that sound datablock at the top that I put.

You have no idea what you're talking about.

You forgot the function that even handles clicks. Great job thinking you know everything.

Cool, I am still confused though, I don't know what a "string" is. You said it was a string of text, is that like a line of text or something similar to that?
I can't easily explain all this.

A string is basically a line of text.
An integer, is well an integer.
A float, is a decimal.

Integers and floats are in the same category, they're both numbers.

%float = 1.0;
%int = 1;
%myString = "Hello!";

Notice the quotes for a string.

Floats and integers don't really matter, nothing you have to worry about, but know what they mean.



That's it, I'm writing a scripting tutorial tonight.

Thank you from the bottom of my <3.

I can't easily explain all this.

A string is basically a line of text.
An integer, is well an integer.
A float, is a decimal.

Integers and floats are in the same category, they're both numbers.

%float = 1.0;
%int = 1;
%myString = "Hello!";

Notice the quotes for a string.

Floats and integers don't really matter, nothing you have to worry about, but know what they mean.



That's it, I'm writing a scripting tutorial tonight.

Now I get the basic string thing.. kind of lol. Thanks, I'll reply back if I have any questions.. but eh, I tried making a simple script.. it showed up in the addon list when you start the game but it didnt work =O.. I tried to make it where you type /up and you go up, I did something like servercmd(up).. something like this
Code: [Select]
servercmd(up);
{
%client playeraddvelocity
};

Just tried to make something basic.. I tried it ingame and it didn't work. Lul. How do I make it so that you type some slash command and it makes you go up with velocity?

EDIT:

That's it, I'm writing a scripting tutorial tonight.
Lol.
« Last Edit: April 22, 2009, 06:20:38 PM by Tojehusiza »

Oh yeah, that is what I was going to do tonight.

Code: [Select]
servercmd(up);
{
%client playeraddvelocity
};
You don't need the parentheses around the up part, just servercmdup(%Client) <<< Args go there
then, for the %client.addvelocity part (I don't even know if that's a valid console command) you need to specify an amount for how much velocity they go up, otherwise it would be 0 or NULL. I found this part for you, it worked in the console so. AddVelocity is the command and you use it like you would events, please note you need "" around then numbers for it not to syntax. I typed in the console:
Code: [Select]
FindClientByName(AGlass).player.addvelocity("0 0 100");
This sent my flying pretty fast upwards
So in the end, your code should look like this:
Code: [Select]
function servercmdup(%client)
{
%client.player.addvelocity("0 0 25");
}
But instead of the ("0 0 25"); replace the numbers with whatever values you want...
« Last Edit: April 22, 2009, 06:49:40 PM by AGlass0fMilk »

I have another question, so I do not know what ( and )'s do now. =o

EDIT: Don't you go into the console by pressing the ~?
« Last Edit: April 22, 2009, 06:49:27 PM by Tojehusiza »


To your second question, yes you do. And I updated my post above and helped you out...

Parentheses do various things throughout the script, most commonly they contain args like in that script,

(%client)
and
("0 0 25");
And other things like that.

Someone better description please?

And I updated my thing above and gave you a code for it.

Paranthesse are places for parameters in a function.

It's possible to not have any parameters.


echo("this is one parameter");

echo();
Does nothing.


And Glass,
FindClientByName(AGlass).player.addvelocity("0 0 100");
Will not work because "AGlass" is not an object. It should be a string.

FindClientByName("AGlass").player.addvelocity("0 0 100");


One will probably notice the similarity to events.

I notice that it looks close to events.. I have another question, lol. I know that 0 0 100 makes you go up, and 0 0 -100 makes you go down, I was just wondering which of the other two make you go east/west and which one makes you go north/south...

i had uploaded a basic tutorial
what happened?

0  0  0
x  y  z

With all 0s, and x as 100, that would be north.
Putting -100 for x is south.

With y, all 0s, y as 100, that would be east.
Putting -100 would be west.