OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: wamingo on 19 Apr 2004, 19:27:59
-
hey guys, here I am again... :P
I'll keep it short...
onMapSingleClick won't for the life of me pass an argument of my own...
I make two tiny scripts: test1.sqs and test2.sqs
I launch test1.sqs from wherever, no arguments like this:
[] exec "test1.sqs"
test1.sqs looks like this:
_myargu = "this is a test"
onMapSingleClick {[_pos, _units, _shift, _alt, _myargu] exec "test2.sqs"}
exit
test2.sqs is then launched when you alt+click on map
if !(_this select 3) then {exit}
_myargu = _this select 4
player groupchat format ["myargu: %1", _myargu]
exit
what this ought to do is you alt+click on map and player will write in group chat: "this is a test"
but...
instead player writes: "myargu: scalar bool array string 0xfcffffef"
so obviously the argument isn't getting passed properly...
if I execute test2.sqs without onMapSingleClick eg [0,0,0,true,_myargu] exec "test2.sqs" it displays the text just like it should...
when I search on this forum I see plenty of examples that passes their own expressions through it and I can only assume that they have it working fine, right?
so what's up?
I've tried several variable names and removing all but one argument etc etc, but either this is a bug or I'm missing something completely obvious.
please help me :-[
-
I just found if I remove the underscore "_" from the myargu variable when I declare it in test1.sqs, it seems to work... ? don't have to remove from test2.sqs though...
strange stuff?
oh well, thanks for the help wamingo! you're welcome wamingo!
but then I got another question :)
are variables declared without underscore _ public to all scripts?
what I'm asking here is really, should I worry about namespace? (conflicting variable names)
and in which case does the script command: Private "myargu" remove it from other scripts?
or maybe: myargu = nil ?
anyone?
-
I always thought a local variable was confined to the script it was created in, however Jezuro informs me that it can be passed to other scripts via the originating script also.
Check this thread:
http://www.ofpec.com/yabbse/index.php?board=6;action=display;threadid=17051
Planck
-
Well, not exactly so.
OFP seems to always do a "call-by-value". This means,
if you call another script using a local variable, the game will replace the variable name with its value.
eg
_myvar=1;
_myvar2=2;
[_myvar, _myvar2] exec "myscript.sqs"
will become
[1,2] exec "myscript.sqs"
on runtime.
All this because you regularly NEED the value of a local variable in another procedure or function :)
Cheers
PiLLe
-
hmm - i believe the problem is totally different than you
guys thought here.
_myargu = "this is a test"
onMapSingleClick {[_pos, _units, _shift, _alt, _myargu] exec "test2.sqs"}
exit
Let's have a theoretical run of this script:
_myargu = "this is a test"
;will assign your string correctly
onMapSingleClick {[_pos, _units, _shift, _alt, _myargu] exec "test2.sqs"}
;will do, what it's told to do
exit
;will exit the script - and that's the point -> the local variable
_myargue doesn't exist anymore from this point and so it
can't be passed to test2.sqs ;)
try summit like that:
_clicked = false
_myargu = "this is a test"
onMapSingleClick {[_pos, _units, _shift, _alt, _myargu] exec "test2.sqs";_clicked = true}
@_clicked
exit
~S~ CD
-
ahh of course, the variable is deleted when the script exits.
thanks guys :)