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

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
Ivan
Addicted to Zandronum
Posts: 2219
Joined: Mon Jun 04, 2012 5:38 pm
Location: Omnipresent

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

#1

Post by Ivan » Sat Sep 16, 2017 8:42 pm

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.
=== RAGNAROK DM ON ... uh... dead forever? ===
=== ALWAYS BET ON ... uh... dead forever? ===
=== Who wanta sum wang? ===
=== Death and Decay - A new Monster/Weapon replacer ===

User avatar
Combinebobnt
Retired Staff / Community Team Member
Posts: 1893
Joined: Mon Jun 04, 2012 3:37 am
Location: Erth
Contact:

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

#2

Post by Combinebobnt » Sun Sep 17, 2017 5:21 am

ask the player to say the variable in chat and hire someone who idles on irc all day to type it into the server

User avatar
Ænima
Addicted to Zandronum
Posts: 3523
Joined: Tue Jun 05, 2012 6:12 pm

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

#3

Post by Ænima » Sun Sep 17, 2017 12:26 pm

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.
­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­
Doom64: Unabsolved: New weapons, monsters, and gameplay features for coop !


ZandroSkins
: a pack made by our community

User avatar
Dusk
Developer
Posts: 581
Joined: Thu May 24, 2012 9:59 pm
Location: Turku

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

#4

Post by Dusk » Sun Sep 17, 2017 2:03 pm

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.

User avatar
Ivan
Addicted to Zandronum
Posts: 2219
Joined: Mon Jun 04, 2012 5:38 pm
Location: Omnipresent

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

#5

Post by Ivan » Sun Sep 17, 2017 2:41 pm

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...
=== RAGNAROK DM ON ... uh... dead forever? ===
=== ALWAYS BET ON ... uh... dead forever? ===
=== Who wanta sum wang? ===
=== Death and Decay - A new Monster/Weapon replacer ===

Catastrophe
Retired Staff / Community Team Member
Posts: 2558
Joined: Sat Jun 02, 2012 2:44 am

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

#6

Post by Catastrophe » Sun Sep 17, 2017 4:59 pm

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.

User avatar
Ivan
Addicted to Zandronum
Posts: 2219
Joined: Mon Jun 04, 2012 5:38 pm
Location: Omnipresent

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

#7

Post by Ivan » Sun Sep 17, 2017 8:52 pm

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.
=== RAGNAROK DM ON ... uh... dead forever? ===
=== ALWAYS BET ON ... uh... dead forever? ===
=== Who wanta sum wang? ===
=== Death and Decay - A new Monster/Weapon replacer ===

Post Reply