Home   Help Search Login Register  

Author Topic: Exiting from custom dialog  (Read 1899 times)

0 Members and 1 Guest are viewing this topic.

Offline Trexian

  • Members
  • *
Exiting from custom dialog
« on: 27 Jan 2010, 19:10:41 »
We are working on updating and improving Pingu's claymore addon for A1.  Been making good progress, but have encountered a problem (well, several, but this is the most debilitating).

For those of you who may not remember, he had a function that allowed you to "sight in" the claymore.  It consisted of a (realistically) simple peep sight.  I can get to the peep sight, but can't escape from it.  Nothing works.  I've got absolutely no experience with dialogs so have no real clue where to go with this.  (I added the disableserialization based on a suggestion from a BI error message.)

Here is the script:
Code: [Select]
#define CW 0
#define CCW 1
#define UP 2
#define DOWN 3
disableSerialization;

_arguments = _this select 3;
_claymore = _arguments select 0;

_camera = "camera" camCreate position _claymore;
_camera cameraEffect ["internal", "back"];
cutrsc ["claymore_peep_sight", "PLAIN DOWN"];

peep_sight_events = compile loadFile "\JTD_mines\scripts\peep_sight_events.sqf";
peep_sight_right = false;
peep_sight_left = false;
peep_sight_forward = false;
peep_sight_backward = false;
peep_sight_nvg = false;


createDialog "peep_sight";
_disp = (findDisplay 55001);

_disp displaySetEventHandler["KeyDown", '["KeyDown",_this] call peep_sight_events'];
_disp displaySetEventHandler["KeyUp", '["KeyUp",_this] call peep_sight_events'];

while {dialog} do
{
if (peep_sight_right) then
{
[_claymore, CW] execVM "\JTD_mines\scripts\rotate.sqf";
};
if (peep_sight_left) then
{
[_claymore, CCW] execVM "\JTD_mines\scripts\rotate.sqf";
};
if (peep_sight_forward) then
{
[_claymore, UP] execVM "\JTD_mines\scripts\rotate.sqf";
};
if (peep_sight_backward) then
{
[_claymore, DOWN] execVM "\JTD_mines\scripts\rotate.sqf";
};

_camera setVectorDirAndUp [vectorDir _claymore, vectorUp _claymore];
camUseNVG peep_sight_nvg;
_camera camCommit 0.1;
sleep 0.05;
};

_camera cameraEffect ["terminate", "back"];
cutrsc ["default", "PLAIN DOWN"];
camDestroy _camera;

I'm tempted to try to code in a "q" keypress that breaks out of the while {dialog} loop, but it seems like that is just a workaround for a more fundamental issue.

Thanks for any help!
Sic semper tyrannosauro.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Exiting from custom dialog
« Reply #1 on: 28 Jan 2010, 10:55:28 »
Um. Are you sure you can't just press Esc? That was a problem back in ArmA at least when people could break out of any dialog simply by pressing Esc, even if they were not 'supposed' to (e.g. deathcams or the like). Anyway, unless it's been fixed with Arma 2, dialogs are generally closed by using closeDialog 0 (since 0 is apparently always the 'topmost' dialog). Is the problem that the dialog resources won't go away, or that the camera won't terminate?

Anyway, where does the global variable "dialog" come from in the while...do loop? All you really need is a button that makes dialog false and you're all fixed (+ a closeDialog to remove the dialog resources, if any). If nothing else, just add a clickable text in the corner that says "Done" (or an X in the upper right corner) and have it run dialog = false. Ta-daa! Although I'd very much suggest adding your TAG to every global you're using!

Good luck!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
Re: Exiting from custom dialog
« Reply #2 on: 28 Jan 2010, 11:32:49 »
closeDialog IDC

you can disable or handle ESC via adding a displayEH to your display/dialog

Offline Trexian

  • Members
  • *
Re: Exiting from custom dialog
« Reply #3 on: 28 Jan 2010, 15:12:46 »
hehe

Thank guys.  I am sure that esc doesn't exit it - the only way to get out was to close A2!   >:(  (Fortunately, I run in windowed mode.) :)  I'm sorting out how to add a keypress to close the dialog.  What I posted was basically the original sqf by Pingu for his claymores.  I kinda assumed it worked for him, and couldn't figure out what wasn't working.  Before release, there are a whole bunch of variables that will get tagged.

@ wolfrug -

RE: the "dialog" variable.  From what I can tell, that is actually a command that returns true as long as a user dialog is open.
http://community.bistudio.com/wiki/dialog

So, the way he set it up was that it would loop as long as the dialog is open.  Alas, he didn't include any way to close the dialog from within the dialog.  Likely, he relied on that esc-closes-any-dialog practice.  It must've changed with A2.

Thanks again guys. I'll probably revisit this when I mess it up. ;)

========================

For future reference, I added the "q" key to quit:
In the events script, I added:
Code: [Select]
case 16 :{ peep_sight_exit = true;};

And in the peep_sight script, I added:
Code: [Select]
if (peep_sight_exit) then
{
closeDialog 0;
};

And it appears to work. :)
« Last Edit: 29 Jan 2010, 16:13:11 by Trexian »
Sic semper tyrannosauro.