[FIXED] JS Gumps interfere with eachother

Here we stuff all the bugs we've managed to squash/squish/squelch.
Locked
User avatar
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

Post by Xuri »

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 =-
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Confirmed the bug again.

If I open Gump A, then open Gump B, any button I click in Gump A will trigger onGumpPress for the buttonID pressed, in Gump B.

In other words, the onGumpPress function for the last script run by a user is the one that all buttons pushed will trigger.
-= Ho Eyo He Hum =-
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

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....).
Scott
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

To reproduce this, do the following:

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;
	}
}
and testgump2.js:

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;
	}
}
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".
-= Ho Eyo He Hum =-
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Addendum: The bug mentioned above only seems to happen with scripted gumps - if you open two 'TWEAK gumps for two different objects and start pushing buttons, nothing at all will happen - not the above mentioned bug, nor what was supposed to happen.
-= Ho Eyo He Hum =-
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Ok, I think I have a good method of fixing this issue, will implement a fix in the beta cycle after the v0.98-3.7 release.
Scott
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

A possible fix for this is up on the CVS as 0.98-3.7a

Please test and let me know if it did the trick.
Scott
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Looks like a fix to me =)
-= Ho Eyo He Hum =-
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

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

Code: Select all

if( !gumpOpen )
{
	gumpOpen = true;
	SendGump();
}
Finally on your onGumpPress() event, add a check so that any buttons that would close the gump do gumpOpen = false;
Scott
Locked