ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


functions:syncvariable

Table of Contents

SyncVariable

void SyncVariable(int tid, num value)

num - any numeric type (int or fixed)

Description

Synchronizes an arbitrary numeric variable from server to all clients using an unused tid. The synchronized value can be read clientside using GetSyncVar and GetSyncVarDefault.

SyncVariable optimizes network traffic to only send packets if the synchronized variable is different.

This function works by spawning an undetectable indestructible actor the first time it's called and using its Speed property to synchronize the value.

You can't synchronize strings this way because dynamic string indices are different between the server and the client. To synchronize strings, use a custom serverside string cvar in CVARINFO.

Examples

This function is intended to be used every tic in a single serverside OPEN script:

script "SyncVariables" OPEN
{
	SyncVariable(TID_LIVESCOUNT, Lives);
	SyncVariable(TID_LIVINGMONSTERCOUNT, LivingMonsterCount());
	SyncVariable(TID_LIFEGAIN, GainedLives);
	Delay(1);
	restart;
}

This makes property synchronization immediate and efficient (no net traffic when no property changes happen).

functions/syncvariable.txt · Last modified: 2018/02/19 23:01 by korshun