I have a block of around 16 UserVariables for my characters, mainly serialized data in the form of strings. One of which I want to update regularly (health,stamina). What is the correct most performant method for updating a single variable from the server, whilst leaving the others alone?
Many thanks.
Correct method to update UserVariable
Re: Correct method to update UserVariable
Hi,
just update that variable. The USER_VARIABLE_UPDATE will only send what is changed.
The method to use is the one from the SFSApi class, called setUserVariables()
Extension code example:
Cheers
just update that variable. The USER_VARIABLE_UPDATE will only send what is changed.
The method to use is the one from the SFSApi class, called setUserVariables()
Extension code example:
Code: Select all
getApi().setUserVariables(...);
Cheers
Re: Correct method to update UserVariable
So I can't update a single user-variable on the server, I use setUserVariables() which seems to send updates for all 16 user-variables, even though only one has changed.
If I change the value of a single var with
It seems to send a USER_VARIABLE_UPDATE with all the user-variables listed, not just the one that's changed (wvid). I guess I'm doing something wrong somewhere.
Code: Select all
private List<UserVariable> m_vars = new ArrayList<UserVariable>();
m_vars.add(new SFSUserVariable("wvid", 10, false, false));
m_vars.add(new SFSUserVariable("transform", transform.toString(), false, false));
m_vars.add(new SFSUserVariable("data", m_data, false, false));
m_vars.add(new SFSUserVariable("option", 17, false, false));
If I change the value of a single var with
Code: Select all
m_vars.set(0, new SFSUserVariable("wvid", 10, false, false));
xxx.setUserVariables(getUser(), m_vars);
It seems to send a USER_VARIABLE_UPDATE with all the user-variables listed, not just the one that's changed (wvid). I guess I'm doing something wrong somewhere.
Re: Correct method to update UserVariable
Ah, sorted it. You need to set a list of UserVariables but it still remembers existing ones. That's not quite how I imagined it working, but it's cool, I have a handle on it now
Re: Correct method to update UserVariable
Yes, those that are already set are not "forgotten".
In the list of variables you want to set you typically pass only what needs to be changed. The server then checks which have really changed and sends only those.
So in case you set a variable to its current value it won't be transmitted.
Cheers
In the list of variables you want to set you typically pass only what needs to be changed. The server then checks which have really changed and sends only those.
So in case you set a variable to its current value it won't be transmitted.
Cheers
Who is online
Users browsing this forum: No registered users and 91 guests