enitity.variables .jar

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

Moderators: Lapo, Bax

DarkGon
Posts: 20
Joined: 25 Apr 2021, 21:54

enitity.variables .jar

Postby DarkGon » 18 Jan 2022, 05:27

Hello again Lapo
And I'm back with a question)
Thanks for helping with .jar last time, now I know how to write my extensions on the server and it works as I want)
But now I have a question, I have doors and when the player re-enters, the state of the door changes to default
I want new players to receive information about the status of players and doors, as I understand it, I need to implement it through server variables, entity.variables;
Did I understand correctly? if yes, then how to save the doors approximately, just according to the documentation on the site I didn't really understand, it would be on the example of the doors or the state of the player's health, then I would figure it out :)
thank you in advance, dear Lapo
DarkGon
Posts: 20
Joined: 25 Apr 2021, 21:54

Re: enitity.variables .jar

Postby DarkGon » 19 Jan 2022, 12:49

refresh actuality
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: enitity.variables .jar

Postby Bax » 20 Jan 2022, 09:07

Hello.
For the doors state you should use a Room Variable. This can be set using the SetRoomVariablesRequest. You have to give each door an id, and you could use a boolean to indicate if it is opened or closed:

Code: Select all

void SomeMethod() {
    sfs.AddEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, OnRoomVarsUpdate);

    List<RoomVariable> roomVars = new List<RoomVariable>();
   
    roomVars.Add( new SFSRoomVariable("door1", false) );
    roomVars.Add( new SFSRoomVariable("door2", false) );
    roomVars.Add( new SFSRoomVariable("door3", true) );

    sfs.Send( new SetRoomVariablesRequest(roomVars) );
}

Whenever a door changes it state, set its Room Variable again and all users in the room will be notified. In the OnRoomVarsUpdate listener you can then retrieve the door state and display it on screen.

For the player health instead you should use a User Variable. Usage is the same as above.
Paolo Bax
The SmartFoxServer Team
DarkGon
Posts: 20
Joined: 25 Apr 2021, 21:54

Re: enitity.variables .jar

Postby DarkGon » 20 Jan 2022, 10:29

Hello)

Thank you very much, this is what I wanted to see and what I just asked for)

I use the list of doors (id) on the client, but on the server I just wanted to find out)

thank you very much
DarkGon
Posts: 20
Joined: 25 Apr 2021, 21:54

Re: enitity.variables .jar

Postby DarkGon » 20 Jan 2022, 20:36

I figured it out, everything works, I just had to turn on my head, I didn't think that everything was so simple, I thought that everything was more complicated. It only remains to find out how to find out the state of the variable after logging on to the server, I change it, but when I log into the game I do not know its state, what is the name of such a method?

I think I realized that I used the wrong thing, the variables are stored until the creator turns off, I need to make sure that the players who even went to an empty server saw the doors that were opened a long time ago or closed a long time ago
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: enitity.variables .jar

Postby Bax » 21 Jan 2022, 08:38

If the Room is "owned" by the server (which means it's created on the server side by your Extension), its Room Variables are never destroyed (unless you restart the server, or you implement Room Persistence - check this article we just published).

To check the state of Room Variables, after joining a Room, the client can access the SFSRoom.GetVariable or SFSRoom.GetVariables methods.
Paolo Bax
The SmartFoxServer Team
DarkGon
Posts: 20
Joined: 25 Apr 2021, 21:54

Re: enitity.variables .jar

Postby DarkGon » 23 Jan 2022, 12:39

https://imgur.com/jaiWD5z
https://imgur.com/9Au476U

I kind of understood everything, but when loading the scene, all the doors behave strangely and gives an error for each door. Is it possible that you will shoot any video on the setup? it will be clearer to everyone, because so far I find the information in chunks and my hands do not quite understand what to do
Thank you for taking the time

Do I just need to implement the room save initialization extension and shove it into my BasicExemple Zone ?
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: enitity.variables .jar

Postby Bax » 24 Jan 2022, 09:00

I'm not sure how to help. I guess it's a matter of checking the errors you get and fix them.
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 49 guests