[HELP] preserve the room variable even if the owner leave

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Post Reply
kaloy12
Posts: 26
Joined: 20 Nov 2010, 23:39
Location: PH

[HELP] preserve the room variable even if the owner leave

Post by kaloy12 »

HI there,

Is there a way to preserve a room variable even if the owner leaves it?

here is my scenario.

Player1 sets a roomvariable isStarted=true

if the roomvariable isStarted==true;
it should not display on the roomlist.

it works fine if Player1 is still on the room.
the problem is if player1 quits the game the isStarted variable becomes undefined or sometimes null.


i hope someone can help me on this.

note:
the use of this code is to prevent other player on the zone not to join on the game if it is started.


it is something like in dota that if the game is started, it will br remove on to the list of the roomdisplay,

is there a better way to do this stuff?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

Hi. Yes there are 2 ways to achieve that, depending on how long you want it to persist:

- Persist until the user disconnects from the server, so it keeps in the room even when the user leaves it but doesn't logout from the server - to achieve this you can set the persistent boolean of a variable to true, upon its creation.
For more information please check the docs (http://www.smartfoxserver.com/docs) at the 5.11 chapter)

- Persist until the server shuts down or restarts - to achieve this you need to set the variable from an extension and set the variable's owner to null.

Hope this helps
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
kaloy12
Posts: 26
Joined: 20 Nov 2010, 23:39
Location: PH

Post by kaloy12 »

rjgtav wrote:Hi. Yes there are 2 ways to achieve that, depending on how long you want it to persist:

- Persist until the user disconnects from the server, so it keeps in the room even when the user leaves it but doesn't logout from the server - to achieve this you can set the persistent boolean of a variable to true, upon its creation.
For more information please check the docs (http://www.smartfoxserver.com/docs) at the 5.11 chapter)

- Persist until the server shuts down or restarts - to achieve this you need to set the variable from an extension and set the variable's owner to null.

Hope this helps

thank you for the help.
i think the one i need is the variable that persist until the server is shut down, and you mention about from an extenstion.
i am not currently familiar about extensions, is there a need on setting it up? i've read the persistence here http://www.smartfoxserver.com/docs/docP ... /index.htm

so i have no problem about the code.
can you teach me where to start about extensions?


my new problem now is how can i notify other player in the room that the room isStarted.

for example:

Player1, Player 2 and Player3 is on the "CHAT" zone.

Player1 creates the a new GameRoom.
it will then display at the roomList.
player2 and player 3 will see the room created by player1.
and player1 is waiting other palyers to join.

Player2 now joins Player1's GameRoom.
player3 is still on the "CHAT" zone.

then

Player1 decided to start the game. so
the roomVariable isStart=true.
my code on onRoomListUpdate is something like

onRoomListUpdate{
var roomList = room;
for(var roomObj:roomList){
var isStarted = roomObj.getVariable("isStarted");
if(!isStarted){
displayRoomlist();
}
}

}

the summary of this code is Not to display the room if its RoomVariable
isStarted==true;

my code works fine if
Player4 is not yet log in while player1 started the game
but still display the room if its
like Player3's scenario

maybe its because player3 is not notify that the current room variable is updated.

how can i solve this
kaloy12
Posts: 26
Joined: 20 Nov 2010, 23:39
Location: PH

Post by kaloy12 »

the views are increasing without further replies. hehe :shock: :shock: :shock:
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

hi. The only way to achieve that is by using an extension, when the game starts, you send a message to all users inside the CHAT zone telling that the game has started.

This has already been discussed some times, so maybe you can try searching on the forums
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
kaloy12
Posts: 26
Joined: 20 Nov 2010, 23:39
Location: PH

Post by kaloy12 »

rjgtav wrote:hi. The only way to achieve that is by using an extension, when the game starts, you send a message to all users inside the CHAT zone telling that the game has started.

This has already been discussed some times, so maybe you can try searching on the forums

yeah im always hearing that it is already been discussed,
but i dont know where to start, where to read,
what to search,

i am always searching for "extensions" but only reading many questions about it and always replyin its already been discussed.

my point here is, can you help me where to find that, if you dont mind , hehe
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
kaloy12
Posts: 26
Joined: 20 Nov 2010, 23:39
Location: PH

Post by kaloy12 »

rjgtav wrote:Hi. Here are some posts I've found searching for the keywords "onRoomVariablesUpdate room":

- http://forums.smartfoxserver.com/viewto ... pdate+room
- http://forums.smartfoxserver.com/viewto ... pdate+room
- http://forums.smartfoxserver.com/viewto ... pdate+room
ok thank you for the information, i'll check it,


thanks a lot again. :D :D :D
kaloy12
Posts: 26
Joined: 20 Nov 2010, 23:39
Location: PH

Post by kaloy12 »

hi, I already read what you have posted and I still having a problem on how to make an extensions.

I know how does extension work but what I don't understand is how to create it?.

what file type it is?
is there a rule on where to put it on particular folder?
Do I need to configure it on config.xml?
What event should be fire when extension fires?

I hope you get my point hehe :P
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

hi. Please read the docs at http://www.smartfoxserver.com/docs. There it explains nearly all SFS features (the rest is explained in the API documentation) including some chapters dedicated to extensions.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
kaloy12
Posts: 26
Joined: 20 Nov 2010, 23:39
Location: PH

Post by kaloy12 »

rj thanks, i've read it and learn a lot of thing,

before i ignore those tutorials on simple extension thing because i am thinking it give me a waste of time.
But re-reading it gives me a lot of help, thanks, cheer up. 8) 8) 8) 8) 8) 8) 8)
Post Reply