Author Topic: "Arrays"  (Read 994 times)

I would greatly appreciate someone explain "arrays" to me. I want to know what they can be used for, How to use them, and an example.

Even if you only answer one of the above; Thank you, in advance.

I could really use some help here. :P

norly, I mean it.

Arrays are a type of variable that can hold several different bits of info.

variable[0] = "hi"
money[%client.BL_ID] += 5;

There's a lot more to it; someone else, explain it a bit better if you can.

In graphic communication they are a pattern in which the values of scale or rotation can be changed but the shape stays the same. I imagine it's similar in Torque.

Oh, btw, Just a side question: How do I tell when a player respawns/dies/kills another player in a script?
« Last Edit: September 28, 2008, 04:28:08 PM by blaman »

Ok, I think I have the basics of arrays.

Could have the following?

Code: [Select]
%array[ValueA, ValueB]

function serverCmdAddtovalueA(%client)
{
 %valueA ++
 echo(%valueA)
}

I know I have the echo and the addition part wrong and probably more, So any help you have, Post.

No, that is all wrong.  I have a copy of Mr.Wallet explaining arrays to me, and he explained them quite well, let me go find were I saved it.

Edit:

Note that I ended up never actually putting much effort into the new crosshair mod, so don't think I'm working on one, since I'm not at this current time.
Quote
  Never give out your password or credit card number in an instant message conversation.
 
laremere says:
hi
laremere says:
Since it's only you and me, I'll explain what I am trying to do with the mod
JJ10DMAN says:
ok
laremere says:
It is an update to the crosshair mod
laremere says:
I want the crosshair to change when you change weapons
laremere says:
what I though of is every little bit it checks if the gui name has changed and if it has it automaticaly changes to the right cross hair
JJ10DMAN says:
nah
JJ10DMAN says:
have it respond to clientcmds
JJ10DMAN says:
when a client changes weapons it's actually because the server said, "ok I see wat u did there, this is what you switched to" which then tells the client machine to mount the weapon
JJ10DMAN says:
you can just package a response to said client cmds to change the crosshairs
laremere says:
good idea
laremere says:
the only problem is having dynamic variables that are added when it detects a new gui name, and also retreaving the correct correct file path for the new crosshair when it detects a crosshair that is already set.
JJ10DMAN says:
not sure what you mean
laremere says:
Like when it changes
laremere says:
I need it to say this is what the new weapon mounted is, and then retreave the variable for that weapon
JJ10DMAN says:
ok so
JJ10DMAN says:
remind me again what you need help with
laremere says:
I need some way of saying $crosshairimage=$NewMountedWeaponsCrossHair
laremere says:
If I figure that out, the rest will come easy
JJ10DMAN says:
well didn't you just do that?
JJ10DMAN says:
right now
laremere says:
No, I want it to add new variables for the new names of the crosshairs
laremere says:
Like you can assign how much a player has is RoB, but I dout you have written script for every single Bl_ID, instead it adds new variables...
JJ10DMAN says:
you just use a variable
JJ10DMAN says:
...?
laremere says:
How do you determine the new variables name wile not overriding anothers?
JJ10DMAN says:
well I guess what you need to learn about is arrays
JJ10DMAN says:
unless I'm missing something which is entirely likely
laremere says:
Well, tell me how arrays work then ;P
laremere says:
brb
JJ10DMAN says:
in most programming languages arrays are ordered sets of variables
JJ10DMAN says:
torquescript cheats a little which can lead to the occasional problem (like in RoB, ugh) but overall makes them easier to work with
JJ10DMAN says:
in a nutshell as far as torquescript is concerned, you can treat arrays as a unique namespace for a set of variables
JJ10DMAN says:
the format of variables is to enter a normal variable name, followed by brackets: [ ]
JJ10DMAN says:
in the brackets you enter 1 or more dimensions seperated by commas which should be numbers or strings
JJ10DMAN says:
so for example, a global array might include $MyArray[0] and $MyArray[1], which are both unique
JJ10DMAN says:
note that they are also unique from plain old $MyArray, so to avoid confusion arrays shouldn't share names with other variables
laremere says:
So if I want to retreave the crosshair for example of the hammer, in the package of the mounting the new weapon, I could have it be: $crosshairimage=$storedvalue[%newweapon] were the $storedvalue of %newweapon is the file path that I am trying to set $crosshairimage to?
JJ10DMAN says:
yeah
JJ10DMAN says:
so say %newweapon $= "hammer"
laremere says:
yes
JJ10DMAN says:
then $StoredValue[%newweapon] would be the same as $StoredValue[hammer]
laremere says:
and $storedvalue["hammer"]=="wantedfilepath"
laremere says:
?
JJ10DMAN says:
a word of caution: avoid special characters in an array's brackets; dashes, underscores, things like that
JJ10DMAN says:
yeah if you set it lol
JJ10DMAN says:
ok well I gtg now
laremere says:
thanks ALOT
JJ10DMAN says:
sure thing
laremere says:
exepect a fancy new crosshair mod for v9
laremere says:
I gtg too, so bye
« Last Edit: September 28, 2008, 10:17:58 PM by laremere »

Oh well for my attempt. :P
But thanks for that Lare.

I know im starting to ask for a lot now, But could someone give me some decent examples of arrays in an actual script?
Sorry for being such a pain. :(

Code: [Select]
serverCmdGiveMoney(%client,%reciever)
{
  if (%client.isSuperAdmin) $money[%reciever.BL_ID] ++;
}

severCmdCheckMoney(%client)
{
  messageClient(%client,'',"\c3You have\c2" SPC $money[%client.BL_ID] SPC "\c3 money.");
}


Obviously there are a lot more features to add but that's a basic idea

Untested, there could be some glaringly obvious bug that I'm missing.

Ha, By looking at that, I think I was interpreting arrays backwards. :P
Thank you again, Falcon. :)