Home   Help Search Login Register  

Author Topic: onMapSingleClick problems  (Read 1128 times)

0 Members and 1 Guest are viewing this topic.

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
onMapSingleClick problems
« 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:

Code: [Select]
;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
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:onMapSingleClick problems
« Reply #1 on: 20 Sep 2005, 15:35:59 »
So what's the problem, exactly?
Plenty of reviewed ArmA missions for you to play

Offline Wadmann

  • OFPEC Patron
  • ****
  • I'm the next evolutionary step after a llama!
Re:onMapSingleClick problems
« Reply #2 on: 20 Sep 2005, 20:47:39 »
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:

Code: [Select]
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
Check out my Camouflage Collection! New items added 31 July 2005.

Offline Killswitch

  • Members
  • *
  • Peace, cheese and ArmA
Re:onMapSingleClick problems
« Reply #3 on: 20 Sep 2005, 22:18:07 »
Quote
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:
Code: [Select]
;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

Offline Wadmann

  • OFPEC Patron
  • ****
  • I'm the next evolutionary step after a llama!
Re:onMapSingleClick problems
« Reply #4 on: 20 Sep 2005, 23:03:35 »
@ 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, I see the errors of my ways (unless anyone else wants to point out any more of my errors  :-[)!

Wadmann

Check out my Camouflage Collection! New items added 31 July 2005.

Kyle Sarnik

  • Guest
Re:onMapSingleClick problems
« Reply #5 on: 20 Sep 2005, 23:10:57 »
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
Code: [Select]
_soldier = _this select 0

? side soldier != "west" : exit

[_soldier] exec "Script2.sqs"
exit

And Script2.sqs will recognize what _soldier is:

Script2.sqs
Code: [Select]
_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  ???

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re:onMapSingleClick problems
« Reply #6 on: 20 Sep 2005, 23:41:06 »
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.  ;)
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re:onMapSingleClick problems
« Reply #7 on: 21 Sep 2005, 13:39:51 »
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:

Code: [Select]
Hint "Select a position for your artillery strike."

onMapSingleClick {[_pos,_shift] exec "ratelo_arty.sqs"; Hint "You have selected a position."}
exit
« Last Edit: 21 Sep 2005, 13:40:23 by Tyger »
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re:onMapSingleClick problems
« Reply #8 on: 21 Sep 2005, 13:53:35 »
you have to remove the action from the singleclick...

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

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re:onMapSingleClick problems
« Reply #9 on: 21 Sep 2005, 14:53:07 »
Ah, genuis! ;D

Thanks mate. This will help a bunch!
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08