Getting the name of the current world in LUA

Post Reply
celinnia
Member
Posts: 13
Joined: Fri Apr 07, 2017 21:21

Getting the name of the current world in LUA

by celinnia » Post

Is it possible to get the name of the currently loaded world in LUA? Thanks in advance!

User avatar
octacian
Member
Posts: 597
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian
Location: Canada

Re: Getting the name of the current world in LUA

by octacian » Post

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.
MicroExpansion, Working Computers, All Projects - Check out my YouTube channel! (octacian)
I'm currently inactive in the Minetest community! So if I don't respond, that's why.

User avatar
kaeza
Moderator
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza
Location: Montevideo, Uruguay
Contact:

Re: Getting the name of the current world in LUA

by kaeza » Post

I'm really interested to know why you need the name of the world in the first place.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal

celinnia
Member
Posts: 13
Joined: Fri Apr 07, 2017 21:21

Re: Getting the name of the current world in LUA

by celinnia » Post

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests