Jump to content
Sign in to follow this  
alleycat

Is it possible to get the idc of the button that was used?

Recommended Posts

Is it possible to get the idc of the button that was used and pass it to the script it fires on

action = ".....

Share this post


Link to post
Share on other sites

ctrlIDC does only return the IDC of whatever control you provide it.

If you want the IDC of the pressed button, you need to do that in the code added to the button. The button is referenced as _this select 0 inside the script. So you can simply do this inside that script:

_idc = ctrlIDC (_this select 0);

Share this post


Link to post
Share on other sites

according to DialogControls-Buttons (wiki), no that information is not passed in action via this (i haven't a moment to check if that is vaild for A3)

but, you could always use a onMouseButtonClick User Interface Event Handler which will pass the control info.

or, if you use Macros (see: Preprocessor Commands) for your IDCs, you can add an additional variable passed in your action line which is just a macro name, at runtime it will pass the IDC used everywhere else

Edited by dr_strangepete
formatting

Share this post


Link to post
Share on other sites

If I use display eventhandlers, where to I put them? Anywhere on the client before the script gets called? Also what finddisplay is needed? The example:

(findDisplay 46) displayAddEventHandler ["keyDown", "_this call functionName_keyDown"];

uses 46, which is the main game screen I think. Do I have to use the IDD of my dialog if I only want it to activate in it?

Share this post


Link to post
Share on other sites

add them to your dialog definition, in the scope of the control you want it applied to (there is also an example second-up from the bottom of the UI Event Handlers page):

class dsp_dialog_weatherApply: RscButton
	{
		idc = 1601;
		onMouseButtonClick = "_this call dsp_fnc_diag_weatherApply";

...

or, if you need to add one later, or for dynamically added button, you can use ctrlAddEventHandler (assuming you know the control by that point)

@zapat, haha, i didn't even think of that, even tho i pasted it, lol...

Edited by dr_strangepete

Share this post


Link to post
Share on other sites

Why don't you simply send it to the fnc called?

{

...

idc = 1111;

action = "[1111, _whatnot] call MyButtonWasPressed;";

...

};

Share this post


Link to post
Share on other sites

Take this as a dialog file (hpp file) and add it to your mission:

class Test {idd = 10000;};

Save the mission before starting it and during runtime, execute this code:

[color=#FF8040][color=#191970][b]disableSerialization[/b][/color][color=#8B3E2F][b];[/b][/color]
[color=#191970][b]createDialog[/b][/color] [color=#7A7A7A]"Test"[/color][color=#8B3E2F][b];[/b][/color]
[color=#1874CD]_button[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#191970][b]findDisplay[/b][/color] [color=#FF0000]10000[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]ctrlCreate[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"RscButtonMenu"[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]10001[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
[color=#1874CD]_button[/color] [color=#191970][b]ctrlSetText[/b][/color] [color=#7A7A7A]"Test button"[/color][color=#8B3E2F][b];[/b][/color]
[color=#1874CD]_button[/color] [color=#191970][b]ctrlSetBackgroundColor[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#FF0000]1[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]0.5[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]0.7[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
[color=#1874CD]_button[/color] [color=#191970][b]ctrlSetPosition[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#FF0000]0.4[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]0.45[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]0.2[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]0.05[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
[color=#1874CD]_button[/color] [color=#191970][b]ctrlAddEventHandler[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"ButtonClick"[/color][color=#8B3E2F][b],[/b][/color] [color=#8B3E2F][b]{[/b][/color]
   [color=#1874CD]_self[/color] [color=#8B3E2F][b]=[/b][/color] [color=#000000]_this[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_self[/color] [color=#191970][b]ctrlSetText[/b][/color] [color=#191970][b]format[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"My IDC = %1"[/color][color=#8B3E2F][b],[/b][/color] [color=#191970][b]ctrlIDC[/b][/color] [color=#1874CD]_self[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color][color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
[color=#1874CD]_button[/color] [color=#191970][b]ctrlCommit[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b];[/b][/color][/color]

Kudos to Killzone_Kid for his SQF to BBCode Converter.

Be aware that the BIKI does not know everything. It's always better to test things before making assertions.

Edited by Heeeere's Johnny!

Share this post


Link to post
Share on other sites
Is it possible to get the idc of the button that was used?

class SOME_BTN_CTRL: rscButton
{
   idc = 90034;
   x = 0.52275 * safezoneW + safezoneX;
   y = 0.63025 * safezoneH + safezoneY;
   w = 0.0425 * safezoneW;
   h = 0.065 * safezoneH;
   action = "90034 call AC_fnc_stuff;"; 
};

AC_fnc_Stuff

player sideChat str _this;

Share this post


Link to post
Share on other sites
idc = 90034;

/* ... */

action = "90034 call AC_fnc_stuff;";

AC_fnc_Stuff

player sideChat str _this;

Well, ... yeah, that works, too, but too plain for my taste. ^_^

Sometimes it could be useful to redo your IDCs if you add more and more controls to the dialog/display and your IDC order (if there ever was one) gets messed up. Then the downside of this might be that you'd have to change all the action strings which you wouldn't need if you used:

idc = 90034;

/* ... */

action = "player sideChat str ctrlIDC (_this select 0);";

EDIT: The above code does not work from within dialog files.

Edited by Heeeere's Johnny!

Share this post


Link to post
Share on other sites

Meh. I always store my IDCs and dialog's IDD into "recognizable" local global variables before hand in an "IDC_Init" script / function. I hate having to remember lots numbers and what controls they go to.

eg;

client script

// DIALOG IDD //
IDD_DLSR_DIALOG					  							= 100000;

// PICTURES //
IDC_DLSR_PICTURE_PIP 										= 30000;
// PROGRESS BARS //
IDC_DLSR_PROGRESS_UNIFORM								= 40000;
IDC_DLSR_PROGRESS_VEST									= 40001;
IDC_DLSR_PROGRESS_BACKPACK								= 40002;
// TEXT //
IDC_DLSR_TXT_MAINHEADER								= 50000;
IDC_DLSR_TXT_MUNITIONHEADER							= 50001;
IDC_DLSR_TXT_COMPATIBLEHEADER							= 50002;
IDC_DLSR_TXT_CONTAINERHEADER							= 50003;
IDC_DLSR_TXT_DESCRIPTION_FOOTER                        	= 50004;
// ACTIVE TEXT //
IDC_DLSR_ACTIVET_UNIFORM						= 60000;
IDC_DLSR_ACTIVET_VEST		    				= 60001;
IDC_DLSR_ACTIVET_BACKPACK	    				= 60002;
IDC_DLSR_ACTIVET_SAVELOAD						= 60003;
IDC_DLSR_ACTIVET_CTC							= 60005; 
IDC_DLSR_ACTIVET_GEAR                         = 60006;					
// LIST BOXES //
IDC_DLSR_LB_MAIN							= 70000;
IDC_DLSR_LB_CONTAINER						= 70001;
IDC_DLSR_LB_COMPATIBLEACC					= 70002;
IDC_DLSR_LB_COMPATIBLEMAGS					= 70003;
// BUTTONS //
IDC_DLSR_BTN_ADDITEM					= 80000;
IDC_DLSR_BTN_REMOVEITEM				= 80001;
IDC_DLSR_BTN_ADDMAGAZINE				= 80002;
IDC_DLSR_BTN_ADDACC					= 80003;
IDC_DLSR_BTN_WEAPONS					= 80004;
IDC_DLSR_BTN_AMMO						= 80005;
IDC_DLSR_BTN_ACCESSORIES				= 80006;
IDC_DLSR_BTN_UNIFORMS					= 80007;
IDC_DLSR_BTN_VESTS					= 80008;
IDC_DLSR_BTN_BACKPACKS					= 80009;
IDC_DLSR_BTN_HEADGEAR					= 80010;
IDC_DLSR_BTN_GLASSES					= 80011;
IDC_DLSR_BTN_EXIT 					= 80012;
// BACKGROUNDS //
IDC_DLSR_BG_MAIN					= 90000;
IDC_DLSR_BG_PIP					= 90001;
IDC_DLSR_BG_UNIFORM				= 90003;
IDC_DLSR_BG_VEST					= 90004;
IDC_DLSR_BG_BACKPACK				= 90005;
IDC_DLSR_BG_GEAR 				    = 90006;

Share this post


Link to post
Share on other sites

Because you're leet and used ctrlIDC to return the button?! /gasps! XD

Share this post


Link to post
Share on other sites
Because you're leet and used ctrlIDC to return the button?! /gasps! XD

No, I used "_this select 0" to return the button inside the action command and "ctrlIDC" to get the IDC of that button. If this is just about the button, leave out the "ctrlIDC" in my example you've got the button.

Actually, nevermind. Larrow just made me realize that this approach does not work from within dialog files.

Edited by Heeeere's Johnny!

Share this post


Link to post
Share on other sites

Ment idc derp. Yes you returned the idc with the ctrlidc command. Seeing as how the command returns an idc (number) and all.

Share this post


Link to post
Share on other sites
Be aware that the BIKI does not know everything. It's always better to test things before making assertions.

What are you referring to? "action" wiki?

Share this post


Link to post
Share on other sites
It's always better to test things before making assertions.
Isn't it just. :P

action = "player sideChat str ctrlIDC (_this select 0);";

Does not work as Action does not return a reference to its IDC.

WIKI says:

The variable "this" is available, and contains the unit that pressed the button, but unlike User Interface Event Handlers no "_this" information about the current control is passed.
but on testing. this throws an error and _this returns a blank string "".

meh

Share this post


Link to post
Share on other sites

but on testing. this throws an error and _this returns a blank string "".

Noted the same.

Share this post


Link to post
Share on other sites
Isn't it just. :P

action = "player sideChat str ctrlIDC (_this select 0);";

Does not work as Action does not return a reference to its IDC.

WIKI says: but on testing. this throws an error and _this returns a blank string "".

meh

Could you please try this example? It works just fine for me.

Oh, and welcome back, Larrow! smile.png

EDIT:

I admit, this does not work within an hpp file, but it works using ctrlSetEventHandler or ctrlAddEventHandler.

Edited by Heeeere's Johnny!

Share this post


Link to post
Share on other sites

That's because using action and simply passing the idc is too easy. :p

Share this post


Link to post
Share on other sites

Already did, several times...

error.png

TestMission

Could you please try this example? It works just fine for me.
disableSerialization;

createDialog "Test";

_button = (findDisplay 10000) ctrlCreate ["RscButtonMenu", 10001];

_button ctrlSetText "Test button";

_button ctrlSetBackgroundColor [1, 0.5, 0, 0.7];

_button ctrlSetPosition [0.4, 0.45, 0.2, 0.05];

_button ctrlAddEventHandler ["ButtonClick", {

_self = _this select 0;

_self ctrlSetText format ["My IDC = %1", ctrlIDC _self];}];

_button ctrlCommit 0;

That example will work ok as you are using an eventHandler, which does return a reference to its own IDC. A UI button ACTION does not.

Ninja'd several times. You guys post to quick ;)

Edited by Larrow

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  

×