Uberi / Minetest-WorldEdit

The ultimate in-game world editing tool for Minetest! Tons of functionality to help with building, fixing, and more.
https://forum.minetest.net/viewtopic.php?f=11&t=572
GNU Affero General Public License v3.0
162 stars 81 forks source link

Runtime error when using worldedit.deserialize #84

Closed Ferk closed 9 years ago

Ferk commented 9 years ago

I'm attempting to make a mod (well, subgame) use ".we" files for its world generation. For this I'm using worldedit.deserialize directly from within my mod.

However, when I attempt to do this I obtain the following error:

Lua: Runtime error from mod 'default' in callback ScriptApiServer::on_chat_message(): 
   ...worldedit/serialization.lua:27: attempt to call method 'find' (a nil value)
   stack traceback:
   ...worldedit/serialization.lua:27: In function 'read_header'
   ...worldedit/serialization.lua:115: In function 'load_schematic'
   ...worldedit/serialization.lua:220: In function 'deserialize'

I'm actually not sure if this is really an issue that I should be posting here or is a mistake I made (I'm not very familiar with minetest development).

The schematic loads fine when I use the //load command from the console, and I'm basically using a very similar code to the one implemented in that command. It's just that I call it from a command implemented in my mod (the 'default' mod of my subgame).

What could be causing 'find' to be nil? Do I need to import some library or something?

ShadowNinja commented 9 years ago

If you're doing worldgen you should probably be using the Minetest schematic API (.mts schematics), since it's much faster than WorldEdit's API.

This error should only occur if you're not passing a string as deserialize's second argument (or you're doing something crazy, like deleting the string metatable).

Ferk commented 9 years ago

You were right.. I found out the problem, it's nothing related to worldedit, sorry. But thank you very much.

The reason why I'm not using .mts is that when using it I will lose data like the content of chests. The map I'm loading has chests and even some entities. I'm gonna have to find a different way to load the entities, but at least the chests are covered by worldedit.

Are there any plans for worldedit to support loading/saving entities? (...or maybe better: for minetest to have a way to save chest + entities).

Also, perhaps because the area is too big, I have errors when trying to load .mts schematic files: deSerializeBulkNodes: decompress resulted in invalid size (do you think I should open an issue in minetest for that?), I just wrote very simple save/load commands and consistently the game crashes with that error when performing //msave and then //mload

minetest.register_chatcommand("/msave", {
    params = "",
    description = "Saves the map",
    privs = {worldedit=true},
    func = function(name, param)
        minetest.create_schematic({x=0,y=-30,z=11}, {x=111,y=30,z=155}, nil, minetest.get_modpath("default").."/map.mts");
    end
});

minetest.register_chatcommand("/mload", {
    params = "",
    description = "Load the map",
    privs = {worldedit=true},
    func = function(name, param)
        minetest.place_schematic({x=0, y=-30, z=11}, minetest.get_modpath("default").."/map.mts");
  end
});
ShadowNinja commented 9 years ago

@Ferk: No plans for entity saving, but that could be added as an option. It seems like your schematic is being corrupted somehow, you might want to ask about it in #minetest-dev.