Home   Help Search Login Register  

Author Topic: The "_Variable" Command  (Read 770 times)

0 Members and 1 Guest are viewing this topic.

RunAwayScientist

  • Guest
The "_Variable" Command
« on: 19 Jan 2003, 17:19:02 »
        I've seen  this in scripts, and I've seen it when I downloaded the Chinhook with a Cargo Hook. Yet, I don't know the proper way to use it. It's, the Under-Slash Variable command *dun dun dun*. For example:

    _Mommy doFire _Daddy

    Instead of:

        Brother doFire LittleBrother

        I've seen it in this command: "_x moveinDriver Ccar2" Foreachunits Police . What I'm thinking is that the _x is some variable, errr, like Algebra. Except, when putting these into a script, the item that triggers that script I usually see two Bracets, in which were used to define the variables.

  For Example:

[ Ccar2, Police] exec "MoveinDriver.sqs"

      So, how do I use this Command? The Underslash? Will it make scripting easier? How do I define the variables? The world may never know....

    -RunAwayScientist[AF]

Offline KTottE

  • Former Staff
  • ****
Re:The "_Variable" Command
« Reply #1 on: 19 Jan 2003, 17:34:13 »
It's easy as pie. When declaring a variable, just put "_" infront of it.

Like:

_num1 = 1
_num2 = 2

Then you have those two variables to toy with.

What it does, is that it makes the variable local.
That's all it does.

_num1 and _num2 will only be accessible in the script where they were created. No other script or function can get to them.

Which is useful when you have several scripts running.

The "_X..." is a special command, and it wouldn't work if you did "_Y..." (afaik).

The underscore doesn't look like much, and it's just that, not much.

_ = local variable.
"Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming 'WOW What a Ride!'"

RunAwayScientist

  • Guest
Re:The "_Variable" Command
« Reply #2 on: 19 Jan 2003, 17:52:30 »

  Hmm, I see. What about the Bracets in the exec command? The [ Ccar1, Police, Dead-Guy, Drunk-Guy, A Bat] exec "moveinDriver.sqs".

  Each one supposedly has a special place, for example:

 [ _Car, _Cop, _OldGuy, _GuyWithKids, _AStrangeMan]

   But, using the bracets, I define each one? I'm not sure how the Bracets relate the in-script commands. For example:

      #ADrunkManWithAVariableOfAQuestion.sqs

 _Cop moveInDriver _Car;
 _OldGuy domove getpos _GuyWithKids;
 _Bat dofire _AStrangeMan;
?(StrangePeople ==1): hint "Woah, strange People";
?(StrangePeople =! 1): hint "Woah, not Strange People";

  Each of the Variables, such as the _Cop, and _Car, should and need to be defined. Before the script is executed though, there's the "Bracets" in the exec Command. For Example:

[_Cop, _Car, _Man, _Person, _Weapon]

[Cop, Copcar, OldMan, Larson, Wrench]exec "RunningOutOfNamesForScripts.sqs"

  That's what I'm talking about. And, how would the Script know what position the Defined Variables are in? What if it thought _Cop was _Weapon? How do I define that Variables position in the bracets? How do I define the variables?!

  [] exec "HELPME.sqs"
  [] exec "ItoughtIranoutofnamesforScripts.sqs"
  [ RunAwayScientist, [AF], Corny Quote] exec "Signature.sqs"

      -RunAwayScientist[AF] (Cheese Please!)

Offline KTottE

  • Former Staff
  • ****
Re:The "_Variable" Command
« Reply #3 on: 19 Jan 2003, 17:59:12 »
Right, everything between [ and ] are parameters passed to a script.

So by doing:

[unit1, unit2, unit3] exec {script.sqs}

you passed the names of the three units to the script, you access them using the "select" command.

_unit1 = _this select 0
_unit2 = _this select 1
_unit3 = _this select 2

Don't use the underscore when passing parameters to a script, it confuses OFP ;)
"Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming 'WOW What a Ride!'"

RunAwayScientist

  • Guest
Re:The "_Variable" Command
« Reply #4 on: 19 Jan 2003, 18:07:52 »

  Alright, even though we talked more on MSN, thanks for answering my question. I think...(Scratches head)

 _Name = _this select 0
 _Organization = _this select 0
 _CornyJoke = _this select 0

[ RunAwayScientist, [AF], CornyDisplay] exec "Signature.sqs"

 - RunAwayScientist[AF] ( What you can't see can't hurt you, but I can!)