Home   Help Search Login Register  

Author Topic: using format for global variables?  (Read 689 times)

0 Members and 1 Guest are viewing this topic.

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
using format for global variables?
« on: 09 Dec 2004, 04:19:37 »
i have a group of scripts that are involving vehicles, using addaction, so i need a global varible for one, which needs to be triggered by a unit and that could happen at any time, and any place (much like the satchel option "touch off # bomb(s)")
so i want to create a global variable using the name of the unit and the vehicle, and i'm camcreating a satchel that will be assigned to that variable.
I'm pretty sure i would would use format for this, but how? the variable needs to be used in another script (added action)

i really hope someone can make sense of this, i don't want to post the scripts, they're small, but there are a lot of them...

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:using format for global variables?
« Reply #1 on: 09 Dec 2004, 06:36:44 »
TRC: You want a custom action for the player, to make another unit place or simulate placing a satchel charge, that the player can then 'tell' taht unit to detonate,?

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:using format for global variables?
« Reply #2 on: 09 Dec 2004, 09:03:56 »
You could try something like
Code: [Select]
call format["my_globalVariable%1",_number]_That should produce you with a variable like my_globalVariable4 depending on what the variable _number contains...

Of course, syntaxes have no warranty :P
« Last Edit: 09 Dec 2004, 09:04:34 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:using format for global variables?
« Reply #3 on: 10 Dec 2004, 04:03:29 »
but then how do i know what global to check for in the action script i use?

to further explain what i'm doing:
every vehicle is given a few actions (the promblematic one is planting explosives in it)
when you choose the bomb action, you get four options:
explode when the vehicle moves (easy)
set timer 30 sec (easy)
set timer 60 sec (same thing, easy)
heres where it gets tough:
triggered explosive (like the touch off bomb you use for satchels)

for the others i just had them attached to the vehicle and when you're near you can activate the action, but for this, it is remote detonation, so i have to attach it to the player. since there are unlimited possibilities of this event occurring at the same time, and since there can be any amount of time between planting the explosive and detonating it, i can't use the same variable with all of them, since it will just overwrite the previous assigned vehicle or whatever.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:using format for global variables?
« Reply #4 on: 11 Dec 2004, 15:46:49 »
Actually, why would you even need global variables?

As addAction passes automatically a few variables in the script it executes you could easily transfer them between scripts as local varibs and would not have to worry about anything....
http://www.ofpec.com/editors/comref.php?letter=A#addAction
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:using format for global variables?
« Reply #5 on: 11 Dec 2004, 19:06:30 »
i knew about that, but for what i am using, it has to be remotely done, so how can i make a player blow up a vehicle from any distance? i can't attach it to the vehicle 'cause then the player can't use the action

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:using format for global variables?
« Reply #6 on: 12 Dec 2004, 10:53:41 »
Right right... :P
Too busy to think I guess...

How I would do it might be something like this:

vehicle addAction ["attach satchel","put.sqs"]
(yes, you need to attach the 'attach' action on the vehicle, not on the unit attaching the satchel...)

put.sqs
Code: [Select]
; the vehicle the action is attached to
_vehicle = _this select 0

;who uses the action
_unit = _this select 1

;action ID for removal
_action = _this select 2

;check if myRemoteSatchelDudes array has been used earlier, if not, initialise it..
? count myRemoteSatchelDudes > 0: goto "next"
myRemoteSatchelDudes = []

#next
;check if myRemoteSatchelAttaches array has been used earlier, if not, initialise it..
? count myRemoteSatchelAttaches > 0: goto "next2"
myRemoteSatchelAttaches = []

#next2
; remove attacha action from the user
_unit removeAction _action

; remove the satchel from the unit to simulate it being attached on the vehicle
_unit removeMagazine "pipebomb"

; add the action user to the myRemoteSatchelDudes array...
myRemoteSatchelDudes = myRemoteSatchelDudes + [ _unit]

; add the action owner to the myRemoteSatchelAttaches array...
myRemoteSatchelAttaches = myRemoteSatchelAttaches + [_vehicle]

;add a new action to the user
_unit addAction ["detonate","detonate.sqs"]


detonate.sqs
Code: [Select]
; action user
_unit = this select 1

; action ID for removal
_action = _this select 2

;remove the action from the user
_unit removeAction _action

; check if the action user is in the myRemoteSatchelDudes array, if not, exit...
? !(_unit in myRemoteSatchelDudes): exit

; find the action user from the array, thus getting the users index...
; this bit most likely wont work but I hope you get the idea... :P
while "((myRemoteSatchelDudes select _i) != _unit) && (_i < (count myRemoteSacthelDudes))" do {_i = _i + 1}

; select the vehicle to be destroyed from the myRemoteSatchelAttaches array
; by using the index of the action user...
; the vehicle should be the same on which the action user attached the
; satchel in put.sqs as they both were stored at the same time...
_vehicle = myRemoteSatchelAttaches select _i

<insert vehicle destroying stuff here>
« Last Edit: 12 Dec 2004, 10:55:04 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:using format for global variables?
« Reply #7 on: 12 Dec 2004, 20:24:55 »
sorry, its hard to explain, but basically, thats the same conclusion i came to, but i am thinking of a good workaround right now

thanks for your help though