OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Tyger on 20 Sep 2005, 13:45:35
-
The issue here is not exactly how to use onMapSingleClick, but how to implement it into a script. What I want to happen is:
- 1. Have a hint displayed saying "Click where you want artillery."
- 2. Player clicks using shift.
- 3. Hint says "You have selected a point."
- 4. Artillery goes.
I have the artillery script ready, but I am having trouble with getting the onMapSingleClick to execute it. Here's my code:
;ratelo_artypos.sqs
Hint "Please select a postion for your artillery strike."
onMapSingleClick {[_pos,_shift] exec "ratelo_arty.sqs"}
Hint "Point was selected."
exit
I think there's a problem with receiving the onMapSingleClick, but I don't really know. :P
-
So what's the problem, exactly?
-
Not an expert on this command, but I enjoy a challenge! ;D
I am with mac, as I am not sure a) what you are trying to do and b) how you are trying to do it.
Are you trying to call the onMapSingleClick command from within the "ratelo_artypos.sqs" and get the results in "ratelo_arty.sqs"? If so, as the "_pos" from "ratelo_artypos.sqs" is local to that script, it is not recognized in "ratelo_arty.sqs" without making it a public variable and then declaring it as such (I think).
If it were me, I would call "ratelo_arty.sqs" from a trigger thereby being able to use the _pos generated by the command. You could set the condition of the trigger to only allow its use after a varaible is called from the "control" source (in a script or different trigger, use "setartypos = true" and the condition of the "ratelo_arty.sqs" trigger would be "setartypos"). You could then put all of the hints/chats and execute the script in the "on Activation" line of the trigger like so:
Hint "Please select a postion for your artillery strike.";onMapSingleClick {[_pos,_shift] exec "ratelo_arty.sqs"};onMapSingleClick{}};Hint "Point was selected."
As usual, my replies are suspect until proven true as I am at work and cannot test the solution. With a litlle more info, I am sure someone can get you going in the right direction.
Wadmann
-
I think there's a problem with receiving the onMapSingleClick, but I don't really know. :P
Nope, the problem here is a misunderstanding of how onMapSingleClick works.
onMapSingleClick is "Tell OFP what to do when the player clicks on the map". The command itself finishes immediately and the script (ratelo_artypos.sqs in this case) then continues on...
What onMapSingleClick does not do is this: "stop execution here and wait for a map click. Upon detecting a map click, execute whatever's is inside the {... } parameter and continue."
Think of onMapSingleClick as a way to hand off a letter with instructions to OFP for what to do in case a map click occurs. Your script can then go about doing something else in the mean time.
Therefore, this will work:
;ratelo_artypos.sqs
hint "Please select a postion for your artillery strike."
onMapSingleClick {[_pos,_shift] exec "ratelo_arty.sqs";onMapSingleClick{};hint "Point was selected."}
exit
-
@ Killswitch
Was I barking up the wrong tree with the presumption that the _pos was only recognized by original script that "asked" for it?
I thought that if "_anyvariable" was initialized in "ScriptA", it would not be recognized in "ScriptB" unless made a global variable as mentioned.
I think I found the answer to my own misconception. It has to do with how arrays work! After reading this (http://www.ofpec.com/editors/comref.php?find=array&type=1), I see the errors of my ways (unless anyone else wants to point out any more of my errors :-[)!
Wadmann
-
I thought that if "_anyvariable" was initialized in "ScriptA", it would not be recognized in "ScriptB" unless made a global variable as mentioned.
No, thats not true. You can still pass on local variables to other scripts when you execute then, for example:
Script1.sqs
_soldier = _this select 0
? side soldier != "west" : exit
[_soldier] exec "Script2.sqs"
exit
And Script2.sqs will recognize what _soldier is:
Script2.sqs
_man = _this select 0
hint format ["%1",name _man]
exit
In this case, _man and _soldier are the same unit, so you can use local variables in the parameters of scripts, It's hard to believe you've actualy been able to script sucessfully without knowing this ???
-
I think I understand now. Part of it was that I assumed that I needed a delay of some sort until the user executed the onMapSingleClick.
Since that's not the case, I think there was really nothing wrong minus the need to shift the final hint to inside the braces of the onMapSingleClick command.
I will test this out and see if it works then. Thanks for now. ;)
-
That almost works fine. The only problem is that I can call the artillery again without using the action. Dang, this is hard to say.
I can continually click and get my artillery support without doing anything to execute my script in my first post. Does that make sense? Here's what I have so far:
Hint "Select a position for your artillery strike."
onMapSingleClick {[_pos,_shift] exec "ratelo_arty.sqs"; Hint "You have selected a position."}
exit
-
you have to remove the action from the singleclick...
Hint "Select a position for your artillery strike."
onMapSingleClick {[_pos,_shift] exec "ratelo_arty.sqs"; Hint "You have selected a position.";onMapSingleClick{}}
exit
something like that...I think ::)
-
Ah, genuis! ;D
Thanks mate. This will help a bunch!