[SOLVED] How to dynamically "require" a file?

Hi!

I’d like to have several scenes, each of them having its own tilemap.

To do so, I need to “dynamically” require my lua files, with a variable inserted into the path.

Ex (test):


:arrow_down: :arrow_down: :arrow_down:
image

The entire path seems to be broken by the inserted variable, so… I assume the “require” path is not a simple string that I can edit at will (would have been too easy :grin:)

Is there a method to dynamically require a file?

Looks like I can store my required data in tables

image
and the pprint function doesn’t create an error, so I suppose it would work
image
image
etc.

Not as elegant as a dynamic “require” (and probably not as easy to maintain), but if there is no method/workaround at all, at least I know I can go for that :thinking:

Maybe you can try solution described here Dynamically load/require lua-files/tables runtime - #9 by sicher

2 Likes

Actually I tried it before posting, but didn’t manage to make it work… and gave up super early :see_no_evil:

But I just gave it a second try and it seems to work as intended, so… just need to ask a few questions on the other topic.

Thank you :slight_smile:

2 Likes