Can you use a module inside another module?

I have a file structure like this

code - Folder
-- GameObjects.jl
-- Characters.jl

I want to use GameObjects inside Characters.jl but I get GameObjects not defined when I do:

# Characters.jl
module Characters
using .GameObjects
# Export statments
# structs and functions
end

I’m assuming that .GameObjects would behave like a sub module as specified in the documentation?

You are just missing an include:

# Characters.jl
module Characters
include("GameObjects.jl") # <-- !!
using .GameObjects
# Export statments
# structs and functions
end
3 Likes

To expand on this, unlike in Python, file/directory names/structure does not create modules/namespaces implicitly. You have to explicitly link them with include and using.

1 Like