Heyo,
I have this class function in a child/sub class called itemBox. It inherits from the parent/super class spawnableThing. Both have a function called Spawn_this, and it’s overridden in the itemBox child class. In that function I try to cast a creative_object (which could be teleporter devices, collectible_object_devices, anything Fortnite offers as a device…) to the more specific collectible_object_device to do specific functions from that collectible object class. Does anyone know about using classes within classes and parent-child (super-subclass) relationships and why I can’t get the Show() and RespawnForAll() functions of collectible_object_device to actually work?
Notes:
- I made this class called
spawnableThings
spawnableThings
has acreative_object
optional variable calledspawnableDevice
- in the function I try to cast the
creative_object
variable namedspawnableDevice
as acollectibe_object_device
in this case to do more specific things, such as call Show() and RespawnForAll() (which are methods ofcollectible_object_device
)
Here is some simplified reduced code that I made to help show what I’m doing:
# ===================================
# spawnable Thing class
# ===================================
spawnableThing := class<unique><concrete>:
# parent class for spawnable things like item boxes, teleporter class, etc.
# idea was to store any creative device from Fortnite's selection, like collectible object device, teleporter device, etc and then handle general shared things like "teleport to new location" functions without writing those individually in sub classes
var spawnableDevice<protected> : ?creative_object = false
# class functions -----
Spawn_this<public>(itemManager_counter : itemManagerStats, newSpot : spawnableSpot):void =
# "spawn" this object by moving it from original position to new position
# note: specific devices like collectible objects should hide / unhide in their own overrided function of this function
# moving object will be done by spawnableSpot function
# hiding / unhiding object will be done in specific object subclass overridden method
# here, we just set the objects status flags and timer
# ===================================
# itemBox class
# ===================================
itemBox := class<unique><concrete>(spawnableThing):
# class for holding item box info, which is a collectible_object_device that players can collect
# class variables
var isSpecial<private> : logic = false
# class functions -----
Spawn_this<override>(itemManager_counter : itemManagerStats, newSpot : spawnableSpot):void =
# "spawn" this item box object
# moving object will be done by spawnableSpot function
# here, we unhide the object / respawn it
if (thisCollectibleDevice : collectible_object_device = collectible_object_device[spawnableDevice?]):
thisCollectibleDevice.Show()
thisCollectibleDevice.RespawnForAll()
(super:)Spawn_this(itemManager_counter, newSpot) # calls super class version of spawn function to finish setting flags
I’m particularly trying to verify this part is working
if (thisCollectibleDevice : collectible_object_device = collectible_object_device[spawnableDevice?]):
thisCollectibleDevice.Show()
thisCollectibleDevice.RespawnForAll()
(super:)Spawn_this(itemManager_counter, newSpot) # calls super class version of spawn