How to reset and sync netwrite [solved]

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Post Reply
User avatar
djhubertus
Translator
Translator
Posts: 1252
Joined: 09 Jul 2012, 18:30
Location: Poland
Contact:

How to reset and sync netwrite [solved]

Post by djhubertus » 15 Sep 2014, 22:21

Hi, I have a problem regarding manialinks and netwrites.

For example, I built shop and in manialink I'm sending netwrite array, what player bought. My question is, how to reset this? I'm trying with foreach(Player in Players) to set netwrite values to 0 or False but it doesn't work.
My Gamemodes:
MP4 - Countdown, Firefight
MP3 - Reduction, Overload, Flashpoint, Territory, SM Race, Escape
MP2 - Search & Destroy, Oscillation, Instagib

GabrielM
Posts: 243
Joined: 13 Jan 2012, 16:53

Re: How to reset and sync netwrite

Post by GabrielM » 16 Sep 2014, 09:14

Could you send a sample of your code to get a better and more precise idea of your issue ?

Don't forget netwrite value are only writable from the side you declared them (client or server side).
But you can read them from both.


One way of reseting a netwrite array could be :


If you declared it Server side

Code: Select all

foreach(Player in Players)
{
   declare UI <=> UIManager.GetUI(Player);
  
   if(UI != Null) 
   {
      declare netwrite Text[] Net_MyTextArray for UI; // To access your array
      Net_MyTextArray.clear();  // To clear/reset it
   } 
}

But if you declared it client side :

Code: Select all

declare netwrite Text[] Net_MyTextArray for UI; 
Net_MyTextArray.clear(); 

User avatar
djhubertus
Translator
Translator
Posts: 1252
Joined: 09 Jul 2012, 18:30
Location: Poland
Contact:

Re: How to reset and sync netwrite

Post by djhubertus » 16 Sep 2014, 10:26

I will send you sample later but I think your answer bring me more knowledge ;) Thank you :thx:

I declared netwrite on client-side manialink and on server-side. That's why values are not similar.I will build additional client-side manialink to reset the data.
My Gamemodes:
MP4 - Countdown, Firefight
MP3 - Reduction, Overload, Flashpoint, Territory, SM Race, Escape
MP2 - Search & Destroy, Oscillation, Instagib

GabrielM
Posts: 243
Joined: 13 Jan 2012, 16:53

Re: How to reset and sync netwrite

Post by GabrielM » 16 Sep 2014, 13:17

djhubertus wrote:I declared netwrite on client-side manialink and on server-side.
You cannot declare the same netwrite Value on both side. You can declare it as a "netwrite" on one side, but then it has to be declared as a "netread" on the other side.

User avatar
djhubertus
Translator
Translator
Posts: 1252
Joined: 09 Jul 2012, 18:30
Location: Poland
Contact:

Re: How to reset and sync netwrite

Post by djhubertus » 17 Sep 2014, 10:27

I wrote this sample away of PC.

Code: Select all

[...]
***StartMap***
***
foreach(Player in Players)
{
	declare UI <=> UIManager.GetUI(Player);
	if(UI == Null) continue;
	declare netwrite Net_ServerWantReset for UI = False;
	Net_ServerWantReset = True;
}
***

[...]

***OnPlayerAdded***
***
declare UI <=> UIManager.GetUI(Player);
if(UI == Null) continue;
declare netwrite Net_ServerWantReset for UI = False;
Net_ServerWantReset = True;
***

[...]

***PlayLoop***
***
if(G_LastUpdate + 1250 >= Now)
{
	G_LastUpdate = Now;
	foreach(Player in Players)
	{
		declare UI <=> UIManager.GetUI(Player);
		if(UI == Null) continue;
		declare netwrite Net_ServerWantReset for UI = False;
		declare netread Net_ClientDoReset for UI = False;
		if(Net_ClientDoReset) Net_ServerWantReset = False;
	}
}
***

[...]

Text UpdateLayerProgression()
{
	return """
[...]

main()
{
	while(True)
	{
		if(InputPlayer == Null) continue;
		
		declare netread Net_ServerWantReset for UI = False;
		declare netwrite Net_StaminaUL for UI = 0;
		declare netwrite Net_JumpUL for UI = 0;
		declare netwrite Net_ArmorUL for UI = 0;
		declare netwrite Net_AmmoSpeedUL for UI = 0;
		declare netwrite Net_AmmoUL for UI = 0;
		declare netwrite Net_UsedPoints for UI = 0;
		declare netwrite Net_ClientDoReset for UI = False;

		if(Net_ServerWantReset && !Net_ClientDoReset)
		{
			Net_UsedPoints = 0;
			Net_StaminaUL = 0;
			Net_JumpUL = 0;
			Net_ArmorUL = 0;
			Net_AmmoSpeedUL = 0;
			Net_AmmoUL = 0;
			Net_ClientDoReset = True;
		}
		else if(!Net_ServerWantReset) Net_ClientDoReset = False;
[...]
So UpdateLayerProgression() is called to all alive players, if someone is joining to game/new map is coming - I want to reset the whole data to init values. So I made something like this and the problem is, that only Net_UsedPoints is cleared to 0.
My Gamemodes:
MP4 - Countdown, Firefight
MP3 - Reduction, Overload, Flashpoint, Territory, SM Race, Escape
MP2 - Search & Destroy, Oscillation, Instagib

User avatar
steeffeen
Translator
Translator
Posts: 2472
Joined: 14 Oct 2012, 16:22
Location: Germany

Re: How to reset and sync netwrite

Post by steeffeen » 17 Sep 2014, 10:45

in most cases it's better to use timestamps for such async stuff
instead of using a boolean for ServerWantReset simply set an integer to Now
on the client save the last timestamp and perform the reset as soon as the value changes (+ save the new timestamp)

like that you only have a one-way communication (saves network)
and you can be sure that it's working correctly, because a second reset right after the first one will still be performed while the boolean could still be True and the client wouldn't be informed about the second trip
    Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

    ManiaControl, FancyManiaLinks

    User avatar
    djhubertus
    Translator
    Translator
    Posts: 1252
    Joined: 09 Jul 2012, 18:30
    Location: Poland
    Contact:

    Re: How to reset and sync netwrite

    Post by djhubertus » 18 Sep 2014, 14:51

    I change to timestamps and everything works fine :)

    Thank you :thx:
    My Gamemodes:
    MP4 - Countdown, Firefight
    MP3 - Reduction, Overload, Flashpoint, Territory, SM Race, Escape
    MP2 - Search & Destroy, Oscillation, Instagib

    Post Reply

    Return to “ManiaScript”

    Who is online

    Users browsing this forum: No registered users and 1 guest