Getting the name of the current world in LUA

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

Getting the name of the current world in LUA

by celinnia » Thu Apr 20, 2017 04:29

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

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

Re: Getting the name of the current world in LUA

by octacian » Thu Apr 20, 2017 15:18

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
Location: Montevideo, Uruguay
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Getting the name of the current world in LUA

by kaeza » Thu Apr 20, 2017 16:08

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 » Thu Apr 20, 2017 16:28

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.
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 1 guest