Home   Help Search Login Register  

Author Topic: SOLVED: Problem having variable keep its value  (Read 1071 times)

0 Members and 1 Guest are viewing this topic.

Offline corrupt3d_Oracle

  • Members
  • *
  • I'm a llama!
SOLVED: Problem having variable keep its value
« on: 15 Jul 2007, 19:35:46 »
I can't get the _var1 value to stay as what I set it at during one of my radio messages. I think this is because the radio messages are each like their own little script that calls the next one. I'm not sure though. I've tried several fixes, but can't figure out what is going on. Thanks for any help with this. The script and example mission is included in the attachment if that would help more.

Code: [Select]
_call = _this select 0
_var1

mainmenu = false
menu1 = false
menu2 = false
menu3 = false

goto _call
exit

#mainMenu
mainmenu = true
menu1 = false
menu2 = false
menu3 = false
1 setradiomsg "Go to next menu"
exit

#R1A
mainmenu = false
menu1 = true
menu2 = false
menu3 = false
1 setradiomsg "Go to next menu (2)"
exit

#R2A
_var1 = 100
hint "var1 has been set to 100"
goto "Menu3"
exit

#Menu3
mainmenu = false
menu1 = false
menu2 = false
menu3 = true
1 setradiomsg "See if var1 is 100."
exit

#S1A
hint format["The var1 is %1.", _var1]
exit

Thanks.
« Last Edit: 17 Jul 2007, 05:07:16 by corrupt3d_Oracle »

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re: Problem having variable keep its value
« Reply #1 on: 15 Jul 2007, 20:42:24 »
If I understand you correctly, you are calling this same script from 3 different radio messages, passing in the lable as _call, and then the code goes to the named label.

It looks like your problem is that _var1 is a local variable, which only holds the value for as long as the script is executed.  Once the script hits an "exit", that variable is gone.

Use a global variable instead.  Simply remove the underscore "_" from the _var1 to make it a global variable named "var1".  Underscores as lead character indicate Local.  No underscore means global.
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline corrupt3d_Oracle

  • Members
  • *
  • I'm a llama!
Re: Problem having variable keep its value
« Reply #2 on: 16 Jul 2007, 06:41:19 »
Yes, that is correct. (sorry, I posted this in OFP, I thought it was in the arma forum when I hit post. If someone wants to move this, please feel free).

I have tried by doing it as a global (without the underscore) and initialize it to a random number (let's say 5). But, whenever I assign it a new value (let's say 100),
when I try and get the value at the same location in the script, it will still have the value of 5.

Thank you for your quick response though!


Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Problem having variable keep its value
« Reply #3 on: 16 Jul 2007, 15:35:03 »
If you want your thread to be moved you can use the report to moderator button to ask that to be done  :)

EDIT:
Changing the _var to be global (everywhere in the script) works fine for me. :scratch:
« Last Edit: 16 Jul 2007, 15:44:17 by h- »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline corrupt3d_Oracle

  • Members
  • *
  • I'm a llama!
Re: Problem having variable keep its value
« Reply #4 on: 17 Jul 2007, 00:52:46 »
Alright, looking back at the history, it appears I changed everything but the one I was using as a test to a global variable  ::).

Oh well,

Thanks for the help and quick responses guys!

Corrupt3d