Page 1 of 1

Can someone tell me how to make my mod work?

PostPosted: Thu Oct 11, 2012 19:14
by Chinchow
Ok so some of you may have noticed I got some code from Pilzadams farming mod so how do I get this to work? here is the code


Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_tool("hatchet:hatchet_wood", {
    description = "Wood Hatchet",
    inventory_image = "hatchet_hatchet_wood.png",
    on_use = function(itemstack, user, pointed_thing)
        if create_tree(pointed_thing.under,  user:get:inventory
(tree), 1) then
            itemstack:add_wear(35535/50)
            return itemstack
        end
    end
})
minetest.register_craft({
    output = "hatchet:hatchet_wood",
    recipe = {
        {"default:wood", "default:wood"},
        {"", "default:stick", "default:wood"}
    }
})

PostPosted: Thu Oct 11, 2012 19:33
by Menche
You mean how to make and install the mod? Create a folder called "hatchet" in mods/minetest and paste the code into a file named "init.lua" in that folder.

PostPosted: Thu Oct 11, 2012 19:46
by Chinchow
No what I mean is i made it but when I try and use it and start the game it says there is an error did i write my parts wrong?

PostPosted: Thu Oct 11, 2012 19:58
by Menche
Could you post the last dozen lines from your debug.txt? The debug.txt usually tells what line of what file the error was on.

PostPosted: Thu Oct 11, 2012 20:09
by jordan4ibanez
of course i have no idea what the actual meaning of this post is, here, this will add damage to your hatchet and remove the node and add an item where the tree block used to be
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_tool("hatchet:hatchet_wood", {
    description = "Wood Hatchet",
    inventory_image = "hatchet_hatchet_wood.png",
    on_use = function(itemstack, user, pointed_thing)
        local below = minetest.env:get_node(pointed_thing.under).name
        --THIS WILL ADD DAMAGE TO YOUR HATCHET WHEN YOU USE IT WHILE POINTING TO DIRT
        if below == "default:tree" then
            minetest.env:remove_node(pointed_thing.under, {name="default:air"})
            itemstack:add_wear(50)
            minetest.env:add_item(pointed_thing.under, "default:wood")
            return itemstack
        end
    end
})

minetest.register_craft({
    output = "hatchet:hatchet_wood",
    recipe = {
        {"default:wood", "default:wood"},
        {"", "default:stick", "default:wood"}
    }
})

PostPosted: Thu Oct 11, 2012 20:18
by Chinchow
16:18:20: INFO[main]: Waiting for other menus
16:18:20: INFO[main]: Waited for other menus
16:18:20: VERBOSE[main]: error_message = ModError: Failed to load and run C:\Users\Cameron\Downloads\minetest-0.4.3-4a11323-meta_set_nodedef-win32\minetest-0.4.3-4a11323-meta_set_nodedef-win32\bin\..\mods\minetest\hatchet\init.lua
16:18:20: VERBOSE[main]: Check debug.txt for details.
16:18:20: INFO[main]: Created main menu
16:18:20: INFO[main]: locale has been set to:English_United States.1252
16:18:20: INFO[main]: locale has been set to:C
16:18:22: INFO[main]: locale has been set to:English_United States.1252
16:18:22: INFO[main]: locale has been set to:C
16:18:23: INFO[main]: Dropping main menu
16:18:23: INFO[main]: Updating configuration file: "C:\Users\Cameron\Downloads\minetest-0.4.3-4a11323-meta_set_nodedef-win32\minetest-0.4.3-4a11323-meta_set_nodedef-win32\bin\..\minetest.conf"
16:18:23: INFO[main]: Skipping writing of C:\Users\Cameron\Downloads\minetest-0.4.3-4a11323-meta_set_nodedef-win32\minetest-0.4.3-4a11323-meta_set_nodedef-win32\bin\..\minetest.conf because content wouldn't be modified

PostPosted: Thu Oct 11, 2012 20:36
by Menche
Replace "user:get:inventory(tree)" on line 5 with "user:get_inventory(tree)", and double check the crafting recipe. I think each line in the recipe definition has to have the same number of items; you have 2 on the first line and 3 on the second.

PostPosted: Thu Oct 11, 2012 20:39
by Topywo
To get the right print of the debug.txt you must do the following:

Exit minetest completely, go to your home folder/directory, delete the debug.txt file, start minetest up again. Try to create/start a game, leave minetest again, go to your home folder, doubleclick on debug.txt to open it with your default text editor, search for ERROR (most of the time the bottom part), copy all those error lines and paste them here.

The text you posted doestn't look like the needed debug.txt

If you would like to stick to the code you made you must make 3 changes:

Chinchow wrote:Ok so some of you may have noticed I got some code from Pilzadams farming mod so how do I get this to work? here is the code


minetest.register_tool("hatchet:hatchet_wood", {
description = "Wood Hatchet",
inventory_image = "hatchet_hatchet_wood.png",
on_use = function(itemstack, user, pointed_thing)

2 errors in here:
if create_tree(pointed_thing.under, user:get: --> must be _ inventory You need to attach (tree) after inventory (enter is too much)
(tree), 1) then

So it becomes like this --> if create_tree(pointed_thing.under, user:get_inventory(tree), 1) then
itemstack:add_wear(35535/50)
return itemstack
end
end
})
minetest.register_craft({
output = "hatchet:hatchet_wood",
recipe = {
{"default:wood", "default:wood"}, --> the rows must have the same amount of items, so change this in: {"", "default:wood", "default:wood"},
{"", "default:stick", "default:wood"}
}
})


Edit: Deleted the -code- to try to get colors

PostPosted: Thu Oct 11, 2012 21:21
by Chinchow
Okay so I get a dummy version in the game but now I get a new error when I try to hit something



"17:20:38: VERBOSE[main]: error_message = ServerError: LuaError: error: ..._nodedef-win32\bin\..\mods\minetest\hatchet\init.lua:1: attempt to call global 'create_tree' (a nil value)"

can anyone fix this?

PostPosted: Thu Oct 11, 2012 21:49
by Topywo
My LUA isn't that sophisticated, so sorry, but I really would like to know the answer too, so thanks for asking.

PostPosted: Fri Oct 12, 2012 13:49
by PilzAdam
Chinchow wrote:Okay so I get a dummy version in the game but now I get a new error when I try to hit something



"17:20:38: VERBOSE[main]: error_message = ServerError: LuaError: error: ..._nodedef-win32\bin\..\mods\minetest\hatchet\init.lua:1: attempt to call global 'create_tree' (a nil value)"

can anyone fix this?

There is no function create_tree() in the minetest API.

PostPosted: Fri Oct 12, 2012 15:15
by Topywo
Thanks for the answer PilzAdam!

PostPosted: Fri Oct 12, 2012 20:32
by Chinchow
Oh well woops