Hi, I am working on a startup routine that puts players on 1v1 teams and the rest as spectators, and lets players choose weapons. I need to add a 1 second timer between changing classes so that it doesn’t bug if the player is standing on top of the class selector, and end up giving them the wrong weapons. I am getting an error if I try to add a sleep(1.0) function inside an if(): clause that says this type of function isn’t allowed here, So now I have a bunch of timers on my map that basically act as sleep functions. Is there a better solution?
Thanks!
1 Like
Yes you can’t put Sleep() inside if() statements, can you provide your code snippet please ?
The only thing I could think of would be to make it async but idk how Verse works in that way
Here’s a short bit of code I use when the players pick a team in my 1v1
OnButtonInteractedWith() : void =
if(s1 := Switch1.GetCurrentState[]):
if(s2 := Switch2.GetCurrentState[]):
Switch1.Disable()
Switch2.Disable()
timerpickteam.Disable()
walltimer.Start()
#DamageVolume.Enable()
timer3.Start()
timer4.Start()
#trigger.Trigger()
It isn’t formatted well because I was experimenting, but basically once both players ready up it will eliminate them with a damage volume, and I have a different damage volume to eliminate the spectators after so that they spectate the players and don’t get bugged into a respawn in the sky. So basically I just have to wait one second after the first damage volume is turned on to disable it and turn the other one on. So I eventually used timer3 and timer4 to initiate the damage volumes at the correct time, then activate the trigger. But I would much rather use a Sleep() function because its really hard to change the code later without comments etc…
And also I plan on using a mutator zone and running a foreach loop on players of team, sending a Damage() function rather than a damage volume device, but this is as far as I got.
Here you go :
OnButtonInteractedWith() : void =
spawn{_OnButtonInteractedWith()}
_OnButtonInteractedWith()<suspends> : void =
if(s1 := Switch1.GetCurrentState[]):
if(s2 := Switch2.GetCurrentState[]):
Switch1.Disable()
Switch2.Disable()
timerpickteam.Disable()
walltimer.Start()
#DamageVolume.Enable()
Sleep(1.0) # Put this wherever you want
timer3.Start()
timer4.Start()
#trigger.Trigger()
2 Likes