Using creative_device classes as an editable requires it to be optional.

This took me a while to figure out…

I was trying to make a quest system where I had a quest which made of an array of tasks and the tasks held all the information about that part of the quest. I also have a npc_device which I was using to tie a character_device and popup_dialog_device together.

I’ve shaired the relivate code below, and will explain the behavior I was getting.

When I was trying to get a NPC from a task like NPC2 it was always returning a default npc_device regardless on if it was set in the editor or not. So Debug2 was printing out “A name goes here”. Once I switch to making my npc_devices optional like NPC1 I could now actually get the proper npc_device, and Debug1 prints “found npc” " NPC.name".

npc_device := class(creative_device):
    @editable
    CharacterDevice : character_device = character_device {}
    @editable
    DialogDevice: popup_dialog_device =  popup_dialog_device {}

    @editable
    Name: string = "A name goes here"

task := class<concrete>:
    
    @editable
    Dialog : string = "This is the default npc message"
    @editable
    Options : []string = array {} 
    @editable
    NPC1 : ?npc_device = false
    @editable
    NPC2 : npc_device = npc_device {}

    Debug1(): void = 
        if(NPC := NPC_Giver?):
            Print("found npc")
            Print(NPC.Name)
        else:
            Print("There was no NPC found")

    Debug2(): void = 
        Print(NPC_Return.Name)

The more I use verse and the more familiar I get with optional the more I understand what they’re good for. I think in this case using an optional is better anyways, but if feels like both should work.