Jump to content
Sign in to follow this  
Kingsley1997

Dialog onLoad Not Working

Recommended Posts

This is starting to really annoy me. It seems wherever I try and put this code it just doesn't work yet everytime I output the variables they all show the right stuff so it will clearly go into the IF's and stuff, and I've also tried multiple ways at editing the dialog controls and tried disableSerialization.

Please someone figure this out. I just want a very simple system where when the dialog loads it will call a script. In that script it will load some variables from the players namespace (the player that opened the dialog) and then if those variables are equal to something then disable a button and set the buttons text to something.

Here's the addAction script to open the dialog

// [target, caller, ID, arguments]

private ["_unit", "_sign", "_loadout", "_hasLoaded", "_playerData", "_actCtrl", "_rank"];

_sign = _this select 0;
_unit = _this select 1;

if (local _unit) then {
createDialog "WS_GUI_Jobs";
};

Here's my dialog.hpp

class WS_GUI_Jobs
{
idd = -1;
movingenable = false;

onLoad = "_this call compile preprocessFileLineNumbers 'ui\jobs\init.sqf';";

class controls
{
	class WSGUIJobs_Back: IGUIBack
	{
		idc = -1;
		x = 0.304013 * safezoneW + safezoneX;
		y = 0.258 * safezoneH + safezoneY;
		w = 0.397131 * safezoneW;
		h = 0.484 * safezoneH;
	};
	class WSGUIJobs_Header: WS_Header
	{
		idc = 2201;
		text = "BASIC ROLES";
		x = 0.304013 * safezoneW + safezoneX;
		y = 0.2338 * safezoneH + safezoneY;
		w = 0.397131 * safezoneW;
		h = 0.022 * safezoneH;
	};
	class WSGUIJobs_StrText_01: RscStructuredText
	{
		idc = 1100;
		x = 0.309171 * safezoneW + safezoneX;
		y = 0.588 * safezoneH + safezoneY;
		w = 0.0928357 * safezoneW;
		h = 0.11 * safezoneH;
	};
	class WSGUIJobs_Pic_01: RscPicture
	{
		idc = 1200;
		text = "ui\jobs\img\medic.paa";
		x = 0.309171 * safezoneW + safezoneX;
		y = 0.269 * safezoneH + safezoneY;
		w = 0.0928357 * safezoneW;
		h = 0.308 * safezoneH;
	};
	class WSGUIJobs_Btn_01: RscButton
	{
		idc = 1600;
		text = "PRIVATE"; //--- ToDo: Localize;
		x = 0.309171 * safezoneW + safezoneX;
		y = 0.709 * safezoneH + safezoneY;
		w = 0.0928357 * safezoneW;
		h = 0.022 * safezoneH;
		action = "closeDialog 2; [player, 'medic'] execVM 'ui\jobs\fn_switchUnit.sqf'";
	};
	class WSGUIJobs_Pic_02: RscPicture
	{
		idc = 1201;
		text = "ui\jobs\img\repair.paa";
		x = 0.407164 * safezoneW + safezoneX;
		y = 0.269 * safezoneH + safezoneY;
		w = 0.0928357 * safezoneW;
		h = 0.308 * safezoneH;
	};
	class WSGUIJobs_StrText_02: RscStructuredText
	{
		idc = 1101;
		text = "";
		x = 0.407164 * safezoneW + safezoneX;
		y = 0.588 * safezoneH + safezoneY;
		w = 0.0928357 * safezoneW;
		h = 0.11 * safezoneH;
	};
	class WSGUIJobs_Btn_02: RscButton
	{
		idc = 1601;
		text = "CORPORAL"; //--- ToDo: Localize;
		x = 0.407164 * safezoneW + safezoneX;
		y = 0.709 * safezoneH + safezoneY;
		w = 0.0928357 * safezoneW;
		h = 0.022 * safezoneH;
		action = "closeDialog 2; [player, 'repair'] execVM 'ui\jobs\fn_switchUnit.sqf'";
	};
	class WSGUIJobs_Pic_03: RscPicture
	{
		idc = 1202;
		text = "ui\jobs\img\pilot.paa";
		x = 0.505158 * safezoneW + safezoneX;
		y = 0.269 * safezoneH + safezoneY;
		w = 0.0928357 * safezoneW;
		h = 0.308 * safezoneH;
	};
	class WSGUIJobs_StrText_03: RscStructuredText
	{
		idc = 1102;
		text = "";
		x = 0.505158 * safezoneW + safezoneX;
		y = 0.588 * safezoneH + safezoneY;
		w = 0.0928357 * safezoneW;
		h = 0.11 * safezoneH;
	};
	class WSGUIJobs_Btn_03: RscButton
	{
		idc = 1602;
		text = "SERGEANT"; //--- ToDo: Localize;
		x = 0.505158 * safezoneW + safezoneX;
		y = 0.709 * safezoneH + safezoneY;
		w = 0.0928357 * safezoneW;
		h = 0.022 * safezoneH;
		action = "closeDialog 2; [player, 'pilot'] execVM 'ui\jobs\fn_switchUnit.sqf'";
	};
	class WSGUIJobs_Pic_04: RscPicture
	{
		idc = 1203;
		text = "ui\jobs\img\sniper.paa";
		x = 0.603151 * safezoneW + safezoneX;
		y = 0.269 * safezoneH + safezoneY;
		w = 0.0928357 * safezoneW;
		h = 0.308 * safezoneH;
	};
	class WSGUIJobs_StrText_04: RscStructuredText
	{
		idc = 1103;
		text = "";
		x = 0.603151 * safezoneW + safezoneX;
		y = 0.588 * safezoneH + safezoneY;
		w = 0.0928357 * safezoneW;
		h = 0.11 * safezoneH;
	};
	class WSGUIJobs_Btn_04: RscButton
	{
		idc = 1603;
		text = "LIEUTENANT"; //--- ToDo: Localize;
		x = 0.603151 * safezoneW + safezoneX;
		y = 0.709 * safezoneH + safezoneY;
		w = 0.0928357 * safezoneW;
		h = 0.022 * safezoneH;
		action = "closeDialog 2; [player, 'sniper'] execVM 'ui\jobs\fn_switchUnit.sqf'";
	};
	class WSGUIJobs_Btn_Close: RscButton
	{
		idc = 1604;
		text = "Close"; //--- ToDo: Localize;
		x = 0.639254 * safezoneW + safezoneX;
		y = 0.7442 * safezoneH + safezoneY;
		w = 0.0618905 * safezoneW;
		h = 0.022 * safezoneH;
		action = "closeDialog 2;";
	};
	class WSGUIJobs_Btn_Spacer: RscButtonSpacer
	{
		idc = 1605;
		x = 0.304013 * safezoneW + safezoneX;
		y = 0.7442 * safezoneH + safezoneY;
		w = 0.334208 * safezoneW;
		h = 0.022 * safezoneH;
	};
};
};

Here's the ui\jobs\init.sqf

_unit = player;
_display = _this select 0;

disableSerialization;

WS_GUI_Jobs_Display = _display;

_playerRank = _unit getVariable["playerRank", ""];
_playerRole = _unit getVariable["playerRole", ""];

if (_playerRank != "" && _playerRole != "") then {
// Medic
_left1_img = _display displayctrl 1200;
_left1_text = _display displayctrl 1100;
_left1_btn = _display displayctrl 1600;
_left1_text ctrlSetStructuredText parseText "<t align='center' size='1.25'>Medic</t><br /><t align='left' size='0.75'>- HEAL TO 100%<br />- 200% FASTER REVIVE<br />- GREAT RESPONSIBILITY</t>";

if (_playerRole == "medic") then {
	_left1_btn ctrlSetText "RESIGN";
	ctrlSetText [1600, "RESIGN"];
	buttonSetAction [1600, "[player] execVM 'ui\jobs\fn_resign.sqf'"];
} else {
	_left1_btn ctrlSetText "CHOOSE ROLE";
	ctrlSetText [1600, "CHOOSE ROLE"];
	buttonSetAction [1600, "[player, 'medic'] execVM 'ui\jobs\fn_switchUnit.sqf'"];
};

// Repair
_left2_img = _display displayctrl 1201;
_left2_text = _display displayctrl 1101;
_left2_btn = _display displayctrl 1601;
_left2_text ctrlSetStructuredText parseText "<t align='center' size='1.25'>Repair</t><br /><t align='left' size='0.75'>- REPAIR VEHICLES<br />- IFV ACCESS<br />- KEY ASSET</t>";

if (_playerRole == "repair") then {
	_left1_btn ctrlSetText "RESIGN";
	ctrlSetText [1601, "RESIGN"];
	buttonSetAction [1601, "[player] execVM 'ui\jobs\fn_resign.sqf'"];
} else {
	_left1_btn ctrlSetText "CHOOSE ROLE";
	ctrlSetText [1601, "CHOOSE ROLE"];
	buttonSetAction [1601, "[player, 'repair'] execVM 'ui\jobs\fn_switchUnit.sqf'"];
};

// Pilot
_right2_img = _display displayctrl 1202;
_right2_text = _display displayctrl 1102;
_right2_btn = _display displayctrl 1602;
_right2_text ctrlSetStructuredText parseText "<t align='center' size='1.25'>Pilot</t><br /><t align='left' size='0.75'>- PILOT ALL AIRCRAFTS<br />- PROVIDE CAS<br />- CONTROL UAV DRONES</t>";

if (_playerRole == "pilot") then {
	_left1_btn ctrlSetText "RESIGN";
	ctrlSetText [1602, "RESIGN"];
	buttonSetAction [1602, "[player] execVM 'ui\jobs\fn_resign.sqf'"];
} else {
	_left1_btn ctrlSetText "CHOOSE ROLE";
	ctrlSetText [1602, "CHOOSE ROLE"];
	buttonSetAction [1602, "[player, 'pilot'] execVM 'ui\jobs\fn_switchUnit.sqf'"];
};

// Sniper
_right1_img = _display displayctrl 1203;
_right1_text = _display displayctrl 1103;
_right1_btn = _display displayctrl 1603;
_right1_text ctrlSetStructuredText parseText "<t align='center' size='1.25'>Sniper</t><br /><t align='left' size='0.75'>- LONG RANGED<br />- PROVIDE RECON<br />- CAMOUFLAGED</t>";

if (_playerRole == "sniper") then {
	_left1_btn ctrlSetText "RESIGN";
	ctrlSetText [1603, "RESIGN"];
	buttonSetAction [1603, "[player] execVM 'ui\jobs\fn_resign.sqf'"];
} else {
	_left1_btn ctrlSetText "CHOOSE ROLE";
	ctrlSetText [1603, "CHOOSE ROLE"];
	buttonSetAction [1603, "[player, 'sniper'] execVM 'ui\jobs\fn_switchUnit.sqf'"];
};

switch ( toUpper _playerRank ) do {
	case "PRIVATE": {
		ctrlEnable [1600, true];
		ctrlEnable [1601, false];
		ctrlEnable [1602, false];
		ctrlEnable [1603, false];
	};
	case "CORPORAL": {
		ctrlEnable [1600, true];
		ctrlEnable [1601, true];
		ctrlEnable [1602, false];
		ctrlEnable [1603, false];
	};
	case "SERGEANT": {
		ctrlEnable [1600, true];
		ctrlEnable [1601, true];
		ctrlEnable [1602, true];
		ctrlEnable [1603, false];
	};
	case "LIEUTENANT": {
		ctrlEnable [1600, true];
		ctrlEnable [1601, true];
		ctrlEnable [1602, true];
		ctrlEnable [1603, true];
	};
};
};

Share this post


Link to post
Share on other sites

Is the code behind onLoad supposed to be in quotation marks ? I looked up one of my dialogues and I don't have these.

onLoad = [] spawn Revo_fnc_onDialogueLoad;

Also, you can remove the check in the addaction if the unit is local. The unit that calls the addAction is always local.

Share this post


Link to post
Share on other sites
Is the code behind onLoad supposed to be in quotation marks ? I looked up one of my dialogues and I don't have these.

onLoad = [] spawn Revo_fnc_onDialogueLoad;

Also, you can remove the check in the addaction if the unit is local. The unit that calls the addAction is always local.

Not sure about the quotes, documentation on dialogs is scarce but I'll try it thanks

Share this post


Link to post
Share on other sites

Arma will automatically add quotes, but it's safer to just use them.

Your problem is likely caused by this line here:

WS_GUI_Jobs_Display = _display; 

You can only store displays in uiNamespace global variables. You also don't need to disable serialization since the display is being passed by reference. :)

Share this post


Link to post
Share on other sites
Arma will automatically add quotes, but it's safer to just use them.

Your problem is likely caused by this line here:

WS_GUI_Jobs_Display = _display; 

You can only store displays in uiNamespace global variables. You also don't need to disable serialization since the display is being passed by reference. :)

Ah okay, I got it all working with storing the display in WS_GUI_Jobs_Display but I'll change it to uiNamespace just to be sure :D

Share this post


Link to post
Share on other sites
Ah okay, I got it all working with storing the display in WS_GUI_Jobs_Display

Wait, really? Perhaps my memory was wrong...but I definitely had a similar issue recently that was solved by using uiNamespace. Weird.

Share this post


Link to post
Share on other sites
Wait, really? Perhaps my memory was wrong...but I definitely had a similar issue recently that was solved by using uiNamespace. Weird.

After changing it to uiNamespace it works exactly the same, but somehow it felt different.. more... reliable...

Share this post


Link to post
Share on other sites

You can only store displays in uiNamespace global variable

*facepalm* Not true at all.

Share this post


Link to post
Share on other sites
*facepalm* Not true at all.

Where would you say is the best place to store it?

Share this post


Link to post
Share on other sites
Where would you say is the best place to store it?

Store it wherever you think is best and suits your needs

Share this post


Link to post
Share on other sites
Well that's odd:

http://i.imgur.com/nFSidaE.jpg (127 kB)

No, what is odd is that you think this message means display can ONLY be stored in uiNamespace.

Also you get the same message (should not store in *mission namespace*) if you try to store in profileNamespace, so what does this tell you??? That missionNamespace == profileNamespace???

profileNamespace setVariable ["display", findDisplay 46]

Edited by Killzone_Kid

Share this post


Link to post
Share on other sites

The word "only" was obviously a mistake on my part, but to use your example:

missionNamespace gives an error

profileNamespace gives an error

uiNamespace doesn't give an error

Seems strange to conclude from this that missionNamespace == profileNamespace. More reasonable to conclude that uiNamespace doesn't produce an error and is therefore a safe place to store display variables. No?

Share this post


Link to post
Share on other sites
The word "only" was obviously a mistake on my part, but to use your example:

missionNamespace gives an error

profileNamespace gives an error

uiNamespace doesn't give an error

Seems strange to conclude from this that missionNamespace == profileNamespace. More reasonable to conclude that uiNamespace doesn't produce an error and is therefore a safe place to store display variables. No?

parsingNamespace also doesnt produce an error

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  

×