OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: corrupt3d_Oracle 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.
_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.
-
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.
-
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!
-
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:
-
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