ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


functions:syncvariable

This is an old revision of the document!


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 retrieved using GetSyncVar and GetSyncVarDefaut. If SyncVariable is called twice with the same value, no network traffic happens.

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.1500214923.txt.gz · Last modified: 2017/07/16 17:22 by korshun