Author Topic: Bizarre problems closing multiple GUIs at once with a single function  (Read 958 times)

So I have an issue, where I have a command that opens up two separate GUI windows, both modeless so that players can interact with both at the same time. One of them is the 'player inventory' GUI that shows all the player's current items, and another is a backpack window where (eventually) they'll be able to deposit their excess items into.

I have it set up so that the close commands on the backpack window call this function:
Code: [Select]
clientCmdOpen_BQSmallRuckSackGUI(%client,1);
Which is declared like this:

Code: [Select]
//wrapper function that first builds the player inventory GUI and then shows it
function renderPlayerInventory(%client) {
commandToServer('buildPlayerInventory',%client);
canvas.pushDialog(BQPlyrInvGUI);
}

//handles opening and closing of the inventory GUI.
function clientCmdOpen_BQSmallRuckSackGUI(%client,%toggle)
{
if(%toggle)
{
if(BQSmallRuckSackGUI.isAwake())
{
//closes GUIs
canvas.popDialog(BQSmallRuckSackGUI);
canvas.popDialog(BQPlyrInvGUI);
return true;
}
else
{
//opens GUIs
if(!BQPlyrInvGUI.isAwake())
{
renderPlayerInventory(%client);
}
canvas.pushDialog(BQSmallRuckSackGUI);
return true;
}
}
}

The only problem is that when I press the exit button (either the actual exit button on the GUI, or my accelerator key 'escape') after interacting with some of the buttons, my game crashes immediately. Trace(1); doesn't seem to have any helpful input either when I run it during the error.

Is calling close on a window not allowed if you do so through a function? Or is the problem just the fact that I'm doing so on two windows at once? Changing the closing command on my window from what's written above to 'canvas.popDialog(BQSmallRuckSackGUI);' seems to work fine and does not crash my game, so I'm certain that the Open_BQSmallRuckSackGUI() function is the problem.

Is this some kind of known issue, or have I just screwed something up and broken the game?

Ah, so I've found the problem.

Turns out, when you're calling a function like:
Code: [Select]
function onButtonPress(%client,%buttonNum) {
    do stuff();
}

You do not call it using onButtonPress(%client,%buttonNum); when you're making the button in the GUI editor. I.e., when you force the GUI to pass %client as an argument, it kills the game if you press the button while doing absolutely anything besides standing still. Very bizarre problem but this is definitely why it was happening.

The proper way to do it is to use onButtonPress(1); or whatever argument you want when writing the command for the GUI button.