I took the code you provided and paired it down to just the essentials to get things working. Below is a recap of the setup.
Code
countdown_timer := class(creative_device):
@editable
GameInfo:game_info = game_info{}
OnBegin<override>()<suspends>:void =
Print("CountdownTimer.OnBegin")
RunCountdown()
RunCountdown<private>()<suspends> : void =
Print("CountdownTimer.RunCountdown")
loop:
Sleep(2.0)
PlayerCount := GetPlayspace().GetPlayers().Length
if (PlayerCount >= 1):
GameInfo.StartGame() #HERE
break
game_info := class(creative_device):
@editable
SpawnInfo:spawn_info = spawn_info{}
StartGame<public>():void =
Print("GameInfo.StartGame")
SpawnInfo.TeleportToMap(1)
spawn_info := class<concrete>(creative_device):
var TeleportNow<public>:logic = false
var Map:int = 0
OnBegin<override>()<suspends> : void =
loop:
Sleep(1.0)
if (TeleportNow = true):
Print("Teleporting now to Map #{Map}")
set TeleportNow = false
TeleportToMap<public>(SelectedMap:int) : void =
Print("SpawnInfo.TeleportToMap({SelectedMap})")
set Map = SelectedMap
set TeleportNow = true
Device setup in scene
Playing
Details
- Each of the devices is set up to chain into one another: countdown_timer → game_info-> spawn_info.
- CountDownTimer.OnBegin runs first, triggering RunCountdown()
- At the same time SpawnInfo.OnBegin runs, which puts it into the loop waiting for “TeleportNow” to be true
- After 2s CountDownTimer.RunCountdown wakes up, checks the player count, then triggers GameInfo.StartGame()
- GameInfo.StartGame() sets TeleportNow to
true
on SpawnInfo - At the next check SpawnInfo.OnBegin sees that TeleportNow is true and prints “Teleporting now to Map #{Map}”.
Next steps
I have a few debugging suggestions/ideas that might help to figure out what part of your code isn’t working.
- You could make a separate device that has a reference to SpawnInfo. In the OnBegin have it call SpawnInfo.TeleportToMap(0). This way you can make sure things are mostly working there and your “print3” gets into the log. Once that is working you could work your way out, moving the OnBegin into GameInfo, which would then trigger SpawnInfo. Continue until you figure out where it started breaking.
- Based on some of the previous code snippets I suspect there might be a few other hidden cases around where Verse device classes are being constructed anew in code instead of drag/dropped from the content browser. Creating instances of classes works for regular Verse classes but it doesn’t work for Verse Devices. So any time that is happening it is going to cause problems.
- I would check the logs for any Verse errors that are present. I think that if you forget to hook up @editable properties for devices then the device might fail while your game will still run.
Let me know how that goes. Hope this helps in some way.