First you need to know that the script of the gamemode and the manialink inside are two separate layers which don't communicate with each other initially. The script is run on the server while the manialink is read locally on the computer of the player. To make it so, you need to use a "new" type of variable which will be read by the script and the manialink.
It works like an "input/output" system in simple language. In a logic sense, you must create first an "output" variable, symbolized with the parameter netwrite
in ManiaScript. This parameter tell that the variable will register/put a value to send to the other layer (the script or the manialink):
declare netwrite Integer Net_MyVariable for UI;
The "for UI" means that the variable is adressed to a specific player (first you have to retrieve the UI of the player with the instruction declare UI <=> UIManager.GetUI(Player);
)
Instead of retrieving all the UIs if the variable is addressed for all players, you can specify
for Teams[0]
orfor Teams[1]
orfor This
This type of variable (netwrite/netread) doesn't work with the bots, it'll crash the script if you try do it, so be sure that when you manipulate this type of variable in the script, to exclude the bot from the execution of the code (Tip: the bot doesn't have an UI, so you can do a check when you have retrieve the UI of a player by test it with if(UI != Null)
).
You have to create an "input" variable on the side where you will receive the value of the other part (for example from the script to the variable) with the netread
parameter between the declaration and the type of the variable :
declare netread Integer Net_MyVariable for UI;
You can't name a netread/netwrite variable with the same name of an existing "standard" variable (name conflict).
You can't manipulate the value of a netread
variable (or the script will crash).
There is a tool that can be usefull in ManiaScript to count the amount of datas exchanged between server and clients.
log(Dbg_DumpDeclareForVariables(Teams[0], False));
This function return a big text with every network variable in the Nod you put in, can be Teams[0]
, Teams[1]
, This
, UI
, etc…
You will see the number of variables and total size on top and then one line of details per variables.
Take in mind that more datas you will send to clients through network, more it will use the bandwitch and can cause lag on client and server side.
Example of return on a gamemode (not full, too much datas) :
netwrite: 78 values (9494 bytes)
86: Text[] Net_LibUI3_Modules = [???]
32: Integer Net_LibUI3_ModulesUpdate = 189
40: Integer Net_LibRaceWarmUp_WarmUpPlayedNb = 1
40: Integer Net_LibRaceWarmUp_WarmUpDuration = 1
45: Boolean Net_Race_WarmupHelpers_IsWarmupActive = False
41: Boolean Net_LibRaceWarmUp_LayerVisibility = True
45: Integer Net_LibRaceWarmUp_LayerPositionUpdate = 189
47: Vec3 Net_LibRaceWarmUp_LayerPosition = <153., 0., 0.>
43: Boolean Net_SplitScreen_PauseMenu_IsVisible = True
44: Boolean Net_Race_PauseMenuOnline_IsLocalMode = False
56: Boolean Net_Race_PauseMenuOnline_IsPreviousReplayAllowed = False
88: Text Net_Race_PauseMenuOnline_Help_Description = "$lhttps://trackmania-formula-league.com"
35: Integer Net_Race_Record_SetupUpdate = 17
38: Boolean Net_Race_Record_PBGhostEnabled = False
35: Boolean Net_Race_Record_CelebratePB = False
36: Boolean Net_Race_Record_MedalEnabled = False
38: Boolean Net_Race_Record_CelebrateMedal = False
35: Text Net_Race_Record_ScopeSeason = ""
38: Text Net_Race_Record_ScopeNotSeason = ""
32: Text Net_Race_Record_ModeName = ""
34: Text Net_Race_Record_CustomData = ""
38: Boolean Net_Race_Record_DisplayRecords = False
41: Boolean Net_Race_Record_NewRecordsEnabled = False