Hello!
I have this code and I can’t to remove widget from my screen after I recieved this.
This is my code
using { /Fortnite.com/Devices }
using { /Fortnite.com/UI }
using { /Verse.org/Simulation }
using { /Verse.org/Colors/NamedColors }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Random }
bank_tycoon := class(creative_device):
# Variables of editable elements
@editable PlayerSpawner : player_spawner_device = player_spawner_device{}
@editable GameEnder : end_game_device = end_game_device{}
@editable PlayerGranter : item_granter_device = item_granter_device{}
@editable RefreshRate : float = 0.1
@editable ButtonWork : button_device = button_device{}
@editable WorkInterectionTime : float = 1.0
@editable ButtonExchange : button_device = button_device{}
@editable ExchangeInterectionTime : float = 0.5
@editable ButtonBuyCoinsPerSecond : button_device = button_device{}
@editable BuyCoinsPerSecondInterectionTime : float = 0.5
# Variables of player
var CurrentCoins : int = 0
var CurrentGoldBar : int = 0
var CoinsPerSecond : int = 0
var ExchangeCurrency : int = 100
var ButtonBuyCoinsPerSecondCurrency : int = 20
var CurrentCoinsText : [agent]?text_block = map{}
var CurrentGoldBarText : [agent]?text_block = map{}
var EventTextBlock : [agent]?text_block = map{}
# Variables of tasks
@editable PropManipulatorTask : prop_manipulator_device = prop_manipulator_device{}
@editable ButtonCreateTask : button_device = button_device{}
var AllTasks : [int]string = map{ 1 => "Task1", 2 => "Task2" }
var Task1DamagedCurrencyMin : int = 20
var Task1DamagedCurrencyMax : int = 40
var Task1DestroydCurrencyMin : int = 30
var Task1DestroydCurrencyMax : int = 60
S2M<localizes>(S:string):message="{S}"
OnBegin<override>()<suspends>:void=
PlayerSpawner.SpawnedEvent.Subscribe(PlayerSpawned)
ButtonWork.InteractedWithEvent.Subscribe(OnWork)
ButtonExchange.InteractedWithEvent.Subscribe(OnExchange)
ButtonBuyCoinsPerSecond.InteractedWithEvent.Subscribe(OnBuyCoinsPerSecond)
ButtonCreateTask.InteractedWithEvent.Subscribe(RecieveTask)
PropManipulatorTask.DamagedEvent.Subscribe(TaskOnDamage)
PropManipulatorTask.DestroyedEvent.Subscribe(TaskOnDestroyed)
PlayerSpawned(Agent:agent):void=
Print("Player Spawned")
PlayerGranter.GrantItem(Agent)
if(MyTextBlock:=CurrentCoinsText[Agent]?){}
if(MyTextBlock1:=CurrentGoldBarText[Agent]?){}
else:
AssignUI(Agent)
AssignUI(Agent:agent):void=
Print("Assigning UI")
MainUI:=MakeCanvas(Agent)
if:
PlayerUI:=GetPlayerUI[player[Agent]]
then:
PlayerUI.AddWidget(MainUI)
spawn{RefreshUI(Agent)}
spawn{SummCoinsPerSecond(Agent)}
RefreshUI(Agent:agent)<suspends>:void=
Print("Starting to Refresh")
if:
TextBlock := CurrentCoinsText[Agent]?
TextBlock1 := CurrentGoldBarText[Agent]?
then:
loop:
# Print("Refreshing")
Sleep(RefreshRate)
TextBlock.SetText(S2M("Coins: {CurrentCoins}/+{CoinsPerSecond} per s"))
TextBlock1.SetText(S2M("Gold bar's: {CurrentGoldBar}"))
MakeCanvas(Agent:agent):canvas=
Print("Making Canvas")
MyTextBlock:=text_block:
DefaultTextColor:=Yellow
MyTextBlock1:=text_block:
DefaultTextColor:=Yellow
if(set CurrentCoinsText[Agent] = option{MyTextBlock}){}
if(set CurrentGoldBarText[Agent] = option{MyTextBlock1}){}
MainUI:=canvas:
Slots:=array:
canvas_slot:
Widget:=MyTextBlock
Anchors:=anchors{Minimum:=vector2{X:=0.0,Y:=0.0},Maximum:=vector2{X:=1.0,Y:=1.0}}
Offsets:=margin{Left:=100.0,Top:=206.0,Right:=1680.0,Bottom:=829.0}
canvas_slot:
Widget:=MyTextBlock1
Anchors:=anchors{Minimum:=vector2{X:=0.0,Y:=0.0},Maximum:=vector2{X:=1.0,Y:=1.0}}
Offsets:=margin{Left:=100.0,Top:=276.0,Right:=1680.0,Bottom:=764.0}
return MainUI
OnWork(Agent:agent):void=
ButtonWork.SetInteractionTime(WorkInterectionTime)
Print("Player working")
set CurrentCoins = CurrentCoins + 10
OnExchange(Agent:agent):void=
ButtonExchange.SetInteractionTime(ExchangeInterectionTime)
if (CurrentCoins >= ExchangeCurrency):
set CurrentCoins = CurrentCoins - ExchangeCurrency
set CurrentGoldBar = CurrentGoldBar + 1
Print("Player exchanging")
else:
Print("Exchenging Error")
OnBuyCoinsPerSecond(Agent:agent):void=
ButtonBuyCoinsPerSecond.SetInteractionTime(BuyCoinsPerSecondInterectionTime)
if (CurrentCoins >= ButtonBuyCoinsPerSecondCurrency):
set CurrentCoins = CurrentCoins - ButtonBuyCoinsPerSecondCurrency
set CoinsPerSecond = CoinsPerSecond + 1
Print("Player bought coins per second")
else:
Print("Bought coins per second Error")
SummCoinsPerSecond(Agent:agent)<suspends>:void=
loop:
set CurrentCoins = CurrentCoins + CoinsPerSecond
Sleep(1.0)
TaskOnDamage(Agent:agent):void=
Print("Player damaged prop")
RecievedCoins := GetRandomInt(Task1DamagedCurrencyMin, Task1DamagedCurrencyMax)
set CurrentCoins = CurrentCoins + RecievedCoins
if (Player := player[Agent], PlayerUI := GetPlayerUI[Player]):
PlayerUI.AddWidget(EventUI(Agent))
if:
TextBlock2 := EventTextBlock[Agent]?
then:
TextBlock2.SetText(S2M("+{RecievedCoins} Coins"))
HIIIdw(Agent)
TaskOnDestroyed(Agent:agent):void=
Print("Player destroyd prop")
set CurrentCoins = CurrentCoins + GetRandomInt(Task1DestroydCurrencyMin, Task1DestroydCurrencyMax)
RecieveTask(Agent:agent):void=
Print("Start creating task")
RecievedTask:=GetRandomInt(1, AllTasks.Length)
Print("Recieved task number {RecievedTask}")
case(RecievedTask):
1 =>
PropManipulatorTask.ShowProps()
2 =>
Print("The task isn't ready in development!")
_ =>
return
EventUI (Agent:agent):canvas=
EventText:=text_block:
DefaultTextColor:=Yellow
if(set EventTextBlock[Agent] = option{EventText}){}
NewCanvas : canvas = canvas:
Slots := array:
canvas_slot:
Widget:=EventText
Anchors:=anchors{Minimum:=vector2{X:=0.0,Y:=0.0},Maximum:=vector2{X:=1.0,Y:=1.0}}
Offsets:=margin{Left:=100.0,Top:=392.0,Right:=1680.0,Bottom:=648.0}
HIIIdw(Agent:agent):void=
if (Player := player[Agent], PlayerUI := GetPlayerUI[Player]):
PlayerUI.RemoveWidget(EventUI(Agent))