[FIXED] JS Gumps interfere with eachother
- Xuri
- Site Admin
- Posts: 3704
- Joined: Mon Jun 02, 2003 9:11 am
- Location: Norway
- Has thanked: 48 times
- Been thanked: 8 times
- Contact:
JS Gumps interfere with eachother
If a player has two (or more) JS Gumps open, clicking a button in one gump may trigger onGumpPress in one of the other gumps.. Will try to gather some more info on this bug soon, gotta go now though.
Last edited by Xuri on Sat Nov 26, 2005 11:17 pm, edited 2 times in total.
-= Ho Eyo He Hum =-
-
giwo
- Developer
- Posts: 1780
- Joined: Fri Jun 18, 2004 4:17 pm
- Location: California
- Has thanked: 0
- Been thanked: 0
Ok, I can verify this one without even testing it, the code obviously was built to act in this way (though I'm sure not purposefully).
However this won't be a quick fix. The problem is we serialize every SE gump with an ID of 20. Thus we will need to come up with a new way to number these gumps (as we can have 4 bytes worth of unique serials for gumps).
This problem should not happen for built-in gumps, as we can limit showing a new gump until we close the former (which we can do with a 0xbf subpacket) or force the user to close it before opening a new one.
As for the crossover, this will only happen between multiple gumps opened by a user, there is no crossover between users, since the data is pulled largely from the socket that sent the gumppress packet.
Any thoughts on this are welcome, I will start looking at a good way to individualize SE gumps (perhaps just using an upper range much like we segregate Items and Characters....).
However this won't be a quick fix. The problem is we serialize every SE gump with an ID of 20. Thus we will need to come up with a new way to number these gumps (as we can have 4 bytes worth of unique serials for gumps).
This problem should not happen for built-in gumps, as we can limit showing a new gump until we close the former (which we can do with a 0xbf subpacket) or force the user to close it before opening a new one.
As for the crossover, this will only happen between multiple gumps opened by a user, there is no crossover between users, since the data is pulled largely from the socket that sent the gumppress packet.
Any thoughts on this are welcome, I will start looking at a good way to individualize SE gumps (perhaps just using an upper range much like we segregate Items and Characters....).
Scott
- Xuri
- Site Admin
- Posts: 3704
- Joined: Mon Jun 02, 2003 9:11 am
- Location: Norway
- Has thanked: 48 times
- Been thanked: 8 times
- Contact:
To reproduce this, do the following:
Setup two new JS scripts - testgump1.js:
and testgump2.js:
Add them to jse_fileassociations.scp, and reload the server/javascript engine. Assign the scripts to two (one script for each) objects ingame. Doubleclick one of the objects to open a testgump.
You'll now have one gump with the text "Gump #" in it, which will produce the text "Pushed button with ID # in Gump #" depending on which button is pushed and in which Gump.
Now open first one testgump, then the other. You'll have two testgumps side by side, one with "Gump 1" and one with "Gump 2". Click on a button in the FIRST gump you opened, and you'll notice that the resulting text will come from the onGumpPress event of the SECOND gump you opened (possibly it will execute for the last gump in a row you open no matter how many, but I haven't tested beyond two yet).
Example: You open GUMP 1, then GUMP 2. You push BUTTON 1 in GUMP 1. You get the text "Pushed button with ID 1 in Gump 2".
Setup two new JS scripts - testgump1.js:
Code: Select all
function onUse( pUser, iUsed )
{
var pSock = pUser.socket;
var testGump1 = new Gump;
testGump1.NoClose();
testGump1.AddPage (1);
testGump1.AddBackground(0, 0, 154, 120, 0x053);
testGump1.AddText( 10, 20, 8, "Gump 1" );
testGump1.AddButton( 25, 80, 0x13ad, 1, 0, 1);
testGump1.AddText( 40, 80, 0, "Button 1");
testGump1.AddButton( 25, 105, 0x13ad, 1, 0, 2);
testGump1.AddText( 40, 105, 0, "Button 2");
testGump1.Send( pSock );
testGump1.Free();
return false;
}
function onGumpPress( pSock, pButton, gumpData )
{
var pUser = pSock.currentChar;
switch( pButton )
{
case 1:
pUser.TextMessage( "Pushed button with ID 1 in Gump 1" );
break;
case 2:
pUser.TextMessage( "Pushed button with ID 2 in Gump 1" );
break;
}
}
Code: Select all
function onUse( pUser, iUsed )
{
var pSock = pUser.socket;
var testGump2 = new Gump;
testGump2.NoClose();
testGump2.AddPage (1);
testGump2.AddBackground(0, 0, 154, 120, 0x9d8);
testGump2.AddText( 30, 20, 8, "Gump 2" );
testGump2.AddButton( 25, 80, 0x13ad, 1, 0, 1);
testGump2.AddText( 40, 80, 0, "Button 1");
testGump2.AddButton( 25, 105, 0x13ad, 1, 0, 2);
testGump2.AddText( 40, 105, 0, "Button 2");
testGump2.Send( pSock );
testGump2.Free();
return false;
}
function onGumpPress( pSock, pButton, gumpData )
{
var pUser = pSock.currentChar;
switch( pButton )
{
case 1:
pUser.TextMessage( "Pushed button with ID 1 in Gump 2" );
break;
case 2:
pUser.TextMessage( "Pushed button with ID 2 in Gump 2" );
break;
}
}You'll now have one gump with the text "Gump #" in it, which will produce the text "Pushed button with ID # in Gump #" depending on which button is pushed and in which Gump.
Now open first one testgump, then the other. You'll have two testgumps side by side, one with "Gump 1" and one with "Gump 2". Click on a button in the FIRST gump you opened, and you'll notice that the resulting text will come from the onGumpPress event of the SECOND gump you opened (possibly it will execute for the last gump in a row you open no matter how many, but I haven't tested beyond two yet).
Example: You open GUMP 1, then GUMP 2. You push BUTTON 1 in GUMP 1. You get the text "Pushed button with ID 1 in Gump 2".
-= Ho Eyo He Hum =-
-
giwo
- Developer
- Posts: 1780
- Joined: Fri Jun 18, 2004 4:17 pm
- Location: California
- Has thanked: 0
- Been thanked: 0
As for having multiple gumps open at the same time, you will want to do something like this.
First, add the command myGump.NoDispose() to stop users from closing the gump with the ESC key.
Next add a check like so
Finally on your onGumpPress() event, add a check so that any buttons that would close the gump do gumpOpen = false;
First, add the command myGump.NoDispose() to stop users from closing the gump with the ESC key.
Next add a check like so
Code: Select all
if( !gumpOpen )
{
gumpOpen = true;
SendGump();
}
Scott