How to use a nested folder's module in Verse?

Hi. How to access a nested folder’s module in Verse?

For example, if I want to access a module in Sub3.verse placed in the Sub1/Sub2 folder, how should I write the using clause?

Unfortunately, the code below did not work.

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

using { Sub1}
using { Sub2}           #Invalid access of internal module `(/localhost/MyProject230520/Sub1:)Sub2` 
using { Sub1.Sub2}      #Invalid access of internal module `(/localhost/MyProject230520/Sub1:)Sub2` 
using { Sub3}           #Unknown identifier `Sub3`.(3506)
using { Sub1.Sub2.Sub3} #Unknown member `Sub3` in `Sub2`.(3506)
using { Sub1.Sub3}      #Unknown member `Sub3` in `Sub1`.(3506)

testDevice1 := class(creative_device):
    OnBegin<override>()<suspends>:void=
        Print("test")

4 Likes

That’s something I would like to know as well! Haven’t played around with it yet though.

1 Like

Hey, did you manage to resolve this in the end? I’ve seen it working for others but I get the ‘Invalid access of internal module’ no matter what I seem to try.

When you create a subfolder in a verse project, the verse compiler creates a module with an implicit <internal> access specifier. Because of the implicit internal you cannot access the submodule from outside the outer module.

The directory structure Sub1/Sub2/Sub3/SomeClass.verse is equivalent to

Sub1 := module:
    Sub2 := module:
        Sub3 := module:
            # Contents of SomeClass.verse
            some_class := class:
                SomeInt : int = 0

You can, however, explicitly declare the Sub2 module with <public> access specifier like this:

# Sub1/Sub2.verse
Sub2<public> := module{}

You could then access the Sub2 module like this:

# Use Sub1 *and* Sub2 contents
using { Sub1 }
using { Sub2 }

# Use Sub2 *without* using Sub1
using { Sub1.Sub2 }
6 Likes

So, it is not possible to have a structure of folders like Sub1 → Sub2 → Sub3.verse
and use Sub3.verse from outside Sub1, because Sub2 is internal?
As I understand your solution is to declare a Sub2.verse , but then you will not have a Sub2 folder and instead you will have a file for that module

1 Like

I can’t get this to work. When I create a file modeled entirely on your first example, it still throws an error in both VSCode and the UEFN editor. I want to define a device then use it as an editable, but apparently this is illegal. I understand the desire to clean up code by binding submodules to the filesystem locations, but not having clean class definitions to work with is - in my humble but currently furstrated opinion - not ideal.

Edit: Figured this out. Made my device definition public. My irritability about module access structure being invisibly bound to directory structure stands.

This seems very inconvenient. If I copy a nested folder to another project I have to create another file (or copy) that exposes the module.

This brings the question why modules aren’t public by default? In other languages (C#, C++) namespaces are public and don’t have access specifiers at all.

1 Like

For more infomation about a module.

This is really inconvenient for organizing a good file structure within my map, for seemingly no reason… Is there any plans to change this in the future?

2 Likes

this gives an error on the latest release, I see the way modules are written have been changed?

1 Like