Jump to content
Elite IV

Issue with getVariable in while loop won't exitWith code

Recommended Posts

Hello everyone,

I've tried to avoid posting this topic, But I've reached my capabilities in scripting in arma 3.

I don't know any other approaches to do this in Arma Scripting. I am still new so any help and pointers are all appreciated and your effort to reply to this post will no go wasted. Thank you.

 

 

So the issue I am having is that the player has "setVariables" on the player and is adjusted from another player on the server via a listbox dialog via "setVariable" command. Once the player's "jailTimeAdjusted" or "jailReleasedEarly" variable has been set to true from another player on the server, the loop that checks if the variables have changed (conditional statement) exits and no code is executed after the "exitWith" braces or the "switch" block below.


When I was debugging this and trying to see where I was at, I added a simple hint with no other code in the exitWith to see if execution goes past that but strangely it does not.

I've checked server and client RPT logs, No errors, Even though i was very sure there were no errors I still checked but to my luck, nothing in the rpts were of any help.

I've looked up "exitWith" on the scripting wiki and how it's used in loops, It leaves the scope of where it was defined in but will continue the rest of the script (if i reworded that right) but over here it does not seem to do that.

 

What confuses me is that these other conditional statements work, They are checked and return true or false, then they exitWith if true and leaves the loop and executes the rest of the code I want it to in the switch block depending on the case of course

 ----->>  "if (player distance (getMarkerPos "my_marker") > 60)" and "if (my_global_var) exitWith {...};"   <<-------- They work in the while loop.

 

But it seems "getVariable" in the conditional statement seems to just not execute code after the exitWith command in the while loop.

 

Maybe it's something to do with how it's being set from the other machine / player ? via the dialog maybe?

 

I added a hint to display the data to see if the variables are set and they indeed are.

 

This is how the variables are set on the player. The first player opens a dialog, selects a player and then either adjusts their prison time or release them from prison. Either way, it'll set the variables accordingly. Then on the other player, when he's in jail - the "while" loop happens for his counter but also monitors his player variables to see if any changes happened, once the changes do happen, the loop exits but no code is executed after.

 

Here is the code for the script function of the dialog:

#include "..\..\system\macroDefinitions.hpp"

if (!alive player) exitWith {};

_adjustTimeBox = ctrlText 9459;
_Characters = toArray (_adjustTimeBox);
_allowed = toArray("0123456789");
_letters = false;

{
	if (!(_x in _allowed)) exitWith {
		_letters = true;
	};
} forEach _Characters;

if (_letters) exitwith {
	hint "You cannot put letters into the box, only numbers."; 
};

if (_adjustTimeBox isEqualTo "") exitwith { 
	hint "You need to put a value into the box." 
};

//Turn the string into integer (number).
_adjustTimeBoxValue = parseNumber(_adjustTimeBox);
_adjustTimeBoxValue = round _adjustTimeBoxValue;

if(_adjustTimeBoxValue < 1 || _adjustTimeBoxValue > 120) exitWith { 
	hint "You can only adjust criminals prison time between 1 - 60 minutes!"; 
};

//Compile the data of the object that's selected in the dialog.
private _currentSelectedPlayer = call compile format["%1",(lbData[8459,(lbCurSel 8459)])];

_currentSelectedPlayer setVariable ["newJailTime", _adjustTimeBoxValue,true];
_currentSelectedPlayer setVariable ["jailTimeAdjusted",true,true];

_ret1 = _currentSelectedPlayer getVariable ["newJailTime",0];
_ret2 = _currentSelectedPlayer getVariable ["jailTimeAdjusted",false];

hint format ["The is CSP: %1 - New Jail Time: %2 Jail Time Adjusted: %3", _currentSelectedPlayer, _ret1, _ret2];

//hint "This feature has not been fully developed yet, should be implemented in the near future.";

 

Here is the code I have for the loop i mentioned before:

#include "..\..\script_macros.hpp"

private["_time","_playerPaidBail","_playerEscaped","_playerJailTimeAdjusted","_playerReleasedEarly","_countDown"];

params [
 ["_ret",[],[[]]],
 ["_bad",false,[false]],
 ["_time",15,[0]]
];

_time = time + (_time * 60);

if (count _ret > 0) then { 
	life_bail_amount = (_ret select 2); 
} else { 
	life_bail_amount = 1500; 
};

_playerEscaped = false;
_playerPaidBail = false;
_playerJailTimeAdjusted = false;
_playerReleasedEarly = false;

if(_time <= 0) then { 
	_time = time + (15 * 60); 
	hintC "Please Report to Elite IV: _time var failed to receive a number, 15 minute added by default - fn_jailMe.sqf";
};


[_bad,_time] spawn {

	life_canpay_bail = false;
	life_bail_amount = life_bail_amount * 5;
	
	if(_this select 0) then {
		sleep ( (_this select 1) * 0.5 );
	} else {
		sleep ( (_this select 1) * 0.2 );
	};
	 
	life_canpay_bail = nil;
};


while {true} do {

	if (round(_time - time) > 0) then {
        _countDown = [(_time - time), "MM:SS"] call BIS_fnc_secondsToString;
        hintSilent parseText format [(localize "STR_Jail_Time") + "<br/> <t size='2'><t color='#FF0000'>%1</t></t><br/><br/>" + (localize "STR_Jail_Pay") + " %3<br/>" + (localize "STR_Jail_Price") + " $%2", _countDown, [life_bail_amount] call life_fnc_numberText, if (isNil "life_canpay_bail") then {"Yes"} else {"No"}];
    };
	
        if (player getVariable ["jailTimeAdjusted",false]) exitWith {
            _playerJailTimeAdjusted = true;
        };
	
        if (player getVariable ["jailReleasedEarly",false]) exitWith {
            _playerReleasedEarly = true;
        };
	
		if(player distance (getMarkerPos "jail_marker") > 60) exitWith {
			_playerEscaped = true;
		};
		
		if(life_bail_paid) exitWith {
			_playerPaidBail = true;
		};
		
		if (LIFE_SETTINGS(getNumber,"jail_forceWalk") isEqualTo 1) then {
			player forceWalk true;
		};
	
		if((round(_time - time)) < 1) exitWith {hint ""};
	 
		if(!alive player && ((round(_time - time)) > 0)) exitWith {};
		
		sleep 1;
};

switch (true) do {
	
	case (_playerPaidBail): {
		life_is_arrested = false;
		life_bail_paid = false;
		player setVariable ["playerInJail", false,true];
		player setVariable ["jailTimeAdjusted", false,true];
		hint localize "STR_Jail_Paid";
		serv_wanted_remove = [player];
		player setPos (getMarkerPos "xtg_jailRelease_SPAWN");
		[getPlayerUID player] remoteExecCall ["life_fnc_wantedRemove",RSERV];
		[5] call XTGALRPG_MYSQL_fnc_updatePartial;
	};
 
	case (_playerEscaped): {
		life_is_arrested = false;
		player setVariable ["playerInJail", false,true];
		player setVariable ["jailTimeAdjusted", false,true];
		hint localize "STR_Jail_EscapeSelf";
		[0,"STR_Jail_EscapeNOTF",true,[profileName]] remoteExecCall ["life_fnc_broadcast",RCLIENT];
		[getPlayerUID player,profileName,"D12"] remoteExecCall ["life_fnc_wantedAdd",RSERV];
		[5] call XTGALRPG_MYSQL_fnc_updatePartial;
	};
	
	case (_playerJailTimeAdjusted): {
		life_is_arrested = false;
		player setVariable ["playerInJail", false,true];
		player setVariable ["jailTimeAdjusted", false,true];
		hint ["Your time in prison was adjusted by the government, You're being assigned your new time now..."];
		systemChat ["Your time in prison was adjusted by the government, You're being assigned your new time now..."];
		[0,"STR_Jail_TimeAdjusted",true,[profileName]] remoteExecCall ["life_fnc_broadcast",RCLIENT];
		[5] call XTGALRPG_MYSQL_fnc_updatePartial;
		//_newJailTime = player getVariable ["newJailTime",0];
		_newJailTime = 60;
		[player, _newJailTime] call life_fnc_arrestAction;
	};
	
	case (_playerReleasedEarly): {
		life_is_arrested = false;
		player setVariable ["playerInJail", false,true];
		player setVariable ["jailReleasedEarly",false,true];
		player setVariable ["jailTimeAdjusted", false,true];
		hint ["You were released from prison early by the government."];
		systemChat ["You were released from prison early by the government."];
		[0,"STR_Jail_ReleasedEarly",true,[profileName]] remoteExecCall ["life_fnc_broadcast",RCLIENT];
		player setPos (getMarkerPos "xtg_jailRelease_SPAWN");
		[5] call XTGALRPG_MYSQL_fnc_updatePartial;
	};
 
	case (alive player && !_playerEscaped && !_playerPaidBail): {
		life_is_arrested = false;
		player setVariable ["playerInJail", false,true];
		player setVariable ["jailTimeAdjusted", false,true];
		hint localize "STR_Jail_Released";
		[getPlayerUID player] remoteExecCall ["life_fnc_wantedRemove",RSERV];
		player setPos (getMarkerPos "xtg_jailRelease_SPAWN");
		[5] call XTGALRPG_MYSQL_fnc_updatePartial;
	};
};

player forceWalk false;

 

Edited by Elite IV
added entire file code to show everything

Share this post


Link to post
Share on other sites

I'm not certain but I think it might be that your variables _playerJailTimeAdjusted and _playerReleasedEarly are only defined for the first time within the loop.  Outside of the loop they have no meaning, or at least not one that's well-defined. That is, they get set to true but only temporarily, so at the end during the switch they are undefined.

Try adding:

private ["_playerJailTimeAdjusted", "_playerReleasedEarly"];

before the loop, in the outermost script context.  That will declare them in the same context as the switch, so when they get set to true they will stay that way.

  • Like 1

Share this post


Link to post
Share on other sites
4 minutes ago, dwringer said:

I'm not certain but I think it might be that your variables _playerJailTimeAdjusted and _playerReleasedEarly are only defined for the first time within the loop.  Outside of the loop they have no meaning, or at least not one that's well-defined.

Try adding:


private ["_playerJailTimeAdjusted", "_playerReleasedEarly"];

before the loop, in the topmost script context.


Yes, Thanks for your reply. I have done this already - Sorry I didn't post the entire file as the other code above isn't an issue.

This is how I've done it:

 

private["_time","_playerPaidBail","_playerEscaped","_playerJailTimeAdjusted","_playerReleasedEarly","_countDown"];

_playerEscaped = false;
_playerPaidBail = false;
_playerJailTimeAdjusted = false;
_playerReleasedEarly = false;

So they are defined outside of those loops and switch blocks and are private to the entire file instead of private to that loop 

 

The problem still persists. It's very strange that when i use "getVariable" in the conditional statement it just exits the loops and completely ignores the code in the "exitWith" braces and the switch block thats below to.

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

×