Getting the name of the current world in LUA
Getting the name of the current world in LUA
Is it possible to get the name of the currently loaded world in LUA? Thanks in advance!
- 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
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).
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.
Code: Select all
-- Get world path:
local path = minetest.get_worldpath()
-- Get world name:
local name = path:match( "([^/]+)$" )
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.
I'm currently inactive in the Minetest community! So if I don't respond, that's why.
- 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
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
Check out my stuff! | Donations greatly appreciated! PayPal
Re: Getting the name of the current world in LUA
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.
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.
Who is online
Users browsing this forum: No registered users and 8 guests