In OnBegin I first want to be sure the map is filled with a lot of players, preferably maxed out. So what I do is
wait until a 60s timer is done
OR
The playercount = 4
The problem here is my CheckIfMaxPlayers(). The loop causes an issue where the game never starts. Correct me if I am wrong but a good solution would be to turn this CheckIfMaxPlayers function into something so that I can say CheckIfMaxPlayers.Await(), similar to how I wait for the timer.
You could potentially make your loop solution work by adding sleep inside of it, but it’s optimal. I looked around in the digest for a way to trigger an await, and it doesn’t seem to be possible to do this directly. For now, you could achieve this by moving the logic into a separate StartGame function that guards itself to only run once. Here’s an example I made:
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Concurrency }
using { /EpicGames.com/Temporary/Diagnostics }
# If you want
game_start_cause := enum:
Timer
PlayerCount
ToString(Cause: game_start_cause): []char=
case(Cause):
game_start_cause.Timer => "timer running out"
game_start_cause.PlayerCount => "max player count hit"
my_device := class(creative_device):
@editable
WaitingForPlayersTimer: timer_device = timer_device{}
var GameStarted: logic = false
PlayerStartCount: int = 4
OnBegin<override>()<suspends>:void=
Playspace := Self.GetPlayspace()
Playspace.PlayerAddedEvent().Subscribe(OnPlayerAdded)
WaitingForPlayersTimer.SuccessEvent.Subscribe(OnTimerComplete)
OnPlayerAdded(Agent: agent):void=
if (Self.GetPlayspace().GetPlayers().Length = PlayerStartCount):
StartGame(game_start_cause.PlayerCount)
OnTimerComplete(Agent: agent):void=
StartGame(game_start_cause.Timer)
StartGame(Cause: game_start_cause):void=
if (GameStarted?) {
return
}
set GameStarted = true
Print("Game started by {Cause}")
# Put your logic here
Thanks I also had something that looked like this at first. But I did not like having the GameStarted variable. I also did not want to go into a new function (StartGame) but I want to stay in OnBegin
As I understand your request you are mostly using CheckIfMaxPlayers() the right way for it to function like the Await you want. Like ProfessionalBot says though you need to include a Sleep in that function for time to pass, as you have it now it is just infinitely looping and getting the same player count over and over. Changing your code to this should work fine?
You can also use an instance of an event class. That is more efficient than polling with a Sleep() - though sometimes polling is the way to go depending on the situation.
call Await() on the event in any of the places that you want to wait for it
then call Signal() on it to wake it up.
An example of it being used is in the Space Inside / Escape Room’s cinematic_character_device.
I’m not currently at my computer - though it should be under “Feature Experiences” (or something like that) in the “Project Browser” when you start UEFN. Then it is in the Verse files for that project called - cinematic_character_device.verse which you should find in the Verse Explorer.
Could it be that you have some unpublished examples?
I checked all available projects in the “Feature Examples” and there’s nothing close to what you describe.
I could have sworn we had more example projects on day 1 of UEFN such as a prop hunt project but as of right now when you go to Feature Examples you get
I know in the creative hub there are tons of games published by Epic Labs that have plenty of features that most of us would love to inspect. If you are able to recommend some of that be added to the Feature Examples internally that would be so awesome.