Skip to content

Instantly share code, notes, and snippets.

@Lootheo
Created August 16, 2023 16:05
Show Gist options
  • Save Lootheo/0038d481362be8112d2450db760313bd to your computer and use it in GitHub Desktop.
Save Lootheo/0038d481362be8112d2450db760313bd to your computer and use it in GitHub Desktop.
persistence test
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Characters }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
var GlobalInt1:weak_map(session, int) = map{}
var GlobalMap1:weak_map(session, player) = map{}
var GlobalMap2:weak_map(session, [player]int) = map{}
# A Verse-authored creative device that can be placed in a level
persistance_device := class(creative_device):
@editable
AddButton:button_device=button_device{}
@editable
EndRoundButton:button_device=button_device{}
@editable
Billboard:billboard_device=billboard_device{}
@editable
EndRoundDevice:end_game_device=end_game_device{}
@editable
PlayerSpawner:player_spawner_device=player_spawner_device{}
GetBillboardMessage<localizes>(IntMessage : int) : message = "{IntMessage}"
var TestMapLocal:[player]int=map{}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
Print("Round Starting")
UpdateBillboard()
GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)
PlayerSpawner.SpawnedEvent.Subscribe(OnPlayerSpawned)
AddButton.InteractedWithEvent.Subscribe(OnAddButtonPressed)
EndRoundButton.InteractedWithEvent.Subscribe(OnEndRoundButtonPressed)
OnPlayerAdded(InPlayer:player):void=
Print("OnPlayerAdded Test")
if(GlobalMap2[GetSession()]):
Print("OnPlayerAdded player already added")
else if(set GlobalMap2[GetSession()]=map{}):
Print("OnPlayerAdded added")
if(GlobalMap1[GetSession()]):
Print("OnPlayerAdded player already added")
else if(set GlobalMap1[GetSession()]=InPlayer):
Print("OnPlayerAdded added")
OnPlayerSpawned(Agent:agent):void=
Print("Player spawner")
Print("Test")
if(InPlayer:=player[Agent]):
if(GlobalMap1[GetSession()]):
if(Player:=GlobalMap1[GetSession()]):
Print(" OnPlayerSpawned player already added")
if(FortCharacter:=Player.GetFortCharacter[]):
Print("FortCharacter was valid")
else:
Print("fort character was not valid")
else:
Print("Player Reference got lost")
else if(set GlobalMap1[GetSession()]=InPlayer):
Print(" OnPlayerSpawned InPlayer added")
UpdateBillboard():void=
Print("Updating Billboard")
if(FirstPlayer:=GetPlayspace().GetPlayers()[0]):
if(SessionInt:=GlobalMap2[GetSession()][FirstPlayer]):
Billboard.SetText(GetBillboardMessage(SessionInt))
else:
Print("No global int, resetting")
if(set GlobalMap2[GetSession()] = map{}){}
if(set GlobalMap2[GetSession()][FirstPlayer] = 0){}
OnAddButtonPressed(Agent:agent):void=
if(Player:=player[Agent]):
if (Y := GlobalMap2[GetSession()][Player]):
Print("Setting global int {Y}")
if(set GlobalMap2[GetSession()][Player] = Y+1){}
else:
if(set GlobalMap2[GetSession()][Player] = 1){}
if (Y := GlobalMap2[GetSession()][Player]):
Print("Global Int is now: {Y}")
Print("Add Button Pressed ")
UpdateBillboard()
OnEndRoundButtonPressed(Agent:agent):void=
EndRoundDevice.Activate(Agent)
Print("Add Button Pressed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment