Jump to content
Sign in to follow this  
jamesj505

Help with waitUntil

Recommended Posts

Hey everyone, I am trying to create a very simple 911 calling script for a life mission but have ran in to some light trouble. The problem which is occurring is that by the time the player has answered the question from the script below which is are you sure they want to dial 911 with a yes/no dialog it is already too late because the script has ran through due to the lack of a waitUntil I've been playing around and looking at other examples of waitUntil trying to see if I could make it work and have tried multiple different solutions but with no luck. I'm starting to run out of ideas so I hope someone can help point me in the right direction or provide a solution.

I've tried things like waitUntil { Antworts == 1;}; and used Antworts = 0; under both sidechat messages with no luck. If anyone can help that would be awesome. This script is called via a button on the phone and I should also note the first time you answer nothing happens due to Antworts not being 1 or 2, but after that every time you select the button on the phone to dial 911 it will display your previous answer as that is what Antworts is.

Part of interaction.sqf

IL_911Calling = {
private ["_player", "_civ"];

_player = _this select 0;
_civ = player;

if (!(createDialog "ja_neins")) exitWith {hint "Dialog Error!"};
ctrlSetText [1, format["Are you sure you want to dial 911 and report your location and an emergency?", _civ]];	

//1024 = Ja_neins
waitUntil{(not(ctrlVisible 1024))};		

//Antworts = Answer
if (Antworts == 1) then {
player sidechat format["%1 Has dialed 911! Dispatch units to his location immediately.", _civ]; call gridcordsfunction;
};

if (Antworts == 2) then {
player groupchat format["You decided not to call 911"];
};
 };

Part of interaction.sqf

gridcordsfunction = {
private ["_civ", "_mapGrid", "_mapgridX", "_mapgridY"];

_civ = player;	
_mapGrid = (getPos _civ) call BIS_fnc_PosToGrid; 
_mapgridX = _mapgrid select 0; 
_mapgridY = _mapgrid select 1; 

player sidechat format["%1 is located at X:%2/Y:%3", _civ, _mapgridX,_mapgridY];  
};

Share this post


Link to post
Share on other sites

waitUntil's and GUI controls are a bad mix in my opinion.

What you want to do is assigning the yes-Button an EventHandler which performs the tasks you want to do when "yes" is clicked.

You can either do it in your dialog's class ("onAction= ...") or using ctrlAddEventHandler.

Share this post


Link to post
Share on other sites

I don't see a problem using a waitUntil with GUI controls.

This should work with your current script if the button/dialog is ctrl #1024.

//For yes button
onButtonClick = "closedialog 0; Antworts = 1;";
//No button
onButtonClick = "closedialog 0; Antworts = 2;";

Upon pressing a button it closes any dialogs and sets the answer to either 1 or 2.

It would be good to reset the Antworts value or use the waituntil based on that.

In the beginning of the script you could put Antworts as nil or 0, then put the waituntil {sleep 0.1; !isNil "Antworts"} or {sleep 0.1; Antworts > 0;}

That way the script continues only if you press yes or no.

You could also include a check if the player manages to close the dialog without pressing a button with eg. waituntil {sleep 0.1; (!isNil "Antworts || !dialog)}; if (isNil "Antworts") exitWith {};

So that the script doesn't keep running in the background.

Edited by Viba

Share this post


Link to post
Share on other sites

Thank you both for the help, I really appreciate it. The explanation about checking if the player closed the dialog is something I wouldn't have setup or even though about.

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  

×