How can share a static variable for zone and room ?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

sonht10
Posts: 5
Joined: 26 Dec 2012, 09:00

How can share a static variable for zone and room ?

Postby sonht10 » 27 Dec 2012, 16:37

Hi all !

I need your help to troubleshoot my problems.
[ I wrote java server - smartfoxserver2x]

I have a class

class LibGame
{
public static Hashmap<Interger, String> testVariable = new Hashmap<Interger, String>();
}

in class UserJoinzone.class , I wrote as follows:
LibGame.testVariable.put(1, "a");
system.out.print(LibGame.testVariable.size()) => return 1;

after user joins room, in UserJoinRoom.class, I wrote as follows:
LibGame.testVariable.put(2, "b");
system.out.print(LibGame.testVariable.size()) => return 1;


if I get size of testvariable at the UserJoinRoom value = 2 is true, but it only = 1, this can means variable testvariable not be shared.
How can I solve this?

My english is not good. Hope everyone can help me.thank you!
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How can share a static variable for zone and room ?

Postby Lapo » 28 Dec 2012, 10:11

The problem is that two Extensions exist in two separate classloaders so thy don't know each others.
Please read here: http://docs2x.smartfoxserver.com/Advanc ... assLoading

If you want to share a model across several extension you could deploy your data classes in the extensions/__lib__/ folder so that they are seen globally, in terms of class loading.
Lapo
--
gotoAndPlay()
...addicted to flash games
sonht10
Posts: 5
Joined: 26 Dec 2012, 09:00

Re: How can share a static variable for zone and room ?

Postby sonht10 » 28 Dec 2012, 10:25

ok,I have resolved . thanks so much, Lapo.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 94 guests