Home   Help Search Login Register  

Author Topic: onMapSingleClick can't pass expressions?  (Read 568 times)

0 Members and 1 Guest are viewing this topic.

wamingo

  • Guest
onMapSingleClick can't pass expressions?
« 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:
Code: [Select]
[] exec "test1.sqs"
test1.sqs looks like this:
Code: [Select]
_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
Code: [Select]
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  :-[


wamingo

  • Guest
Re:onMapSingleClick can't pass expressions?
« Reply #1 on: 19 Apr 2004, 20:41:59 »
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?
« Last Edit: 19 Apr 2004, 20:43:10 by wamingo »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:onMapSingleClick can't pass expressions?
« Reply #2 on: 19 Apr 2004, 21:05:14 »
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
I know a little about a lot, and a lot about a little.

csde-PiLLe

  • Guest
Re:onMapSingleClick can't pass expressions?
« Reply #3 on: 20 Apr 2004, 01:23:10 »
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

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:onMapSingleClick can't pass expressions?
« Reply #4 on: 20 Apr 2004, 09:03:58 »
hmm - i believe the problem is totally different than you
guys thought here.

Code: [Select]
_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:

Code: [Select]
_clicked = false
_myargu = "this is a test"
onMapSingleClick {[_pos, _units, _shift, _alt, _myargu] exec "test2.sqs";_clicked = true}
@_clicked
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

wamingo

  • Guest
Re:onMapSingleClick can't pass expressions?
« Reply #5 on: 20 Apr 2004, 14:20:45 »
ahh of course, the variable is deleted when the script exits.
thanks guys :)