Jump to content
Sign in to follow this  
CarlGustaffa

Magic _pos in SSM, where does it come from?

Recommended Posts

Now that commanding is back to supporting floating mouse, we can no longer rely on screenToWorld [0.5,0.5] for input.

But SSM is still able to get mouse data.

If you have a look at Expansion\Addons\modules_e\SSM\data\scripts\init.sqf and look for BIS_SSM_fnc_updateMenu, you'll see some kind of magic "_pos". Can anyone shed a light on what this "expression" thingie is, and how to use it in scripts? It shares some resemblance to _pos in onMapSingleClick {_pos}

Example from script:

[["expression", "[_pos,""Mortar""] call BIS_SSM_fnc_Request"]]; //Part of the array being built.

Basically, how exactly does

player setVariable ["BIS_SSM_RequestPos",_rp]

work? Where does _rp come from? Backtracking it, I'm not able to figure it out. It's about that "expression" somehow, but but... :confused:

:help:

Share this post


Link to post
Share on other sites

It's magic, so obviously from the unicorns. :)

Isn't is just saying "the next array select is to be used as an expression", so _pos would already be declared in whatever function that array is being passed to?

Share this post


Link to post
Share on other sites

No, BIS_SSM_fnc_Request goes like:

_rp = [(_this select 0) select 0, (_this select 0) select 1]; //Positional array

followed later by:

player setvariable ["BIS_SSM_RequestPos",_rp,true];

so _pos is already set somehow, by magic :p I just can't figure out where.

Maybe it's being set internally when user selects a comm item? If so, how can I do the same thing without using the comm menu? Given that cursorTarget only reveals targets (and not positions), screenToWorld[0.5,0.5] does not follow mouse, and that we have no getMousePosition to feed it with.

Suggestions?

Share this post


Link to post
Share on other sites

Ya know, it could be like the _pos in onMapClick, because the communication menu does record the cursor position when you activate it (as I found out the first few times that I dropped arty on my head assuming it would later ask me where I wanted it).

Share this post


Link to post
Share on other sites

"[_pos,""Artillery""] call BIS_SSM_fnc_Request"

Is a string element in the array (or subarray inside of) _e. So _pos must be a variable in whatever scope that string-code is compiled and executed. That code gets very hard to read, but essentially _e is the arguments for showCommandingMenu. There's an example on the wiki, maybe you'll find where _pos comes from in there. Specifically, it's part of this syntax:

script-string: command to be executed on activation. (no arguments passed)

Edit2: According to the wiki, no arguments are passed. I'm not sure what scope that passed string-code is called from either, so it's a really good question where _pos is coming from. Maybe ask a dev.

Edited by Big Dawg KS

Share this post


Link to post
Share on other sites

Thanks, seems to be explained there, as "CursorOnGround" is a parameter used in the script, which points further to \ca\ui\data\cursor_support_ca. So, time to have a look there :) Ehh, no, nothing found. Seems to be a parameter available to configs (such as houses, sea, and forest etc).

Edited by CarlGustaffa

Share this post


Link to post
Share on other sites
\ca\ui\data\cursor_support_ca

That's just a UI element (.paa probably).

The thing you want to look at here is the script-string element. Maybe try writing a quick menu that that displays _pos or spawns an object there, and try seeing if it's an actual argument generated by the command. Using the example:

MY_MENU_inCommunication =
[
["Test Menu",true],
["Test option", [2], "", -5, [["expression", "hint format [""%1"",_pos] "]], "1", "1"]
];

showCommandingMenu "#USER:MY_MENU_inCommunication";

---------- Post added at 12:25 PM ---------- Previous post was at 12:18 PM ----------

Ok, I just did a quick test using this code:

MY_MENU_inCommunication =
[
["Test Menu",true],
["Test option", [2], "", -5, [["expression", "player setPos _pos"]], "1", "1"]
];

showCommandingMenu "#USER:MY_MENU_inCommunication";

The effect: I teleported to the position of my cursor when selecting the command.

So obviously it's one of those automatically passed arguments similiar to onMapClick.

Edit: It also works by map clicking. Have fun with it then. :)

Edited by Big Dawg KS

Share this post


Link to post
Share on other sites

Sounds like a lot of trouble to go to in order to parse a position to a script, having to go through the communication menu system I mean. You think this could be made so that a script does the needed "comm menu selecting" from an invisible comm menu, in order to obtain the position? I admit I haven't really played much with the comm menu, other than noticing it looks quite complex.

Share this post


Link to post
Share on other sites
Ya know, it could be like the _pos in onMapClick, because the communication menu does record the cursor position when you activate it (as I found out the first few times that I dropped arty on my head assuming it would later ask me where I wanted it).

Good, so I wasn't they only one that thought it should have asked. :yay:

Share this post


Link to post
Share on other sites
You think this could be made so that a script does the needed "comm menu selecting" from an invisible comm menu, in order to obtain the position?

Sitting here looking through the module scripts and looking for something like this for a script i have activated via addaction(Mortar/machinegun/launcher assembling/disassembling for AI teammates), and a "getMousePosition" type function/command would be very useful for this.

The script is basically finished, but it is as of now up to the mission designer to select the default position. But recording the mouseposition when the action is activated would be awesome.

So, have anyone found something to avoid the communications menu as these will mostly be reserved for the SSM and/or Secops?

Edited by Jelliz

Share this post


Link to post
Share on other sites

Command getMousePosition would seem a better choice than a function, considering we already have setMousePosition.

Thanks for the scripting thread and ticket. Voted, naturally :)

Edited by CarlGustaffa

Share this post


Link to post
Share on other sites
Command getMousePosition would seem a better choice than a function, considering we already have setMousePosition.

Thanks for the scripting thread and ticket. Voted, naturally :)

Kewl, thanks. :shine:

Well, as i have dug more and more and more into this, i have found that the magic _pos/_rp comes from the magic Cursoronground, as this is also used for the move command in the command menu.(Dta-Bin-config.bin)

class Move

{

title = "$STR_rscMenu.hppRscGroupRootMenu_Items_Move0";

shortcuts[] = {0};

command = "CMD_MOVE_AUTO";

show = "IsLeader * CursorOnGround * (1 - IsWatchCommanded)";

enable = "NotEmpty";

speechId = 0;

};

Shows that it somehow can be made into a GetMousePosition scripting command does it not?

Share this post


Link to post
Share on other sites

I would think so. CursorOnGround (parameter) is what I want it for since you can translate it to world pos using screenToWorld, but a new command getMousePosition would be slightly more generalized. Maybe useful in dialogs i.e.

Share this post


Link to post
Share on other sites
Well, as i have dug more and more and more into this, i have found that the magic _pos/_rp comes from the magic Cursoronground, as this is also used for the move command in the command menu.(Dta-Bin-config.bin)

Nope, cursorOnGround is just one of many conditions telling commanding menu item when to be displayed (in this case only when cursor is on ground, not sky). It has nothing to do with setting the variable.

_pos is just variable set automatically by engine, similar to already mentioned onMapSingleClick command. Other available variable is _is3D, which is true if you clicked on position in 3D world, not in map.

Edited by Moricky

Share this post


Link to post
Share on other sites
Nope, cursorOnGround is just one of many conditions telling commanding menu item when to be displayed (in this case only when cursor is on ground, not sky). It has nothing to do with setting the variable.

_pos is just variable set automatically by engine, similar to already mentioned onMapSingleClick command. Other available variable is _is3D, which is true if you clicked on position in 3D world, not in map.

This is all good stuff to know. Wonder why it's not on the biki... :rolleyes:

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×