Home   Help Search Login Register  

Author Topic: Passing local vars using 'AddAction'  (Read 577 times)

0 Members and 1 Guest are viewing this topic.

Tom Norman

  • Guest
Passing local vars using 'AddAction'
« on: 13 Apr 2004, 09:46:38 »
Hiya.  I've got a bit of a problem here...how can I pass a local variable to a script executed via an added action?  For example you might have a line of code that reads:
Quote
_Unit = _This Select 0
_Alt = 150
OpenChute = _Unit Addaction ["Deploy canopy",{OpenParachute.sqs}]

But how, for example, could you pass _Alt to the "OpenParachute.sqs" script (without using global variables)?

Offline Marvin

  • Members
  • *
  • One day they will come
Re:Passing local vars using 'AddAction'
« Reply #1 on: 13 Apr 2004, 09:48:19 »
You could use -
[_Alt] exec "OpenParachute.sqs"

and then in OpenParachute.sqs type
_alt = _this select 0


Is this what you want?
Is there any games than Flashpoint?

Tom Norman

  • Guest
Re:Passing local vars using 'AddAction'
« Reply #2 on: 13 Apr 2004, 10:12:26 »
Erm, no.  Sorry mate, thanks for trying to offer a solution, but I don't think you quite understand the problem.  What you've suggested there would work, but it wouldn't fire when you used the action from your action menu, it'd just fire as soon as the script came to it.  I could control when the script would get to it via the addaction command and the '@' command, but I'd need to use a global variable in the executed script.  If you don't understand how to use the addaction command, I don't think you're really equipped to help me out here.  This problem is on a slightly higher level than the explanation you just gave me for passing local variables.  I understand how to execute a script and pass local vars via the normal means, but I need to know how to pass local variables via an 'AddAction' command.  At the moment, the only way I can see of doing it is to have the other script pick up a global variable as defined in the main script.  This is no good though because I need to make my script function for individual units.  Thanks anyway though, you did try to help.   ;)
« Last Edit: 13 Apr 2004, 10:19:19 by Tom Norman »

Offline Marvin

  • Members
  • *
  • One day they will come
Re:Passing local vars using 'AddAction'
« Reply #3 on: 13 Apr 2004, 10:21:36 »
Oh yes, now noticed, you are trying to post the local variables with addaction!
Should read carefull! :)

I already tried this out when were creating support team script, i used arrays to show what unit to do!

Simple when you are assigning unit to script [this,number] exec "script.sqs", i gave the exact number to unit, then read this in file from arrays. I think this is easier than create more scripts to each unit!
« Last Edit: 13 Apr 2004, 10:22:02 by Marvin »
Is there any games than Flashpoint?

Tom Norman

  • Guest
Re:Passing local vars using 'AddAction'
« Reply #4 on: 13 Apr 2004, 10:37:22 »
Thanks Marvin, by the sounds of it you understand the problem now, but I think I'm being a bit stupid...I'm afraid I don't understand your solution.  What I think you mean is that instead of specifying the target unit, you're just picking it's ID number out of the (Units Group) array.  But this is what I don't understand...this sounds exactly like specifying the unit by it's name, except you're specifying it via a different means.  How would you pass this unit to the activated script though?  Bearing in mind the 'addaction' command offers no place for local variables?  How would you pick them up in the activated script?  You couldn't type in '_Unit = _This select 0', because there's nothing there to select, it has had no variables and therefore now array passed to it...it has just been executed as it is.  Do you get what I'm saying pal?  If I'm just being stuipd, could you please explain your answer to me again in slow time?  Ta. ;D

Offline Marvin

  • Members
  • *
  • One day they will come
Re:Passing local vars using 'AddAction'
« Reply #5 on: 13 Apr 2004, 10:45:58 »
I`m not at home right now!
Byt i can post the script i created, then it would be all clear!
If you need it give me your email, at the 6:00 Pm i could post it to you!
I dont know the time difference, byt you can wait it at evening!
Is there any games than Flashpoint?

Tom Norman

  • Guest
Re:Passing local vars using 'AddAction'
« Reply #6 on: 13 Apr 2004, 10:53:46 »
That'd be perfect mate, my email addy is exactly what it says on my profile  (gnrnorman@hotmail.com).  Thanks very much.   :)

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Passing local vars using 'AddAction'
« Reply #7 on: 13 Apr 2004, 11:13:46 »
Heya Tom...

addaction does pass arguements when it's executed...

The arguements go something like this:
  • _this select 0  -  The unit/object that the action was added to
  • _this select 1  -  The unit activiating the action (generally the player)
  • _this select 2  -  The action ID. Starts at 0, and increments with every action added. Ie. the section action added to the object will have an action ID of 1. I generally prefer to 'name' the action so there's no confusion...
Anyway, depending on what you're trying to do exactly, we can probably figure out a work around to pass what you're after ;)

Feel free to throw me an IM either here or on the UKF forums if you want to talk about it some more...

Tom Norman

  • Guest
Re:Passing local vars using 'AddAction'
« Reply #8 on: 13 Apr 2004, 11:26:25 »
LOL!  How ironic is this.  I'm the UKF scripter and here's a UKF forum regular telling me how to do my job!  That's perfect mate, it's exactly what I was after. Thanks a lot, you've just contributed to the upcoming 'Bayonet script.'   ;)

Hey, do you want my job?  Sounds like you could do it better than me!

Offline Marvin

  • Members
  • *
  • One day they will come
Re:Passing local vars using 'AddAction'
« Reply #9 on: 13 Apr 2004, 11:30:03 »
Sui! You just saved many lives! :)
Thanks!
Is there any games than Flashpoint?

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Passing local vars using 'AddAction'
« Reply #10 on: 13 Apr 2004, 11:33:31 »
Hmm.... does it pay more than this one does?

* Sui pokes Sefe with a stick

;D ;D