JASS:
library ValSync
globals
gamecache SyncA = InitGameCache( "SyncA" )
integer AsyncP = 0
boolean IsSync = false
endglobals
function ReadSyncVal takes string StoreCode returns integer
debug if not IsSync then
debug call DisplayTimedTextToPlayer( GetLocalPlayer( ) , 0 , 0 , 60 , "|cffffff00[Synchronization]: You should sync before reading data.|r" )
debug endif
return GetStoredInteger( SyncA , "0" , I2S( GetStoredInteger( SyncA , StoreCode , "0" ) ) )
endfunction
function ExecSync takes player varOwner returns nothing
if not IsSync then
set IsSync = true
call TriggerSyncStart( )
if GetLocalPlayer( ) == varOwner then
loop
exitwhen AsyncP == 0
call SyncStoredInteger( SyncA , "0" , I2S( AsyncP ) )
set AsyncP = AsyncP - 1
endloop
endif
call TriggerSyncReady( )
debug else
debug call DisplayTimedTextToPlayer( GetLocalPlayer( ) , 0 , 0 , 60 , "|cffff0000[Synchronization]: You have already synchronized!|r" )
endif
endfunction
function AddSyncVal takes string StoreCode , integer Var returns nothing
if not IsSync then
if "0" != StoreCode then
set AsyncP = AsyncP + 1
call StoreInteger( SyncA , StoreCode , "0" , AsyncP )
call StoreInteger( SyncA , "0" , I2S( AsyncP ) , Var )
debug else
debug call DisplayTimedTextToPlayer( GetLocalPlayer( ) , 0 , 0 , 60 , "|cffff0000[Synchronization]: You are unable to use the \"0\" as a store string.|r" )
endif
debug else
debug call DisplayTimedTextToPlayer( GetLocalPlayer( ) , 0 , 0 , 60 , "|cffff0000[Synchronization]: Sync table is read only! Clear it before start adding values.|r" )
endif
endfunction
function ClearSync takes nothing returns nothing
set AsyncP = 0
set IsSync = false
call FlushGameCache( SyncA )
set SyncA = InitGameCache( "SyncA" )
endfunction
// Safe calls
globals
player ValSync_TempP = null
endglobals
function ExecSyncFunc takes nothing returns nothing
if ValSync_TempP != null then
call ExecSync( ValSync_TempP )
endif
endfunction
function ExecSync_Safe takes player VarOwner returns nothing
set ValSync_TempP = VarOwner
call ExecuteFunc( "ExecSyncFunc" )
endfunction
endlibrary