Home   Help Search Login Register  

Author Topic: Scripted actions....  (Read 5950 times)

0 Members and 1 Guest are viewing this topic.

KyleSarnik

  • Guest
Scripted actions....
« on: 27 Sep 2003, 17:20:23 »
I use an addaction in my script, but the problem is the script being called by the action requires three prameters ([param1,param2,param3] exec "script.sqs), all witch are defined erlier. Is there any way to add them to an addaction???
« Last Edit: 10 Oct 2003, 23:02:39 by KyleSarnik »

KyleSarnik

  • Guest
Re:addaction and parameters
« Reply #1 on: 27 Sep 2003, 18:18:39 »
I know there has to be a way around this, I tried looking through similar scripts but found nothing.

Offline KJAM

  • Contributing Member
  • **
  • Why Me, Whats it For?
    • Nightstalker mod
Re:addaction and parameters
« Reply #2 on: 27 Sep 2003, 19:39:04 »
erm i dont know too much about scripting, but is it possible to have a trigger that needs those 3 parameters to go off, then once it fires it adds the action to the user?

KyleSarnik

  • Guest
Re:addaction and parameters
« Reply #3 on: 27 Sep 2003, 22:29:23 »
no what I mean is: I have a script that activates another one, and in the init of a vehicle I have [this,param2,param3] exec "myscript.sqs" (param2,3 and script irrelevent). In myscript, this is what unit, param2 and param3 are the names of things that i want to createvehicle like "parachutewest" (im not really creating a parachute but its an example). Ok so in myscript there is a line: param1 (witch was this) addaction ["Action","script2.sqs"]. But.. waht I want to do is transfer the three parameters to script 2. For example: [this,param2,param3] exec "script2.sqs". But... if I put that line in the addaction it doesnt work. So can someone help me figure out a way to do thise plz????

KyleSarnik

  • Guest
Re:addaction and parameters
« Reply #4 on: 28 Sep 2003, 02:38:37 »
Is there any other way to transfer the parameters to the other script while still using addaction. Say for instance in script 1 before the addaction execute script 2 but in script 2 wait for a certain variable till everything starts then have a 3rd script thats just variable = true that would work wont it?? Well ill go try

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:addaction and parameters
« Reply #5 on: 28 Sep 2003, 06:44:34 »
Why don't you just let the script which get's launched
by the addAction command call for another script.

e.g:

vehicle addAction ["blabla","script1.sqs"]

<<script1.sqs>>

_guy = _this select 0

:note - there's _this select 0 and _this select 1
One of them returns the owner of the action and one
returns the caller. Owner = verhicle, caller = player who
triggers the action button. I'm not sure which one, but you
should easily figure that out  ;)
So _guy sould be one of these two.

Then as next line of the script you say:

[_guy,param2,param3] exec "myscript.sqs"

exit

~S~ CD


Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

KyleSarnik

  • Guest
Re:addaction and parameters
« Reply #6 on: 28 Sep 2003, 17:49:08 »
I dont think that will work. The three parameters are allready used in the script using addaction. But I need to transfer the params to the second script. I think your confused. The parameters are not always the same. This is how it should go.

In the init if the vehicle:

[this,param2,param3] exec "script1.sqs"

Now in script one:

Code: [Select]
_blah = _this select 0
_blahblah = _this select 1
_blahblahblah = _this select 2

#loop
?Ifwhatever : goto "next"
goto "loop"

#next

_action = _blah addaction ["ACTION","script2.sqs"]

where script2 has the parameters [_blah,_blahblah,_blahblahblah] exec "script2.sqs"

So in script 2:

Code: [Select]
_blah = _this select 0
_blahblah = _this select 1
_blahblahblah = _this select 2

and so on...
« Last Edit: 28 Sep 2003, 17:49:51 by KyleSarnik »

KyleSarnik

  • Guest
Re:addaction and parameters
« Reply #7 on: 29 Sep 2003, 13:00:23 »
There must be a way....

Offline Killswitch

  • Members
  • *
  • Peace, cheese and ArmA
Re:addaction and parameters
« Reply #8 on: 29 Sep 2003, 14:32:42 »
One solution might be to declare those three parameters you need to pass on to the AddAction script as globals. Remember to name them wisely so as to not pollute the global namespace, since addons and possibly other scripts may have globals going around too.

By "naming them wisely" I mean
  • Don't use common names such as "count", "score", "soldier"
  • Instead, use "KYL_count", "KYL_score" or something to that effect. Note: first check that "KYL" isn't a OFPEC tag that's alredy taken by someone else, of course.

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:addaction and parameters
« Reply #9 on: 29 Sep 2003, 15:09:37 »
Kyle, when i suggested you to start another script out
of the action-launched script, off course i've been talking
about global variables like Killswitch mentioned.

I cannot really see therefore, what your problem is.

Global variables you could even access without the need to
pass them to a script.

Sure, if you have a script, which should be controlable
by bypassed parameters, you need to pass them thru da
exec statement. If you want to use always the same variables
(whatever value they got right now), then you wouldn't need
to pass 'em to the script, as you could also say in the script:

_whatever1 = param1
_whatever2 = param2

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline ACF

  • Members
  • *
  • Llama?? Ain't that French for tanks?
Re:addaction and parameters
« Reply #10 on: 29 Sep 2003, 18:30:59 »
Unfortunately, Kyle has got a real problem as I had it too.  The problem with global variables is that you can't vary them through the AddAction.

How to explain: I have a generic artillery script where the ammo types (e.g. HE or smoke), battery size etc. are passed as script arguments.  (global variables are involved though derived from OnMapSingleClick).  Originally, I exec'd it from radio triggers say:
[HE,6] exec "arty.sqs"

Being lazy, AddActions looked a lot easier than setting up radio triggers.  But the arguments don't work (same problem with the script box for scripted WPs) you can't do:
_fireHE = player AddAction ["HE - fire for effect",[HE,6] exec "arty.sqs"]
Tried it with curly brackets to no avail.

The only workaround I could come up with was, for example:

_fireHE =  AddAction ["HE - fire for effect","artyHE.sqs"]

as the addaction, where artyHE.sqs was a two line script that exec'd the actual arty code:

[HE,6] exec "arty.sqs"
exit

And so on for other ammo natures.  

Support for script arguments in AddActions and Scripted WPs is on my OFP2 wishlist.

Sorry, I don't know of any other way, but I'm keeping an eye on this in case . . .


KyleSarnik

  • Guest
Re:addaction and parameters
« Reply #11 on: 29 Sep 2003, 20:58:06 »
No I dont think you guys understand (ACF you get it tho). 2 of the params are class names. Like "laserguidedbomb" or "berettamag" or "parachutewest".

So heres why variables wont work!

You have 2 guys and in the init of guy1:

[this,"BerettaMag"] exec "rearm.sqs"

Guy2:

[this,"M16"] exec "rearm.sqs"

Now heres rearm.sqs:

Code: [Select]
_param1 = _this select 0
_param2 = _this select 1

[_param1,_param2] exec "giveemammo.sqs"

_param1 addaction ["ReArm","variable.sqs"

variable.sqs:

Code: [Select]
variable=true
giveemammo.sqs

Code: [Select]
_param1 = _this select 0
_param2 = _this select 1

#loop
?variable : goto "dothis"
goto "loop"

THIS DOES NOT WORK. Heres why. Guy1 is low on 92f ammo. He clicks on ReArm action. He gets some ammo, BUT, guy2 is given some M16 mags as well!!! Maybe it doesnt really matter in such an example, but say, an ejection seat script. You dont want everyone to eject when 1 guy presses the action. Thus my problem....

PS: ACF, I cannot use it the way you did because that would mean I need to make a script for every parameter, and thats just nonsense. Plus if I decide to add a posible classname, I would have to change the script and thats not good cause I plan to release it to the public.

KyleSarnik

  • Guest
Re:addaction and parameters
« Reply #12 on: 30 Sep 2003, 04:42:19 »
Doesnt anyone know???

Unnamed

  • Guest
Re:addaction and parameters
« Reply #13 on: 30 Sep 2003, 10:49:13 »
I have not tested this as I don't know if this is exactly what you want? but no harm done if it isn't :)

Cant you have this in each guys init field:

Code: [Select]
AmmoList=AmmoList+[[This,"M16"]]
And the other guy:

Code: [Select]
AmmoList=AmmoList+[[This,"BerrettaMag"]]
And in init.sqs add this:

Code: [Select]
AmmoList=[]
Then your addaction script:

Code: [Select]
_param1 addaction ["ReArm","variable.sqs"]
could be changed to:

Code: [Select]
_param1 addaction ["ReArm","rearm.sqs"]
rearm.sqs would contain:

Code: [Select]
_CurrGuy=_This Select 1
;Cant remember if this is the correct parameter, but this should be the
;player parameter addaction passes to the script by default

{If ((_x Select 0)==_CurrGuy) Then {_CurrGuy AddMagazine (_x Select 1}} ForEach AmmoList

You would have to check syntax to make sure the arrays within AmmoList array are setup correctly, and the correct parameter is being assigned to _CurrGuy.

But I think it will work?
« Last Edit: 30 Sep 2003, 10:50:36 by Unnamed »

KyleSarnik

  • Guest
Re:addaction and parameters
« Reply #14 on: 30 Sep 2003, 13:04:30 »
Its not ammo that was just an example. Im working with vehicle classnames. I don't even understand how that would work either... Please explain it more.