Desyncs

2 replies [Last post]
Greenhead352
Greenhead352's picture
User offline. Last seen 28 weeks 3 days ago. Offline
Joined: 2023-08-19
Posts: 5

Hi , i made a kaos mod (first mod ive made) but it keeps desyncing on round 2 when i play with other people Sad Smiley , do i have to do anything else for it to work?

Greenhead352
Greenhead352's picture
User offline. Last seen 28 weeks 3 days ago. Offline
Joined: 2023-08-19
Posts: 5

figured it out, lua's random wouldnt work

Wuzzy
Wuzzy's picture
User offline. Last seen 29 weeks 2 days ago. Offline
Joined: 2012-06-20
Posts: 1304

Yes, indeed. Using math.random for gameplay-related events like setting the position of a hedgehog is strictly forbidden!

The reason for that is because math.random isn't synchronized between the clients and each client might generate different random numbers, thus causing clients to end up in a different state so they're no longer synchronized and the game must fail for that reason.

That doesn't mean you can't use math.random ever. For things that don't affect gameplay, like purely graphical effects, math.random is safe.

I just noticed the HWKB page for Lua code rules didn't mention math.random so far, so I added it right now. (math.random was only mentioned at the GetRandom function documentation so this could have been overlooked easily)

LuaRules

Hi, I am a Hedgewars developer. Smile

User login

Copyright © 2004-2024 Hedgewars Project. All rights reserved. [ contact ]