Page 1 of 1

Getting the name of the current world in LUA

PostPosted: Thu Apr 20, 2017 04:29
by celinnia
Is it possible to get the name of the currently loaded world in LUA? Thanks in advance!

Re: Getting the name of the current world in LUA

PostPosted: Thu Apr 20, 2017 15:18
by octacian
No, you can't directly get the name if the world, but you can get the path of the world. However, from the path of the world you can separate the name (see below).

Code: Select all
-- Get world path:
local path = minetest.get_worldpath()
-- Get world name:
local name = path:match( "([^/]+)$" )


I didn't have time to test the part where match is used to get the world name, but I assume it works as it was taken from this StackOverflow answer.

Note: I assume you are aware, but lines beginning with "--" are comments, lines that are not actually read by the Lua parser but are simply there for us humans to read.

Re: Getting the name of the current world in LUA

PostPosted: Thu Apr 20, 2017 16:08
by kaeza
I'm really interested to know why you need the name of the world in the first place.

Re: Getting the name of the current world in LUA

PostPosted: Thu Apr 20, 2017 16:28
by celinnia
Thanks for your help! The path actually is probably better for my needs anyway.

I'm using raspberryjammod to have Python as an additional scripting layer. I created my own mod, so I'm hoping to set it up so that my init.lua int the Mod directory will automatically load a Python script associated with each world.