Issue with documentation tutorial: "Create your own NPC Medic"

For the “Create your own NPC Medic” tutorial on the documention, in the queue.verse code that the documentation provides, there is a script error. Line 5 for “(t:type)”.

See error from UEFN: queue.verse(5,14, 5,22) : Script error 3502: Can’t access a function from a preceding type.

Any potential solutions?

Link: Create your own NPC Medic

Full code below:

list(t:type) := class:
    Data:t
    Next:?list(t)

queue<public>(t:type) := class<internal>:
    Elements<internal>:?list(t) = false
    Size<public>:int = 0

    Enqueue<public>(NewElement:t):queue(t) =
        queue(t):
            Elements := option:
                list(t):
                    Data := NewElement
                    Next := Elements
            Size := Size + 1

    Dequeue<public>()<decides><transacts>:tuple(queue(t), t) =
        List := Elements?
        (queue(t){Elements := List.Next, Size := Size - 1}, List.Data)

    Front<public>()<decides><transacts>:t = Elements?.Data

CreateQueue<public><constructor>(InData:t where t:type) := queue(t):
    Elements := option:
        list(t):
            Data := InData
            Next := false
    Size := 1

@SatoriFN Thank you for your feedback. While I cannot guarantee a response, I can confirm that this has been forwarded to the appropriate team.

1 Like

Solution:

The code provided in the tutorial has to be in the same .verse file with the queue class code preceding the code found in medic_example.verse. Though not always ideal, it does work.

See this forum post for a previous run in of this issue: Unusable Verse modules

1 Like

Yes, never use generic classes or type aliases across files. It is a ticking bomb and will randomly work or fail.

1 Like

@SatoriFN This is a tricky problem with the current compiler. Parametric classes like the queue are not currently usable outside of their file, but putting the file that calls the generic class in a submodule resolves this. Check step 2.6 in the “Healing Characters inside a volume” of the medic tutorial, that’s the part that covers moving the medic_example into its own separate submodule. In a future version of Verse this step should be unnecessary - parametric classes like queue.verse will be useable in other files regardless of your file structure. You could also implement queue.verse in the file that calls it directly but as you said it’s not always ideal. Check if the file structure in the image I attached resolves the error.

7 Likes

Hi @Microcosms Thanks, this is very helpful. With the new file structure, I don’t have any errors and the medic functions properly.

Thanks for the info about a future version when parametric classes will be useable regardless of file structure–exciting!

Was this fixed in the last update?

THANK YOU! This corrected the issues for me too. I apologize, I really believed I followed the tutorial exactly as written. I am noob. I am learning how to program.