I was followed this tutorial and Code is
GM_countdown_timer_01.verse
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/UI }
using { /Verse.org/Colors }
using { /Verse.org/Simulation }
MakeCountdownTimer<constructor><public>(MaxTime : float, InPlayer : agent) := GM_countdown_timer_01:
RemainingTime := MaxTime
MaybePlayerUI := option{GetPlayerUI[player[InPlayer]]}
GM_countdown_timer_01 := class:
<# This block runs for each instance of the countdown_timer class.
We can setup the canvas once here. #>
block:
set Canvas = canvas:
Slots := array:
canvas_slot:
Anchors := anchors:
Minimum := vector2{X := 0.5, Y := 0.05}
Maximum := vector2{X := 0.5, Y := 0.05}
Alignment := vector2{X := 0.5, Y := 0.0}
Offsets := margin{Top := 0.0, Left := 50.0, Bottom := 0.0, Right := 0.0}
SizeToContent := true
Widget := AddedTimeWidget
canvas_slot:
Anchors := anchors:
Minimum := vector2{X := 0.5, Y := 0.05}
Maximum := vector2{X := 0.5, Y := 0.05}
Alignment := vector2{X := 0.5, Y := 0.0}
Offsets := margin{Top := 25.0, Left := 0.0, Bottom := 0.0, Right := 0.0}
SizeToContent := true
Widget := RemainingTimeWidget
CountdownEndedEvent<publi`Preformatted text`c> : event() = event(){}
StartCountdown<public>() : void =
Print("Starting countdown")
if (PlayerUI := MaybePlayerUI?):
PlayerUI.AddWidget(Canvas)
# Update the UI when we start the timer to see the initial RemainingTime on screen
UpdateUI()
spawn:
RunCountdown()
AddRemainingTime<public>(Time : float) : void =
set RemainingTime += Time
# Immediately update the UI for better player feedback when time is added.
UpdateUI()
# Fire a simple callout to show the time being added.
spawn:
AddedTimeCallout(Time)
MaybePlayerUI<internal> : ?player_ui = false
var RemainingTime<internal> : float = 0.0
RemainingTimeWidget<private> : text_block = text_block{DefaultTextColor := NamedColors.White}
AddedTimeWidget<private> : text_block = text_block{DefaultTextColor := NamedColors.White}
AddedTimeText<private><localizes>(AddedTime : int) : message = " +{AddedTime}!"
RemainingTimeText<private><localizes>(CurrentRemainingTime : int) : message = "{CurrentRemainingTime}"
var Canvas<private> : canvas = canvas{}
var TotalTime<private> : float = 0.0
# The timer "precision": how often, in seconds, it ticks.
TimerTickPeriod<private> : float = 0.5
RunCountdown<private>()<suspends> : void =
# We loop with the TimerTickPeriod.
# The UI is also updated each time.
loop:
Sleep(TimerTickPeriod) # Wait TimerTickPeriod seconds before updating the UI again.
set TotalTime += TimerTickPeriod
set RemainingTime -= TimerTickPeriod # Update how much time is left in the countdown after waiting
UpdateUI()
# Timer End
if (RemainingTime <= 0.0):
if (PlayerUI := MaybePlayerUI?):
PlayerUI.RemoveWidget(Canvas)
CountdownEndedEvent.Signal()
break
AddedTimeCallout<private>(Time : float)<suspends> : void =
if:
PlayerUI := MaybePlayerUI?
IntTime := Int[Time]
then:
AddedTimeWidget.SetVisibility(widget_visibility.Visible)
AddedTimeWidget.SetText(AddedTimeText(IntTime))
Sleep(2.0)
AddedTimeWidget.SetVisibility(widget_visibility.Hidden)
UpdateUI<private>() : void =
if (IntTime := Int[RemainingTime]):
RemainingTimeWidget.SetText(RemainingTimeText(IntTime))
GM_countdown_timer_example_01.verse
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/UI }
GM_countdown_timer_example_01 := class(creative_device):
@editable
AddMoreTimeButton : button_device = button_device{}
@editable
PauseButton : button_device = button_device{}
@editable
ResumeButton : button_device = button_device{}
@editable
RestartButton : button_device = button_device{}
@editable
EndGame : end_game_device = end_game_device{}
var CountdownTimer : GM_countdown_timer_01 = GM_countdown_timer_01{}
InitialCountdownTime : float = 7.5
OnBegin<override>()<suspends>:void=
AddMoreTimeButton.InteractedWithEvent.Subscribe(OnButtonInteractedWith)
if:
FirstPlayer := Self.GetPlayspace().GetPlayers()[0]
PlayerUI := GetPlayerUI[player[FirstPlayer]]
then:
set CountdownTimer = GM_countdown_timer_01{MaybePlayerUI := option{PlayerUI}, RemainingTime := InitialCountdownTime}
CountdownTimer.StartCountdown()
CountdownTimer.CountdownEndedEvent.Await()
EndGame.Activate(FirstPlayer)
else:
Print("Can't find player")
PauseButton.InteractedWithEvent.Subscribe(OnButtonInteractedWith)
if:
FirstPlayer := Self.GetPlayspace().GetPlayers()[0]
PlayerUI := GetPlayerUI[player[FirstPlayer]]
then:
set CountdownTimer = GM_countdown_timer_01{MaybePlayerUI := option{PlayerUI}, RemainingTime := InitialCountdownTime}
CountdownTimer.StartCountdown()
CountdownTimer.CountdownEndedEvent.Await()
EndGame.Activate(FirstPlayer)
else:
Print("Can't find player")
OnButtonInteractedWith(Agent : agent) : void =
TimeToAdd : float = 2.0
CountdownTimer.AddRemainingTime(TimeToAdd)
but it seems like very hard to make PAUSE, RESUME, RESTART by buttons.
Anyone know about make this?