Not logged inOpenClonk Forum
Up Topic Development / Developer's Corner / Remove AsyncRandom() script function
- - By Sven2 [us] Date 2016-04-25 19:07
"We couldn't think of any reason you'd want to use this over regular Random() in script."

Sometimes there are situations where script callbacks are not synchronized. While they are best avoided, it's not always feasible and the idea is that you do only non-sync-changing stuff in them.

For example I think there used to be a "MusicFinished"-callback that allowed a script to play the next piece. This was probably when AsyncRandom was added. It was later replaced by Playlists. I think portrait assignment also used AsyncRandom because portraits were not synchronized.

I also added an AsyncGet-callback to custom properties in the new editor because I want them to work when multiple people are editing in paused mode. They just call stuff like GetColor(), but they may also want to call AsyncRandom at some point.
Parent - By Maikel Date 2016-04-25 20:20
Just a side note: If one adds it again, please only with corresponding documentation and an example.
Parent - By Luchs [de] Date 2016-04-25 20:28
Okay. Isilkor also suggested renaming to "UnsyncedRandom()", which is also the new name of "SafeRandom()" now.
Parent - - By Isilkor Date 2016-04-27 12:52

> For example I think there used to be a "MusicFinished"-callback that allowed a script to play the next piece. This was probably when AsyncRandom was added. It was later replaced by Playlists. I think portrait assignment also used AsyncRandom because portraits were not synchronized.


Guenther and me had a look through the old RWD repository and nothing in there uses AsyncRandom, so what it was intended for is anyone's guess.

> I also added an AsyncGet-callback to custom properties in the new editor because I want them to work when multiple people are editing in paused mode. They just call stuff like GetColor(), but they may also want to call AsyncRandom at some point.


This sounds extremely dangerous and I'd rather limit those kinds of property accessors to only call pure functions.
Reply
Parent - By Sven2 Date 2016-04-27 15:11

> Guenther and me had a look through the old RWD repository and nothing in there uses AsyncRandom, so what it was intended for is anyone's guess.


I think Soeren wanted to use it in "Ruf der Wipfe" (that's why we also had that weird GetTime() function which only worked in non-network). But I don't know if was ultimately used.

Anyway, we can just re-add it when we need it.
Parent - - By PeterW [gb] Date 2016-04-27 16:07
If it helps - I have no idea either. Actually didn't even know it existed.
Parent - - By Clonkonaut [de] Date 2016-04-27 16:08
How can you not having an idea help in any way? ;P
Reply
Parent - - By PeterW [gb] Date 2016-04-27 17:03
It might help reach the conclusion to remove it. Maybe.
Parent - - By Sven2 [us] Date 2016-04-27 17:43
It was already removed. I just wanted to comment on the commit message "We couldn't think of any reason you'd want to use this over regular Random() in script.".
Parent - - By Clonkonaut [de] Date 2016-04-27 18:20
loop
{
if (AsyncRandom(2))
  return EliminatePlayers();
if (GetPlayerCount() == 1)
  GameOver();
}


Thrilling fun with RandomElimination.ocs! Who might win?
Reply
Parent - By K-Pone [de] Date 2016-04-27 18:24
Looks like a possible bugfix for the Angry Tools game in Clonkfest ;)
Parent - By PeterW [gb] Date 2016-04-27 18:31 Edited 2016-04-27 18:35
Hm, rather hard to say. I think the host has better changes though - the client needs to guess every random number right all the way until the first game over check, otherwise they'd lose due to desync. On the other hand, the desync check doesn't happen very often for release builds... So then again it might not matter.
Parent - By Günther [de] Date 2016-04-29 02:12

> Guenther and me had a look through the old RWD repository and nothing in there uses AsyncRandom, so what it was intended for is anyone's guess.


To elaborate, the script function is Sven2's fault:

> + Added AsyncRandom for script" (2007)


The curious thing is that he didn't add the implementation, which already existed in the initial revision, containing 4.65, but wasn't exported for some lost reason. It's only a trivial wrapper around SafeRandom, which is actually used for various things in the engine.
Reply
Up Topic Development / Developer's Corner / Remove AsyncRandom() script function

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill