I have two verse code files, everything works until I add the block of code where it updates every second. I need to update so that I can display player’s real time money. Please help, I will be very thankful.
using { /Verse.org/Simulation }
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters}
using { /UnrealEngine.com/Temporary/UI }
countdown_timer_example := class(creative_device):
var PlayerMoney : int = 50
var TillPortal : int = 100
var CountdownTimer : countdown_timer = countdown_timer{}
@editable
Portal1 : conditional_button_device = conditional_button_device{}
@editable
Portal2 : conditional_button_device = conditional_button_device{}
@editable
Portal3 : conditional_button_device = conditional_button_device{}
@editable
Portal4 : conditional_button_device = conditional_button_device{}
@editable
GoldCounter: conditional_button_device = conditional_button_device{}
CountGold(Agent: agent): int=
# Assuming you only inserted gold in the button so the index of gold is 0
Amount:= GoldCounter.GetItemCount(Agent, 0)
CountdownTimer.UpdateUI(Amount, TillPortal)
return Amount
IteratingCounter()<suspends>: void=
for (Player: GetPlayspace().GetPlayers(), FortCharacter := Player.GetFortCharacter[]):
CountGold(Player)
set PlayerMoney = CountGold(Player)
Print("Player has {CountGold(Player)} gold")
CountdownTimer.UpdateUI(CountGold(Player), TillPortal)
OnBegin<override>()<suspends>: void=
# for every player give this ■■■■
loop:
Sleep(1.0)
spawn:
IteratingCounter()
Portal1.ActivatedEvent.Subscribe(OnButtonInteracted1)
Portal2.ActivatedEvent.Subscribe(OnButtonInteracted2)
Portal3.ActivatedEvent.Subscribe(OnButtonInteracted3)
Portal4.ActivatedEvent.Subscribe(OnButtonInteracted4)
if:
FirstPlayer := Self.GetPlayspace().GetPlayers()[0]
PlayerUI := GetPlayerUI[player[FirstPlayer]]
then:
set CountdownTimer = countdown_timer{Money := PlayerMoney, Portal:= TillPortal, MaybePlayerUI := option{PlayerUI}}
CountdownTimer.StartUI()
else:
Print("Can't find player")
OnButtonInteracted1(Agent : agent) : void =
set TillPortal = 200
CountdownTimer.UpdateUI(PlayerMoney, TillPortal)
OnButtonInteracted2(Agent : agent) : void =
set TillPortal = 500
CountdownTimer.UpdateUI(PlayerMoney, TillPortal)
OnButtonInteracted3(Agent : agent) : void =
set TillPortal = 800
CountdownTimer.UpdateUI(PlayerMoney, TillPortal)
OnButtonInteracted4(Agent : agent) : void =
set TillPortal = 800;
CountdownTimer.UpdateUI(PlayerMoney, TillPortal)
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Simulation }
using { /Fortnite.com/UI }
MakeCountdownTimer(PlayerMoney : int, TillPortal : int, InPlayer : agent) := countdown_timer:
Money := PlayerMoney
Portal := TillPortal
MaybePlayerUI := option{GetPlayerUI[player[InPlayer]]}
countdown_timer := 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.4, Y := 0.3}
Maximum := vector2{X := 0.6, Y := 0.3}
Alignment := vector2{X := 0.5, Y := 0.5 }
Offsets := margin{Top := 0.0, Left := 0.0, Bottom := 0.0, Right := 0.0}
SizeToContent := true
Widget := MyTextBlock
StartUI<public>() : void=
if (PlayerUI := MaybePlayerUI?):
PlayerUI.AddWidget(Canvas)
MyTextBlock.SetText(TextForCanvas(Money, Portal))
UpdateUI<public>(NewMoney : int, NewPortal : int) : void=
MyTextBlock.SetText(TextForCanvas(NewMoney, NewPortal))
MaybePlayerUI<internal> : ?player_ui = false
Money : int = 0;
Portal : int = 0;
MyTextBlock<private> : text_block = text_block{}
var Canvas<private> : canvas = canvas{}
TextForCanvas<localizes><private>(Number1 : int, Number2 : int) : message = "{Number1}/{Number2}"