Page 1 of 1

[ACS] Best way to sync global variables with server and client?

Posted: Sat Sep 16, 2017 8:42 pm
by Ivan
I'm having trouble finding an efficient and fool-proof way of syncing the global variables of my mod from server to client. These variables are dynamic, and can change at item pickup, or depending on user action on certain scenarios.

Also, I think we should have a modifier to variables to ensure they get auto-synced to clients. Honestly it confuses me why global variables wouldn't be synced automatically anyway.

[ACS] Re: Best way to sync global variables with server and client?

Posted: Sun Sep 17, 2017 5:21 am
by Combinebobnt
ask the player to say the variable in chat and hire someone who idles on irc all day to type it into the server

[ACS] Re: Best way to sync global variables with server and client?

Posted: Sun Sep 17, 2017 12:26 pm
by Ænima
Idk if i would rely that heavily on clients to tell you the exact values of their variables. Because if they get desync'd, wouldn't that then mess the globals up?

I guess it depends exactly what you're using these variables for.

[ACS] Re: Best way to sync global variables with server and client?

Posted: Sun Sep 17, 2017 2:03 pm
by Dusk
I'm afraid there's no good solution. If you don't have too many of such variables, you could create a setter function that calls ACS_Execute on a clientside script to sync these variables to clients.
Ivan wrote:Also, I think we should have a modifier to variables to ensure they get auto-synced to clients.
I tried to do that at some point, but it requires a lot of effort. Especially since acc needs to be changed accordingly. Unless we'd only do it on the ACS VM side and let more advanced ACS compilers implement such a keyword.
Ivan wrote:Honestly it confuses me why global variables wouldn't be synced automatically anyway.
Because that would break existing mods.

[ACS] Re: Best way to sync global variables with server and client?

Posted: Sun Sep 17, 2017 2:41 pm
by Ivan
Dusk wrote:I'm afraid there's no good solution. If you don't have too many of such variables, you could create a setter function that calls ACS_Execute on a clientside script to sync these variables to clients.
Ivan wrote:Also, I think we should have a modifier to variables to ensure they get auto-synced to clients.
I tried to do that at some point, but it requires a lot of effort. Especially since acc needs to be changed accordingly. Unless we'd only do it on the ACS VM side and let more advanced ACS compilers implement such a keyword.
Ivan wrote:Honestly it confuses me why global variables wouldn't be synced automatically anyway.
Because that would break existing mods.

Code: Select all

typedef struct {
	int prosperity_orb_bonus;
	int fortitude_orb_bonus;
	
	int hp_flat_bonus;
	int armor_flat_bonus;
	
	int hp_percent_bonus;
	int armor_percent_bonus;
	
	int greed_percent_bonus;
	int wisdom_percent_bonus;
	
	int damage_type_bonus[MAX_TALENTS];
} pstat_T;

global pstat_T 4: Player_Bonuses[MAXPLAYERS];
And this is only going to grow in the future...

The reason I need the syncing is because I'm relying on a shit-ton of inventory items to do the syncing right now and it's getting tedious. Also, there are some requirements that force me to not use inventories for syncing anymore. (Using a MaxHealthBonus increase item to increase health capacity of player for example, I can't rely on this anymore because I'll have some things actually reduce the health capacity and I can't take these items away to do that...)

I guess I'll do a huge ass syncing function and hope it works right on clients' end...

[ACS] Re: Best way to sync global variables with server and client?

Posted: Sun Sep 17, 2017 4:59 pm
by Catastrophe
If you want a reliable way to guarantee syncing, spawn a dummy server-side actor and set its angle and pitch to the variables you wanna save. Everyone on the player will have to spawn that actor with the correct angle and pitch as well.

So for example, if you wanna store a players "credit", spawn a dummy actor with a TID relative to the player, set its angle = credits, and then it'll be updated for everyone since it's angles and pitches.

[ACS] Re: Best way to sync global variables with server and client?

Posted: Sun Sep 17, 2017 8:52 pm
by Ivan
Catastrophe wrote:If you want a reliable way to guarantee syncing, spawn a dummy server-side actor and set its angle and pitch to the variables you wanna save. Everyone on the player will have to spawn that actor with the correct angle and pitch as well.

So for example, if you wanna store a players "credit", spawn a dummy actor with a TID relative to the player, set its angle = credits, and then it'll be updated for everyone since it's angles and pitches.
That's an interesting idea, never thought of that and it makes sense as I used similar things. Damn.

Unfortunately though I just ended up doing what Dusk said and it'll take a lot of time to redo it, but that's good to keep in mind.