I figured it out! I just needed to see an example of how to get an optional value, which I found in this example here.
Er, it was also clearly outlined in the Option documentation.
Whatever, here’s a summary for anyone else who is new to this. Basically, to initialize a variable:
var BusReference : ?fort_vehicle = false
Then to set it:
set BusReference = option{RealBus}
Then to get from it:
if(MyVehicle:= BusReference?):
Print("bus location: {MyVehicle.GetTransform().Translation}")
Full code below:
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Vehicles }
simple_vehicle_location := class(creative_device):
@editable MyButton : button_device = button_device{}
@editable BusSpawner : vehicle_spawner_armored_battle_bus_device = vehicle_spawner_armored_battle_bus_device{}
#create a reference to the bus, which is false for now. so it uses the ?fort_vehicle syntax to be false.
var BusReference : ?fort_vehicle = false
var BusPosition : vector3 = vector3{X:=0.0,Y:=0.0,Z:=0.0}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
BusSpawner.SpawnedEvent.Subscribe(OnStoreBus)
MyButton.InteractedWithEvent.Subscribe(OnButtonPressed)
OnStoreBus(RealBus : fort_vehicle):void =
# here, when setting the ?fort_vehicle, we need to use option
set BusReference = option{RealBus}
set BusPosition = RealBus.GetTransform().Translation # this works!
Print("bus location: {RealBus.GetTransform().Translation}") #this works!
OnButtonPressed (Agent: agent):void =
if(MyVehicle:= BusReference?): # THIS is the format!
Print("bus location: {MyVehicle.GetTransform().Translation}") # this works!!!