onMapSingleClick – Talk

From Bohemia Interactive Community
Revision as of 15:25, 16 March 2013 by Master85 (talk | contribs)
Jump to navigation Jump to search

Note: This expects a bool return value, unlike onPlayerConnected. --Doolittle 07:33, 9 July 2007 (CEST)

Much appreciated. Please give an example. Thanks --ViperMaul 11:40, 9 July 2007 (CEST)

Command description text already states this.

If click is processed, command should return true.

Planck 11:53, 9 July 2007 (CEST)

Correct me if I am wrong here. But technically speaking the term "command" in "If click is processed, command should return true" when applied to the following example given onMapSingleClick """SoldierWB"" createUnit [_pos, group player]";

in this statement the command == """SoldierWB"" createUnit [_pos, group player]" right? And if command returns true then this example evaluates to onMapSingleClick true; This is judging by the read.

Is it not a better example to say _result = onMapSingleClick """SoldierWB"" createUnit [_pos, group player]"; where _result can equal true or false? Again if I am off the mark then I am confused and I am asking for a concrete example to clear this up for me and probably others.

I am used to functions returning values. Not commands returning values. --ViperMaul 05:34, 10 July 2007 (CEST)

This is how you do it in a .sqf file: onmapsingleclick "[_pos, _units, _shift, _alt] execvm ""mapclick.sqf""; true"; execvm returns a handle, not bool.. so throw a fake bool on the end. --Doolittle 05:46, 12 July 2007 (CEST)

Return value

Let's clear this up.

this command does not return Anything

it is a command that, at 'some future time' will execute Code

whether the individual and wanted command(s) within Code return a boolean true would be highly problematic and unlikely.

So, in order to satisfy the engine, a Boolean true is required from the Code

It is an engine requirement that the 'click has been processed'.

Presumably if it gets any other value, the engine will sulk, or worse, repeat the Code in the belief that it needs to.

an excellent example of how to achieve this miracle is given above and repeated here

onmapsingleclick "[_pos, _units, _shift, _alt] execvm ""mapclick.sqf""; true";

The result of the command (yes, it is a command) 'true' is passed back to the engine. The fact (mentioned above) that execVM returns a handle is irrelevant, it is overridden by a subsequent command, true

To be even clearer, the boolean returned is passed to the engine not the front end of onmapsingleclick. onmapsingleclick was 'executed' some time ago.


ook? 02:00, 5 September 2007 (CEST)

More on the return value of true or false... if my mapclick.sqf sees that _units are currently selected, then I return FALSE so that the game will continue processing and do a MOVE command to the selected AI. If I returned TRUE with _units.. then it would be impossible to move them! So, rule of thumb, if your code handles the map mouse click, return true. If you do not handle it then return false so that the game can handle it however it wants to. --Doolittle 05:01, 5 September 2007 (CEST)

function

there is no such thing as, or a concept of, 'function' in scripting syntax. Code can execute sqf script files eg, but command syntax is exactly that, a series of command(s). The idea that a function 'returns something' is a throwback to Basic programming language.

a = b + c

has no functions. it contains the commands = and +.

just like

exit is not a function, it is a command, like all others in the syntax repertoire


ook? 01:59, 5 September 2007 (CEST)

String or code

Mike, you need to change the description of the syntax back to onMapsingleClick <string> or whatever, 'cause it's confusing, when i just looked at the page for the syntax, by what is currently written I typed into my script onMapSingleClick {a=1; hint format["%1",a];}; only to find it errored in ArmA 'cause onMapSingleClick expects a string that represents code not a parameter of type code... --Sy 04:56, 7 September 2007 (CEST)

While it would be logical for this function to accept (and require) code, unfortunately is does not, and it requires a string. --Suma 10:48, 7 September 2007 (CEST)
urk! there's inconsistency here between brace and quotes some commands do, some commands wont and some will on both. I'll have to be careful in future and check a little more rigourously. I quite wrongly assumed (coming from an ofp background) that the new way of doing things with brace, was exclusive. It isn't. Bad mistake on my part. Sorry. Mikero 06:09, 8 September 2007 (CEST) (nee ook?)

Isn't this incorrect?????

Example 2: onMapSingleClick ""_grp1 move _pos; onMapSingleClick {};true;"" talking about the code brackets {} --Nixer6 21:04, 8 January 2008 (CET)

Much better examples now, thanks Kronsky.

--Nixer6 12:48, 10 January 2008 (CET)

As of Arrowhead 1.52 the example posted by Sy works for me in the initialization line of an unit, even without returning true at the end. Can anyone come with an example using braces that doesn't work?

--Muzzleflash 02:49, 21 August 2010 (CET)

I cannot get this to work on a dedicated server

I made two very simple scripts to test this. Just a player, another guy who sidechats telling him to click on the map, a helo and a marker.

I used the exact line: onmapsingleclick "[_pos, _units, _shift, _alt] execvm ""mapclick.sqf""; true";

I even used the same name for the script. It works perfect in SP and in MP when NOT on a dedi. I am trying to move a helo to a point on the map. The marker moves on a dedi but the helo will not fly to the marker. I am not the only one having problems with this on a dedi either.

Any ideas would be much appreciated. Here's a 4 page thread about it at OFPEC. [1]

--Nixer6 06:54, 7 January 2008 (CET)

Ok, the problem here was my misunderstanding of the use of a doMove command for an AI on a dedicated server. not the OnMapSingleClick command itself.

--Nixer6 12:44, 10 January 2008 (CET)

execVM - Mistery is solved

Many of you wrote about geting problems when using execVM in onMapSingleClick scope. That issue can be solved by adding the execVM command into a varaible (global and local both work). Here is an example:

  onMapSingleClick "if (_alt) then {_a = [_shift, _alt, _pos] execVM 'arty_menu.sqf'; };";

--Mlacix 12:47, 16 March 2013 (CET)

It's not a mystery at all, you forgot to return a boolean at the end (and the engine errors on the script handle returned by execVM). --Master85 14:25, 16 March 2013 (CET)