[SOLVED?] Indexing nil value but not sure why

Post Reply
Icalasari
Member
Posts: 166
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

[SOLVED?] Indexing nil value but not sure why

by Icalasari » Post

I may just be blind or messed up something. Some trees have special blocks, notably branches and twigs, alternate leaf blocks, and alternate log blocks (although this one is so far just two that are so vastly different that it's better just to make them their own special nodes)

So tried making another section for them. Trouble is, I'm getting a nil value. Advice on this? It looks fine when I look at it, so I'm hoping it isn't some simple typo I keep missing

Any horizontal scrolling should just be for descriptions or groups for the code, and the path name for the error. Code definition table is messy as it's in progress, but it's also all commented out and just for remembering what does what

Code:

Code: Select all

mindeca.trees = {
	{"cherry",	"Cherry Tree"},
	{"oak",		"Oak Tree"},
}

--Terms

--trunk = log
--leaves = leaves
--saplingf

mindeca.treepart = {
	--Spring
	cherry = {
		trunk = "Cherry Tree Log\n\nMindeca",
		wood = "Cherry Tree Wood\n\nSoft pink wood for building.\n\nMindeca",
		leaves = "Cherry Tree Leaves\n\nMindeca"
	},
	--Summer
	--Autumn
	oak = {
		trunk = "Oak Tree Log\n\nMindeca",
		wood = "Oak Tree Wood\n\nWood for building that smells of autumn.\n\nMindeca",
		leaves = "Oak Tree Leaves\n\nMindeca"
	},
	--Winter
}

mindeca.treeparta = {
	--Spring
	--Summer
	--Autumn
	oak = {
		leavesa = "Oak Tree Leaves (Autumn)\n\nMindeca"
	},
	--Winter
}

for i in ipairs(mindeca.trees) do
	local minetree = mindeca.trees[i][1]
	minetest.register_node("mindeca:tree_"..minetree.."_log", {
		description = mindeca.treepart[minetree].trunk,
		tiles = {
			"mindeca_tree_"..minetree.."_trunk_top.png",
			"mindeca_tree_"..minetree.."_trunk_top.png",
			"mindeca_tree_"..minetree.."_trunk.png",
			},
		paramtype2 = "facedir",
		is_ground_content = false,
		groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2},
		sounds = default.node_sound_wood_defaults(),
		on_place = minetest.rotate_node
	})
	minetest.register_node("mindeca:wood_tree_"..minetree, {
		description = mindeca.treepart[minetree].wood,
		tiles = {"mindeca_wood_tree_"..minetree..".png"},
		is_ground_content = false,
		groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 3, wood = 1},
		flags = "force_placement",
		sounds = default.node_sound_wood_defaults(),
	})

	minetest.register_node("mindeca:tree_"..minetree.."_leaves", {
		description = mindeca.treepart[minetree].leaves,
		drawtype = "allfaces_optional",
		waving = 1,
		tiles = {"mindeca_tree_"..minetree.."_leaves.png"},
		special_tiles = {"mindeca_tree_"..minetree.."_leaves_s.png"},
		paramtype = "light",
		is_ground_content = false,
		groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1},
		drop = {
			max_items = 1,
			items = {
				{
					-- player will get sapling with 1/20 chance
					items = {"mindeca:tree_"..minetree.."_sapling"},
					rarity = 20,
				},
				{
					-- player will get leaves only if they get no saplings,
					-- this is because max_items is 1
					items = {"mindeca:tree_"..minetree.."_leaves"},
				}
			}
		},
		sounds = default.node_sound_leaves_defaults(),
		after_place_node = after_place_leaves,
	})



	minetest.register_node("mindeca:tree_"..minetree.."_leavesa", {
		description = mindeca.treeparta[minetree].leavesa,
		drawtype = "allfaces_optional",
		waving = 1,
		tiles = {"mindeca_tree_"..minetree.."_a_leaves.png"},
		special_tiles = {"mindeca_tree_"..minetree.."_a_leaves_s.png"},
		paramtype = "light",
		is_ground_content = false,
		groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1},
		drop = {
			max_items = 1,
			items = {
				{
					-- player will get sapling with 1/20 chance
					items = {"mindeca:tree_"..minetree.."_sapling"},
					rarity = 20,
				},
				{
					-- player will get drop with 1/10 chance
					items = {"mindeca:item_fruit_"..minetree},
					rarity = 10,
				},
				{
					-- player will get leaves only if they get no saplings,
					-- this is because max_items is 1
					items = {"mindeca:tree_"..minetree.."_leavesa"},
				}
			}
		},
		sounds = default.node_sound_leaves_defaults(),
		after_place_node = after_place_leaves,
	})
end
Error:

Code: Select all

ModError: Failed to load and run script from D:\Users\Vee\Documents\!!!Games\Open World\minetest-5.5.1-win64\bin\..\mods\mindeca\Mindeca Main\init.lua:
....5.1-win64\bin\..\mods\mindeca\Mindeca Main/treepart.lua:94: attempt to index a nil value
stack traceback:
	....5.1-win64\bin\..\mods\mindeca\Mindeca Main/treepart.lua:94: in main chunk
	[C]: in function 'dofile'
	...st-5.5.1-win64\bin\..\mods\mindeca\Mindeca Main\init.lua:20: in main chunk
Check debug.txt for details.
EDIT: ...May have an idea of what's going wrong, but would need to wait until tomorrow to test
Last edited by Icalasari on Mon Aug 08, 2022 02:38, edited 3 times in total.

User avatar
Blockhead
Member
Posts: 1622
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: Indexing nil value but not sure why

by Blockhead » Post

It looks like minedeca.treeparta["oak"] works fine but you have no table entry for mindeca.treeparta["cherry"], hence it's nil and indexing nil leads to a crash. Either add leavesa entries for all your trees or check for nil and skip that registration.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

Icalasari
Member
Posts: 166
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

Re: Indexing nil value but not sure why

by Icalasari » Post

Did a little reorganize and it's working, but keeps throwing up an error on load saying that it can't load certain textures when it shouldn't even be trying

Code: Select all

mindeca.trees = {
	{"cherry",	"Cherry Tree"},
	{"oak",		"Oak Tree"},
}

--Terms

--trunk = log
--wood = planks, wood
--leaves = leaves
--leavesa = alternate leaves (if any)

mindeca.treepart = {
	--Spring
	cherry = {
		trunk = "Cherry Tree Log\n\nMindeca",
		wood = "Cherry Tree Wood\n\nSoft pink wood for building.\n\nMindeca",
		leaves = "Cherry Tree Leaves\n\nMindeca",
		leavesa = nil,
	},
	--Summer
	--Autumn
	oak = {
		trunk = "Oak Tree Log\n\nMindeca",
		wood = "Oak Tree Wood\n\nWood for building that smells of autumn.\n\nMindeca",
		leaves = "Oak Tree Leaves\n\nMindeca",
		leavesa = "Oak Tree Leaves (Autumn)\n\nMindeca",
	},
	--Winter
}

for i in ipairs(mindeca.trees) do
	local minetree = mindeca.trees[i][1]
	minetest.register_node("mindeca:tree_"..minetree.."_log", {
		description = mindeca.treepart[minetree].trunk,
		tiles = {
			"mindeca_tree_"..minetree.."_trunk_top.png",
			"mindeca_tree_"..minetree.."_trunk_top.png",
			"mindeca_tree_"..minetree.."_trunk.png",
			},
		paramtype2 = "facedir",
		is_ground_content = false,
		groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2},
		sounds = default.node_sound_wood_defaults(),
		on_place = minetest.rotate_node
	})
	minetest.register_node("mindeca:wood_tree_"..minetree, {
		description = mindeca.treepart[minetree].wood,
		tiles = {"mindeca_wood_tree_"..minetree..".png"},
		is_ground_content = false,
		groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 3, wood = 1},
		flags = "force_placement",
		sounds = default.node_sound_wood_defaults(),
	})

	minetest.register_node("mindeca:tree_"..minetree.."_leaves", {
		description = mindeca.treepart[minetree].leaves,
		drawtype = "allfaces_optional",
		waving = 1,
		tiles = {"mindeca_tree_"..minetree.."_leaves.png"},
		special_tiles = {"mindeca_tree_"..minetree.."_leaves_s.png"},
		paramtype = "light",
		is_ground_content = false,
		groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1},
		drop = {
			max_items = 1,
			items = {
				{
					-- player will get sapling with 1/20 chance
					items = {"mindeca:tree_"..minetree.."_sapling"},
					rarity = 20,
				},
				{
					-- player will get leaves only if he get no saplings,
					-- this is because max_items is 1
					items = {"mindeca:tree_"..minetree.."_leaves"},
				}
			}
		},
		sounds = default.node_sound_leaves_defaults(),
		after_place_node = after_place_leaves,
	})

	minetest.register_node("mindeca:tree_"..minetree.."_leavesa", {
		description = mindeca.treepart[minetree].leavesa,
		drawtype = "allfaces_optional",
		waving = 1,
		tiles = {"mindeca_tree_"..minetree.."_a_leaves.png"},
		special_tiles = {"mindeca_tree_"..minetree.."_a_leaves_s.png"},
		paramtype = "light",
		is_ground_content = false,
		groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1},
		drop = {
			max_items = 1,
			items = {
				{
					-- player will get sapling with 1/20 chance
					items = {"mindeca:tree_"..minetree.."_sapling"},
					rarity = 20,
				},
				{
					-- player will get drop with 1/10 chance
					items = {"mindeca:item_fruit_"..minetree},
					rarity = 10,
				},
				{
					-- player will get leaves only if he get no saplings,
					-- this is because max_items is 1
					items = {"mindeca:tree_"..minetree.."_leavesa"},
				}
			}
		},
		sounds = default.node_sound_leaves_defaults(),
		after_place_node = after_place_leaves,
	})
end

Code: Select all

2022-08-07 08:52:26: ERROR[Main]: generateImage(): Could not load image "mindeca_tree_cherry_a_leaves.png" while building texture; Creating a dummy image
2022-08-07 08:52:26: ERROR[Main]: generateImage(): Could not load image "mindeca_tree_cherry_a_leaves_s.png" while building texture; Creating a dummy image

User avatar
Blockhead
Member
Posts: 1622
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: Indexing nil value but not sure why

by Blockhead » Post

Are you using drawers mod by any chance? That's the only place I've seen that error. Otherwise, no idea sorry.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

Icalasari
Member
Posts: 166
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

Re: Indexing nil value but not sure why

by Icalasari » Post

Not using drawers mod, no

Edit: Hmm, wonder if I use the array to store alt leaves and info on which trees use branches and twigs, if that might work...? Will need to check after my shift

Icalasari
Member
Posts: 166
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

Re: Indexing nil value but not sure why

by Icalasari » Post

Finally got it working. Going to share the code but uh... Gonna be a lot

Still, 350-400 lines much better than 1200+ lines

Code: Select all

mindeca.trees = {
	--{"Tree",	"Log/Wood",	"Door",		"Fruit",	"AltLeaves",	"Stairs/Fence",	"Branch/Twig"},
	--Spring
	{"cherry",	"Cherry",	"cherry",	"cherry",	nil,		"Cherry",	nil},
	{"poplar",	nil,		nil,		nil,		nil,		nil,		"Poplar"},
	--Summer
	{"peach",	nil,		nil,		"peach",	nil,		nil,		"Peach"},
	{"plum",	nil,		nil,		"plum",		nil,		nil,		"Plum"},
	{"magnolia",	"Magnolia",	"magnolia",	nil,		nil,		"Magnolia",	nil},
	{"dogwood",	"Dogwood",	"dogwood",	nil,		nil,		"Dogwood",	nil},
	{"ash",		"Ash",		"ash",		nil,		nil,		"Ash",		nil},
	--Autumn
	{"oak",		"Oak",		"oak",		nil,		"oak",		"Oak",		nil},
	--Winter
	{"cedar",	"Cedar",	"cedar",	nil,		nil,		"Cedar",	nil}
}

--Terms

--trunk = log
--wood = planks, wood
--doord = door
--fruit = fruit
--leaf = leaves
--leafa = alternate leaves (if any)
--stair = stairs
--slab = slabs
--branch = branch
--twig = twig
--chartwig = charred twig

mindeca.treepart = {
	--Spring
	cherry = {
		trunk = "Cherry Tree Log\n\nA beautiful Cherry Tree log.\n\nMindeca",
		wood = "Cherry Wood\n\nSoft pink wood for building.\n\nMindeca",
		doord = "Cherry Wood Door\n\nA pink, traditional sliding door.\n\nMindeca",
		fruit = "Cherry\n\nA tasty cherry for a quick snack.\n\nMindeca",
		leaf = "Cherry Tree Leaves\n\nSoft leaves that promise pink blossoms.\n\nMindeca",
		leafa = "Cherry Tree Blossoms\n\nPink blossoms that smell of spring.\n\nMindeca",
		stair = "Cherry Wood Stairs\n\nPink stairs with a faint cherry scent.\n\nMindeca",
		slab = "Cherry Wood Slab\n\nA pink slab with a faint cherry scent.\n\nMindeca"
	},
	poplar = {
		leaf = "Poplar Tree Leaves\n\nLeaves that are quite Pop-u-lar.\n\nMindeca",
		branch = "Poplar Tree Branch\n\nA very Pop-u-lar branch.\n\nMindeca",
		twig = "Poplar Tree Twig\n\nA very Pop-u-lar twig.\n\nMindeca",
		chartwig = "Poplar Tree Twig (Charred)\n\nA charred twig that got too Pop-u-lar.\n\nMindeca"
	},
	--Summer
	peach = {
		fruit = "Peach\n\nA juicy peach for a quick snack.\n\nMindeca",
		leaf = "Peach Tree Leaves\n\nLeaves with a nice, floral scent.\n\nMindeca",
		branch = "Peach Branch\n\nA peachy-keen branch.\n\nMindeca",
		twig = "Peach Twig\n\nA peachy-keen twig.\n\nMindeca",
		chartwig = "Peach Twig (Charred)\n\nA charred twig that things don't look peachy for.\n\nMindeca"
	},
	plum = {
		fruit = "Plum\n\nA juicy plum for a quick snack.\n\nMindeca",
		leaf = "Plum Tree Leaves\n\nLeaves with a sharp, floral scent.\n\nMindeca",
		branch = "Plum Branch\n\nA branch plum full of spirit.\n\nMindeca",
		twig = "Plum Twig\n\nA twig plum full of spirit.\n\nMindeca",
		chartwig = "Plum Twig (Charred)\n\nA charred twig plum full of ash.\n\nMindeca"
	},
	magnolia = {
		trunk = "Magnolia Tree Log\n\nA smooth log with a jungle flora scent.\n\nMindeca",
		wood = "Magnolia Wood\n\nPale wood useful for building.\n\nMindeca",
		doord = "Magnolia Door\n\nAn intricate door with floral designs.\n\nMindeca",
		leaf = "Magnolia Leaves\n\nLeaves with a floral, jungle scent.\n\nMindeca",
		stair = "Magnolia Wood Stairs\n\nPale stairs useful for building.\n\nMindeca",
		slab = "Magnolia Wood Slab\n\nA pale slab useful for building.\n\nMindeca"
	},
	dogwood = {
		trunk = "Dogwood Log\n\nA log of Dogwood. Its bark is worse than its bite.\n\nMindeca",
		wood = "Dogwood Wood\n\nDogwood Wood with which you would build.\n\nMindeca",
		doord = "Dogwood Door\n\nA simple door with a porthole window.\n\nMindeca",
		leaf = "Dogwood Leaves\n\nLeaves of a Dogwood tree.\n\nMindeca",
		stair = "Dogwood Stairs\n\nStairs of Dogwood. No bark, no bite.\n\nMindeca",
		slab = "Dogwood Slab\n\nA slab of Dogwood. No bark, no bite.\n\nMindeca"
	},
	ash = {
		trunk = "Ash Tree Log\n\nA log of Ash. No, not the burnt ash.\n\nMindeca",
		wood = "Ash Wood\n\nAshen wood useful for building.\n\nMindeca",
		doord = "Ash Door\n\nA somewhat rickety looking door.\n\nMindeca",
		leaf = "Ash Leaves\n\nLeaves that ash-k no questions.\n\nMindeca",
		stair = "Ash Wood Stairs\n\nAshen stairs useful for building.\n\nMindeca",
		slab = "Ash Wood Slab\n\nAn ashen slab useful for building.\n\nMindeca"
	},
	--Autumn
	oak = {
		trunk = "Oak Tree Log\n\nA sturdy Oak log.\n\nMindeca",
		wood = "Oak Wood\n\nSturdy Oak wood for building.\n\nMindeca",
		doord = "Oak Door\n\nA solid, sturdy door of Oak.\n\nMindeca",
		leaf = "Oak Tree Leaves\n\nMindeca",
		leafa = "Oak Tree Leaves (Autumn)\n\nMindeca",
		stair = "Oak Wood Stairs\n\nSturdy stairs made of Oak.\n\nMindeca",
		slab = "Oak Wood Slab\n\nA sturdy slab made of Oak.\n\nMindeca"
	},
	--Winter
	cedar = {
		trunk = "White Cedar Log\n\nA log of White Cedar. Very multipurpose.\n\nMindeca",
		wood = "White Cedar Wood\n\nWood of the versatile White Cedar.\n\nMindeca",
		doord = "White Cedar Door\n\nSee? Door!\n\nMindeca",
		leaf = "White Cedar Leaves\n\nLeaves with a dainty scent. Good as tea.\n\nMindeca",
		stair = "White Cedar Stairs\n\nStairs of versatile White Cedar wood.\n\nMindeca",
		slab = "White Cedar Slab\n\nA slab of versatile White Cedar wood.\n\nMindeca"
	}
}

for i in ipairs(mindeca.trees) do
	local minetree = mindeca.trees[i][1]
	local trunk = mindeca.trees[i][2]
	local door = mindeca.trees[i][3]
	local fruit = mindeca.trees[i][4]
	local leafalt = mindeca.trees[i][5]
	local stair = mindeca.trees[i][6]
	local branch = mindeca.trees[i][7]

	minetest.register_node("mindeca:tree_"..minetree.."_leaves", {
		description = mindeca.treepart[minetree].leaf,
		drawtype = "allfaces_optional",
		waving = 1,
		tiles = {"mindeca_tree_"..minetree.."_leaves.png"},
		special_tiles = {"mindeca_tree_"..minetree.."_leaves_s.png"},
		paramtype = "light",
		is_ground_content = false,
		groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1},
		drop = {
			max_items = 1,
			items = {
				{
					-- player will get sapling with 1/20 chance
					items = {"mindeca:tree_"..minetree.."_sapling"},
					rarity = 20,
				},
				{
					-- player will get leaves only if he get no saplings,
					-- this is because max_items is 1
					items = {"mindeca:tree_"..minetree.."_leaves"},
				}
			}
		},
		sounds = default.node_sound_leaves_defaults(),
		after_place_node = after_place_leaves,
	})

	local trunkname = nil
	if trunk then
		minetest.register_node("mindeca:tree_"..minetree.."_log", {
			description = mindeca.treepart[minetree].trunk,
			tiles = {
				"mindeca_tree_"..minetree.."_trunk_top.png",
				"mindeca_tree_"..minetree.."_trunk_top.png",
				"mindeca_tree_"..minetree.."_trunk.png",
				},
			paramtype2 = "facedir",
			is_ground_content = false,
			groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2},
			sounds = default.node_sound_wood_defaults(),
			on_place = minetest.rotate_node
		})
		minetest.register_node("mindeca:wood_tree_"..minetree, {
			description = mindeca.treepart[minetree].wood,
			tiles = {"mindeca_wood_tree_"..minetree..".png"},
			is_ground_content = false,
			groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 3, wood = 1},
			flags = "force_placement",
			sounds = default.node_sound_wood_defaults(),
		})
	end

	local fruitname = nil
	if fruit then
		minetest.register_node("mindeca:item_fruit_"..fruit, {
			description = mindeca.treepart[minetree].fruit,
			drawtype = "plantlike",
			tiles = {"mindeca_item_fruit_"..minetree..".png"},
			inventory_image = "mindeca_item_fruit_"..minetree..".png",
			paramtype = "light",
			sunlight_propagates = true,
			walkable = false,
			is_ground_content = false,
			selection_box = {
				type = "fixed",
				fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
			},
			groups = {fleshy = 3, dig_immediate = 3, flammable = 2, leafdecay = 3, leafdecay_drop = 1, food_apple = 1},
			on_use = minetest.item_eat(2),
			sounds = default.node_sound_leaves_defaults(),
			after_place_node = function(pos, placer, itemstack)
				minetest.set_node(pos, {name = "mindeca:item_fruit_"..minetree, param2 = 1})
			end,
		})
	end

	local branchname = nil
	if branch then
		minetest.register_node("mindeca:tree_"..minetree.."_branch", {
			description = mindeca.treepart[minetree].branch,
			drawtype = "nodebox",
			connects_to = {"group:tree", "group:leaves", "group:wood", "group:soil"},
			node_box = {
				type = "connected",
				fixed = {-4/16, -4/16, -4/16, 4/16, 4/16, 4/16},
				connect_top = {-4/16, -4/16, -4/16, 4/16, 8/16, 4/16},
				connect_bottom = {-4/16, -8/16, -4/16, 4/16, 4/16, 4/16},
				connect_front = {-4/16, -4/16, -8/16, 4/16, 4/16, 4/16},
				connect_left = {-8/16, -4/16, -4/16, 4/16, 4/16, 4/16},
				connect_back = {-4/16, -4/16, -4/16, 4/16, 4/16, 8/16},
				connect_right = {-4/16, -4/16, -4/16, 8/16, 4/16, 4/16},
				disconnected = {-4/16, -8/16, -4/16, 4/16, 8/16, 4/16},
				},
			tiles = {"mindeca_tree_"..minetree.."_trunk.png"},
			paramtype = "light",
			paramtype2 = "facedir",
			is_ground_content = false,
			sunlight_propagates = true,
			groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
			flags = "force_placement",
			sounds = default.node_sound_wood_defaults(),
			on_place = minetest.rotate_node
		})

		minetest.register_node("mindeca:tree_"..minetree.."_twig", {
			description = mindeca.treepart[minetree].twig,
			drawtype = "nodebox",
			connects_to = {"group:tree", "group:leaves", "group:wood", "group:twig"},
			node_box = {
				type = "connected",
				fixed = {-2/16, -2/16, -2/16, 2/16, 2/16, 2/16},
				connect_top = {-2/16, -2/16, -2/16, 2/16, 8/16, 2/16},
				connect_bottom = {-2/16, -8/16, -2/16, 2/16, 2/16, 2/16},
				connect_front = {-2/16, -2/16, -8/16, 2/16, 2/16, 2/16},
				connect_left = {-8/16, -2/16, -2/16, 2/16, 2/16, 2/16},
				connect_back = {-2/16, -2/16, -2/16, 2/16, 2/16, 8/16},
				connect_right = {-2/16, -2/16, -2/16, 8/16, 2/16, 2/16},
				disconnected = {-2/16, -8/16, -2/16, 2/16, 8/16, 2/16},
			},
			tiles = {"mindeca_tree_"..minetree.."_trunk.png"},
			paramtype = "light",
			paramtype2 = "facedir",
			is_ground_content = false,
			groups = {tree = 1, choppy = 3, oddly_breakable_by_hand = 3, flammable = 3},
			flags = "force_placement",
			sounds = default.node_sound_wood_defaults(),
			on_place = minetest.rotate_node
		})

		minetest.register_node("mindeca:tree_"..minetree.."_twig_charred", {
			description = mindeca.treepart[minetree].chartwig,
			drawtype = "nodebox",
			connects_to = {"group:tree", "group:leaves"},
			node_box = {
				type = "fixed",
				fixed = {-2/16, -8/16, -2/16, 2/16, 8/16, 2/16},
				},
			tiles = {
				"mindeca_s_char_tip.png",
				"mindeca_tree_"..minetree.."_trunk.png",
				{name = "mindeca_tree_"..minetree.."_trunk.png^mindeca_overlay_charred.png",}
				},
			paramtype = "light",
			paramtype2 = "facedir",
			is_ground_content = false,
			groups = {tree = 1, choppy = 3, oddly_breakable_by_hand = 3, flammable = 3},
			flags = "force_placement",
			sounds = default.node_sound_wood_defaults(),
			on_place = minetest.rotate_node
		})
		end
	end

	local branchname = nil
	local trunkname = nil
	local branchname = nil
	if branch then
		default.register_leafdecay({
			trunks = {"mindeca:tree_"..minetree.."_branch", "mindeca:tree_"..minetree.."_twig"},
			leaves = {"mindeca:tree_"..minetree.."_leaves"},
			radius = 4,
		})
	elseif trunk then
		default.register_leafdecay({
			trunks = {"mindeca:tree_"..minetree.."_log"},
			leaves = {"mindeca:tree_"..minetree.."_leaves"},
			radius = 4,
		})
	end

	local leafaltname = nil
	if leafalt then
		minetest.register_node("mindeca:tree_"..leafalt.."a_leaves", {
			description = leafdesc,
			drawtype = "allfaces_optional",
			waving = 1,
			tiles = {"mindeca_tree_"..leafalt.."_a_leaves.png"},
			special_tiles = {"mindeca_tree_"..leafalt.."_a_leaves_s.png"},
			paramtype = "light",
			is_ground_content = false,
			groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1},
			drop = {
				max_items = 1,
				items = {
					{
						-- player will get sapling with 1/20 chance
						items = {"mindeca:tree_"..minetree.."_sapling"},
						rarity = 20,
					},
					{
						-- player will get drop with 1/10 chance
						items = {"mindeca:item_fruit_"..minetree},
						rarity = 10,
					},
					{
						-- player will get leaves only if he get no saplings,
						-- this is because max_items is 1
						items = {"mindeca:tree_"..minetree.."_leavesa"},
					}
				}
			},
			sounds = default.node_sound_leaves_defaults(),
			after_place_node = after_place_leaves,
		})
	if branch then
		default.register_leafdecay({
			trunks = {"mindeca:tree_"..minetree.."_branch", "mindeca:tree_"..minetree.."_twig"},
			leaves = {"mindeca:tree_"..minetree.."_leaves", "mindeca:tree_"..leafalt.."a_leaves"},
			radius = 4,
		})
	elseif log then
		default.register_leafdecay({
			trunks = {"mindeca:tree_"..minetree.."_log"},
			leaves = {"mindeca:tree_"..minetree.."_leaves", "mindeca:tree_"..leafalt.."a_leaves"},
			radius = 4,
		})
	end


	local doorname = nil
	if door then
		doors.register("mindeca:door_"..minetree, {
			tiles = {{ name = "mindeca_door_"..minetree..".png", backface_culling = true }},
			description = mindeca.treepart[minetree].doord,
			inventory_image = "mindeca_item_door_"..minetree..".png",
			groups = {node = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
			gain_open = 0.06,
			gain_close = 0.13,
			recipe = {
				{"mindeca:wood_tree_"..minetree, "mindeca:wood_tree_"..minetree},
				{"mindeca:wood_tree_"..minetree, "mindeca:wood_tree_"..minetree},
				{"mindeca:wood_tree_"..minetree, "mindeca:wood_tree_"..minetree},
			}
		})
	end
	local stairname = nil
	if stair then
		if minetest.get_modpath("stairs") then
			stairs.register_stair_and_slab(
				"mindeca_wood_tree_"..minetree,
				"mindeca:wood_tree_"..minetree,
				{ snappy=1, choppy=2, oddly_breakable_by_hand=2, flammable=3 },
				{ "mindeca_wood_tree_"..minetree..".png" },
				mindeca.treepart[minetree].stair,
				mindeca.treepart[minetree].slab,
				default.node_sound_wood_defaults()
			)
		end
	end
end

Icalasari
Member
Posts: 166
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

Re: Indexing nil value but not sure why

by Icalasari » Post

I give up, it either breaks the whole mod or I start missing either the alt leaves or the stairs, slabs, and doors. It does not want to work with me and I am getting VERY frustrated with this

Code: Select all

mindeca.trees = {
	--{"Tree",	"Log/Wood",	"Door",		"Fruit",	"Stairs/Fence",	"Branch/Twig"},
	--Spring
	{"cherry",	"Cherry",	"cherry",	"cherry",	"Cherry",	nil},
	{"poplar",	nil,		nil,		nil,		nil,		"Poplar"},
	--Summer
	{"peach",	nil,		nil,		"peach",	nil,		"Peach"},
	{"plum",	nil,		nil,		"plum",		nil,		"Plum"},
	{"magnolia",	"Magnolia",	"magnolia",	nil,		"Magnolia",	nil},
	{"dogwood",	"Dogwood",	"dogwood",	nil,		"Dogwood",	nil},
	{"ash",		"Ash",		"ash",		nil,		"Ash",		nil},
	--Autumn
	{"oak",		"Oak",		"oak",		nil,		"Oak",		nil},
	--Winter
	{"cedar",	"Cedar",	"cedar",	nil,		"Cedar",	nil}
}

--Terms

--trunk = log
--wood = planks, wood
--doord = door
--fruit = fruit
--leaf = leaves
--stair = stairs
--slab = slabs
--branch = branch
--twig = twig
--chartwig = charred twig

mindeca.treepart = {
	--Spring
	cherry = {
		trunk = "Cherry Tree Log\n\nA beautiful Cherry Tree log.\n\nMindeca",
		wood = "Cherry Wood\n\nSoft pink wood for building.\n\nMindeca",
		doord = "Cherry Wood Door\n\nA pink, traditional sliding door.\n\nMindeca",
		fruit = "Cherry\n\nA tasty cherry for a quick snack.\n\nMindeca",
		leaf = "Cherry Tree Leaves\n\nSoft leaves that promise pink blossoms.\n\nMindeca",
		stair = "Cherry Wood Stairs\n\nPink stairs with a faint cherry scent.\n\nMindeca",
		slab = "Cherry Wood Slab\n\nA pink slab with a faint cherry scent.\n\nMindeca"
	},
	poplar = {
		leaf = "Poplar Tree Leaves\n\nLeaves that are quite Pop-u-lar.\n\nMindeca",
		branch = "Poplar Tree Branch\n\nA very Pop-u-lar branch.\n\nMindeca",
		twig = "Poplar Tree Twig\n\nA very Pop-u-lar twig.\n\nMindeca",
		chartwig = "Poplar Tree Twig (Charred)\n\nA charred twig that got too Pop-u-lar.\n\nMindeca"
	},
	--Summer
	peach = {
		fruit = "Peach\n\nA juicy peach for a quick snack.\n\nMindeca",
		leaf = "Peach Tree Leaves\n\nLeaves with a nice, floral scent.\n\nMindeca",
		branch = "Peach Branch\n\nA peachy-keen branch.\n\nMindeca",
		twig = "Peach Twig\n\nA peachy-keen twig.\n\nMindeca",
		chartwig = "Peach Twig (Charred)\n\nA charred twig that things don't look peachy for.\n\nMindeca"
	},
	plum = {
		fruit = "Plum\n\nA juicy plum for a quick snack.\n\nMindeca",
		leaf = "Plum Tree Leaves\n\nLeaves with a sharp, floral scent.\n\nMindeca",
		branch = "Plum Branch\n\nA branch plum full of spirit.\n\nMindeca",
		twig = "Plum Twig\n\nA twig plum full of spirit.\n\nMindeca",
		chartwig = "Plum Twig (Charred)\n\nA charred twig plum full of ash.\n\nMindeca"
	},
	magnolia = {
		trunk = "Magnolia Tree Log\n\nA smooth log with a jungle flora scent.\n\nMindeca",
		wood = "Magnolia Wood\n\nPale wood useful for building.\n\nMindeca",
		doord = "Magnolia Door\n\nAn intricate door with floral designs.\n\nMindeca",
		leaf = "Magnolia Leaves\n\nLeaves with a floral, jungle scent.\n\nMindeca",
		stair = "Magnolia Wood Stairs\n\nPale stairs useful for building.\n\nMindeca",
		slab = "Magnolia Wood Slab\n\nA pale slab useful for building.\n\nMindeca"
	},
	dogwood = {
		trunk = "Dogwood Log\n\nA log of Dogwood. Its bark is worse than its bite.\n\nMindeca",
		wood = "Dogwood Wood\n\nDogwood Wood with which you would build.\n\nMindeca",
		doord = "Dogwood Door\n\nA simple door with a porthole window.\n\nMindeca",
		leaf = "Dogwood Leaves\n\nLeaves of a Dogwood tree.\n\nMindeca",
		stair = "Dogwood Stairs\n\nStairs of Dogwood. No bark, no bite.\n\nMindeca",
		slab = "Dogwood Slab\n\nA slab of Dogwood. No bark, no bite.\n\nMindeca"
	},
	ash = {
		trunk = "Ash Tree Log\n\nA log of Ash. No, not the burnt ash.\n\nMindeca",
		wood = "Ash Wood\n\nAshen wood useful for building.\n\nMindeca",
		doord = "Ash Door\n\nA somewhat rickety looking door.\n\nMindeca",
		leaf = "Ash Leaves\n\nLeaves that ash-k no questions.\n\nMindeca",
		stair = "Ash Wood Stairs\n\nAshen stairs useful for building.\n\nMindeca",
		slab = "Ash Wood Slab\n\nAn ashen slab useful for building.\n\nMindeca"
	},
	--Autumn
	oak = {
		trunk = "Oak Tree Log\n\nA sturdy Oak log.\n\nMindeca",
		wood = "Oak Wood\n\nSturdy Oak wood for building.\n\nMindeca",
		doord = "Oak Door\n\nA solid, sturdy door of Oak.\n\nMindeca",
		leaf = "Oak Tree Leaves\n\nOak leaves that signal the coming of fall.\n\nMindeca",
		stair = "Oak Wood Stairs\n\nSturdy stairs made of Oak.\n\nMindeca",
		slab = "Oak Wood Slab\n\nA sturdy slab made of Oak.\n\nMindeca"
	},
	--Winter
	cedar = {
		trunk = "White Cedar Log\n\nA log of White Cedar. Very multipurpose.\n\nMindeca",
		wood = "White Cedar Wood\n\nWood of the versatile White Cedar.\n\nMindeca",
		doord = "White Cedar Door\n\nSee? Door!\n\nMindeca",
		leaf = "White Cedar Leaves\n\nLeaves with a dainty scent. Good as tea.\n\nMindeca",
		stair = "White Cedar Stairs\n\nStairs of versatile White Cedar wood.\n\nMindeca",
		slab = "White Cedar Slab\n\nA slab of versatile White Cedar wood.\n\nMindeca"
	}
}

for i in ipairs(mindeca.trees) do
	local minetree = mindeca.trees[i][1]
	local trunk = mindeca.trees[i][2]
	local door = mindeca.trees[i][3]
	local fruit = mindeca.trees[i][4]
	local leafalt = mindeca.trees[i][5]
	local stair = mindeca.trees[i][6]
	local branch = mindeca.trees[i][7]

	minetest.register_node("mindeca:tree_"..minetree.."_leaves", {
		description = mindeca.treepart[minetree].leaf,
		drawtype = "allfaces_optional",
		waving = 1,
		tiles = {"mindeca_tree_"..minetree.."_leaves.png"},
		special_tiles = {"mindeca_tree_"..minetree.."_leaves_s.png"},
		paramtype = "light",
		is_ground_content = false,
		groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1},
		drop = {
			max_items = 1,
			items = {
				{
					-- player will get sapling with 1/20 chance
					items = {"mindeca:tree_"..minetree.."_sapling"},
					rarity = 20,
				},
				{
					-- player will get leaves only if he get no saplings,
					-- this is because max_items is 1
					items = {"mindeca:tree_"..minetree.."_leaves"},
				}
			}
		},
		sounds = default.node_sound_leaves_defaults(),
		after_place_node = after_place_leaves,
	})

	local trunkname = nil
	if trunk then
		minetest.register_node("mindeca:tree_"..minetree.."_log", {
			description = mindeca.treepart[minetree].trunk,
			tiles = {
				"mindeca_tree_"..minetree.."_trunk_top.png",
				"mindeca_tree_"..minetree.."_trunk_top.png",
				"mindeca_tree_"..minetree.."_trunk.png",
				},
			paramtype2 = "facedir",
			is_ground_content = false,
			groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2},
			sounds = default.node_sound_wood_defaults(),
			on_place = minetest.rotate_node
		})
		minetest.register_node("mindeca:wood_tree_"..minetree, {
			description = mindeca.treepart[minetree].wood,
			tiles = {"mindeca_wood_tree_"..minetree..".png"},
			is_ground_content = false,
			groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 3, wood = 1},
			flags = "force_placement",
			sounds = default.node_sound_wood_defaults(),
		})
	end

	local fruitname = nil
	if fruit then
		minetest.register_node("mindeca:item_fruit_"..fruit, {
			description = mindeca.treepart[minetree].fruit,
			drawtype = "plantlike",
			tiles = {"mindeca_item_fruit_"..minetree..".png"},
			inventory_image = "mindeca_item_fruit_"..minetree..".png",
			paramtype = "light",
			sunlight_propagates = true,
			walkable = false,
			is_ground_content = false,
			selection_box = {
				type = "fixed",
				fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
			},
			groups = {fleshy = 3, dig_immediate = 3, flammable = 2, leafdecay = 3, leafdecay_drop = 1, food_apple = 1},
			on_use = minetest.item_eat(2),
			sounds = default.node_sound_leaves_defaults(),
			after_place_node = function(pos, placer, itemstack)
				minetest.set_node(pos, {name = "mindeca:item_fruit_"..minetree, param2 = 1})
			end,
		})
	end

	local branchname = nil
	if branch then
		minetest.register_node("mindeca:tree_"..minetree.."_branch", {
			description = mindeca.treepart[minetree].branch,
			drawtype = "nodebox",
			connects_to = {"group:tree", "group:leaves", "group:wood", "group:soil"},
			node_box = {
				type = "connected",
				fixed = {-4/16, -4/16, -4/16, 4/16, 4/16, 4/16},
				connect_top = {-4/16, -4/16, -4/16, 4/16, 8/16, 4/16},
				connect_bottom = {-4/16, -8/16, -4/16, 4/16, 4/16, 4/16},
				connect_front = {-4/16, -4/16, -8/16, 4/16, 4/16, 4/16},
				connect_left = {-8/16, -4/16, -4/16, 4/16, 4/16, 4/16},
				connect_back = {-4/16, -4/16, -4/16, 4/16, 4/16, 8/16},
				connect_right = {-4/16, -4/16, -4/16, 8/16, 4/16, 4/16},
				disconnected = {-4/16, -8/16, -4/16, 4/16, 8/16, 4/16},
				},
			tiles = {"mindeca_tree_"..minetree.."_trunk.png"},
			paramtype = "light",
			paramtype2 = "facedir",
			is_ground_content = false,
			sunlight_propagates = true,
			groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
			flags = "force_placement",
			sounds = default.node_sound_wood_defaults(),
			on_place = minetest.rotate_node
		})

		minetest.register_node("mindeca:tree_"..minetree.."_twig", {
			description = mindeca.treepart[minetree].twig,
			drawtype = "nodebox",
			connects_to = {"group:tree", "group:leaves", "group:wood", "group:twig"},
			node_box = {
				type = "connected",
				fixed = {-2/16, -2/16, -2/16, 2/16, 2/16, 2/16},
				connect_top = {-2/16, -2/16, -2/16, 2/16, 8/16, 2/16},
				connect_bottom = {-2/16, -8/16, -2/16, 2/16, 2/16, 2/16},
				connect_front = {-2/16, -2/16, -8/16, 2/16, 2/16, 2/16},
				connect_left = {-8/16, -2/16, -2/16, 2/16, 2/16, 2/16},
				connect_back = {-2/16, -2/16, -2/16, 2/16, 2/16, 8/16},
				connect_right = {-2/16, -2/16, -2/16, 8/16, 2/16, 2/16},
				disconnected = {-2/16, -8/16, -2/16, 2/16, 8/16, 2/16},
			},
			tiles = {"mindeca_tree_"..minetree.."_trunk.png"},
			paramtype = "light",
			paramtype2 = "facedir",
			is_ground_content = false,
			groups = {tree = 1, choppy = 3, oddly_breakable_by_hand = 3, flammable = 3},
			flags = "force_placement",
			sounds = default.node_sound_wood_defaults(),
			on_place = minetest.rotate_node
		})

		minetest.register_node("mindeca:tree_"..minetree.."_twig_charred", {
			description = mindeca.treepart[minetree].chartwig,
			drawtype = "nodebox",
			connects_to = {"group:tree", "group:leaves"},
			node_box = {
				type = "fixed",
				fixed = {-2/16, -8/16, -2/16, 2/16, 8/16, 2/16},
				},
			tiles = {
				"mindeca_s_char_tip.png",
				"mindeca_tree_"..minetree.."_trunk.png",
				{name = "mindeca_tree_"..minetree.."_trunk.png^mindeca_overlay_charred.png",}
				},
			paramtype = "light",
			paramtype2 = "facedir",
			is_ground_content = false,
			groups = {tree = 1, choppy = 3, oddly_breakable_by_hand = 3, flammable = 3},
			flags = "force_placement",
			sounds = default.node_sound_wood_defaults(),
			on_place = minetest.rotate_node
		})
		end
	end

	local doorname = nil
	if door then
		doors.register("mindeca:door_"..minetree, {
			tiles = {{ name = "mindeca_door_"..minetree..".png", backface_culling = true }},
			description = mindeca.treepart[minetree].doord,
			inventory_image = "mindeca_item_door_"..minetree..".png",
			groups = {node = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
			gain_open = 0.06,
			gain_close = 0.13,
			recipe = {
				{"mindeca:wood_tree_"..minetree, "mindeca:wood_tree_"..minetree},
				{"mindeca:wood_tree_"..minetree, "mindeca:wood_tree_"..minetree},
				{"mindeca:wood_tree_"..minetree, "mindeca:wood_tree_"..minetree},
			}
		})
	end
	local stairname = nil
	if stair then
		if minetest.get_modpath("stairs") then
			stairs.register_stair_and_slab(
				"mindeca_wood_tree_"..minetree,
				"mindeca:wood_tree_"..minetree,
				{ snappy=1, choppy=2, oddly_breakable_by_hand=2, flammable=3 },
				{ "mindeca_wood_tree_"..minetree..".png" },
				mindeca.treepart[minetree].stair,
				mindeca.treepart[minetree].slab,
				default.node_sound_wood_defaults()
			)
		end
	end

	local branchname = nil
	local trunkname = nil
	local branchname = nil
	if branch then
		default.register_leafdecay({
			trunks = {"mindeca:tree_"..minetree.."_branch", "mindeca:tree_"..minetree.."_twig"},
			leaves = {"mindeca:tree_"..minetree.."_leaves"},
			radius = 4,
		})
	elseif trunk then
		default.register_leafdecay({
			trunks = {"mindeca:tree_"..minetree.."_log"},
			leaves = {"mindeca:tree_"..minetree.."_leaves"},
			radius = 4,
		})
	end

	local leafaltname = nil
	if leafalt then
		minetest.register_node("mindeca:tree_"..leafalt.."a_leaves", {
			description = leafdesc,
			drawtype = "allfaces_optional",
			waving = 1,
			tiles = {"mindeca_tree_"..leafalt.."_a_leaves.png"},
			special_tiles = {"mindeca_tree_"..leafalt.."_a_leaves_s.png"},
			paramtype = "light",
			is_ground_content = false,
			groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1},
			drop = {
				max_items = 1,
				items = {
					{
						-- player will get sapling with 1/20 chance
						items = {"mindeca:tree_"..minetree.."_sapling"},
						rarity = 20,
					},
					{
						-- player will get drop with 1/10 chance
						items = {"mindeca:item_fruit_"..minetree},
						rarity = 10,
					},
					{
						-- player will get leaves only if he get no saplings,
						-- this is because max_items is 1
						items = {"mindeca:tree_"..minetree.."_leavesa"},
					}
				}
			},
			sounds = default.node_sound_leaves_defaults(),
			after_place_node = after_place_leaves,
		})
	if branch then
		default.register_leafdecay({
			trunks = {"mindeca:tree_"..minetree.."_branch", "mindeca:tree_"..minetree.."_twig"},
			leaves = {"mindeca:tree_"..minetree.."_leaves", "mindeca:tree_"..leafalt.."a_leaves"},
			radius = 4,
		})
	elseif log then
		default.register_leafdecay({
			trunks = {"mindeca:tree_"..minetree.."_log"},
			leaves = {"mindeca:tree_"..minetree.."_leaves", "mindeca:tree_"..leafalt.."a_leaves"},
			radius = 4,
		})
	end
end



-----
--Alt Leaves
-----

--For SOME reason, these are just refusing to play nice

minetest.register_node("mindeca:tree_oak_a_leaves", {
	description = "Oak Tree Leaves (Autumn)\n\nOak leaves that signal the coming of fall.\nThese are already in fall colours.\n\nMindeca",
	drawtype = "allfaces_optional",
	waving = 1,
	tiles = {"mindeca_tree_oak_a_leaves.png"},
	special_tiles = {"mindeca_tree_oak_a_leaves_s.png"},
	paramtype = "light",
	is_ground_content = false,
	groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1},
	drop = {
		max_items = 1,
		items = {
			{
				-- player will get sapling with 1/20 chance
				items = {"mindeca:tree_oak_a_sapling"},
				rarity = 20,
			},
			{
				-- player will get drop with 1/10 chance
				items = {"mindeca:item_fruit_acorn"},
				rarity = 10,
			},
			{
				-- player will get leaves only if he get no saplings,
				-- this is because max_items is 1
				items = {"mindeca:tree_oak_a_leaves"},
			}
		}
	},
	sounds = default.node_sound_leaves_defaults(),
	after_place_node = after_place_leaves,
})

default.register_leafdecay({
	trunks = {"mindeca:tree_oak_log"},
	leaves = {"mindeca:tree_oak_a_leaves"},
	radius = 4,
})
EDIT: Lots of headaches later and I got it working

It was the leaf decay stuff that was breaking it

But I need the leaf decay stuff

@.@ What in the heck

EDIT 2: Well, had to do each decay manually

Will gladly take advice on how to tie them in, so far leaf decay and tree grow timers are the only things that want to fight with me on this

For now? Guess it's as [SOLVED] as it can be

Code: Select all

mindeca.trees = {
    --{"Tree",    "Log/Wood",    "Door",        "Fruit",    "AltLeaves",    "Stairs/Fence",    "Branch/Twig"},
    --Spring
    {"cherry",    "Cherry",    "cherry",    "cherry",    nil,        "Cherry",    nil},
    {"poplar",    nil,        nil,        nil,        nil,        nil,        "Poplar"},
    --Summer
    {"peach",    nil,        nil,        "peach",    nil,        nil,        "Peach"},
    {"plum",    nil,        nil,        "plum",        nil,        nil,        "Plum"},
    {"magnolia",    "Magnolia",    "magnolia",    nil,        nil,        "Magnolia",    nil},
    {"dogwood",    "Dogwood",    "dogwood",    nil,        nil,        "Dogwood",    nil},
    {"ash",        "Ash",        "ash",        nil,        nil,        "Ash",        nil},
    --Autumn
    {"oak",        "Oak",        "oak",        nil,        "oak",        "Oak",        nil},
    --Winter
    {"cedar",    "Cedar",    "cedar",    nil,        nil,        "Cedar",    nil}
}

--Terms

--trunk = log
--wood = planks, wood
--doord = door
--fruit = fruit
--leaf = leaves
--leafa = alternate leaves
--stair = stairs
--slab = slabs
--branchd = branch
--twigd = twig
--chartwig = charred twig

mindeca.treepart = {
    --Spring
    cherry = {
        trunk = "Cherry Tree Log\n\nA beautiful Cherry Tree log.\n\nMindeca",
        wood = "Cherry Wood\n\nSoft pink wood for building.\n\nMindeca",
        doord = "Cherry Wood Door\n\nA pink, traditional sliding door.\n\nMindeca",
        fruit = "Cherry\n\nA tasty cherry for a quick snack.\n\nMindeca",
        leaf = "Cherry Tree Leaves\n\nSoft leaves that promise pink blossoms.\n\nMindeca",
        stair = "Cherry Wood Stairs\n\nPink stairs with a faint cherry scent.\n\nMindeca",
        slab = "Cherry Wood Slab\n\nA pink slab with a faint cherry scent.\n\nMindeca"
    },
    poplar = {
        leaf = "Poplar Tree Leaves\n\nLeaves that are quite Pop-u-lar.\n\nMindeca",
        branchd = "Poplar Tree Branch\n\nA very Pop-u-lar branch.\n\nMindeca",
        twigd = "Poplar Tree Twig\n\nA very Pop-u-lar twig.\n\nMindeca",
        chartwig = "Poplar Tree Twig (Charred)\n\nA charred twig that got too Pop-u-lar.\n\nMindeca"
    },
    --Summer
    peach = {
        fruit = "Peach\n\nA juicy peach for a quick snack.\n\nMindeca",
        leaf = "Peach Tree Leaves\n\nLeaves with a nice, floral scent.\n\nMindeca",
        branchd = "Peach Branch\n\nA peachy-keen branch.\n\nMindeca",
        twigd = "Peach Twig\n\nA peachy-keen twig.\n\nMindeca",
        chartwig = "Peach Twig (Charred)\n\nA charred twig that things don't look peachy for.\n\nMindeca"
    },
    plum = {
        fruit = "Plum\n\nA juicy plum for a quick snack.\n\nMindeca",
        leaf = "Plum Tree Leaves\n\nLeaves with a sharp, floral scent.\n\nMindeca",
        branchd = "Plum Branch\n\nA branch plum full of spirit.\n\nMindeca",
        twigd = "Plum Twig\n\nA twig plum full of spirit.\n\nMindeca",
        chartwig = "Plum Twig (Charred)\n\nA charred twig plum full of ash.\n\nMindeca"
    },
    magnolia = {
        trunk = "Magnolia Tree Log\n\nA smooth log with a jungle flora scent.\n\nMindeca",
        wood = "Magnolia Wood\n\nPale wood useful for building.\n\nMindeca",
        doord = "Magnolia Door\n\nAn intricate door with floral designs.\n\nMindeca",
        leaf = "Magnolia Leaves\n\nLeaves with a floral, jungle scent.\n\nMindeca",
        stair = "Magnolia Wood Stairs\n\nPale stairs useful for building.\n\nMindeca",
        slab = "Magnolia Wood Slab\n\nA pale slab useful for building.\n\nMindeca"
    },
    dogwood = {
        trunk = "Dogwood Log\n\nA log of Dogwood. Its bark is worse than its bite.\n\nMindeca",
        wood = "Dogwood Wood\n\nDogwood Wood with which you would build.\n\nMindeca",
        doord = "Dogwood Door\n\nA simple door with a porthole window.\n\nMindeca",
        leaf = "Dogwood Leaves\n\nLeaves of a Dogwood tree.\n\nMindeca",
        stair = "Dogwood Stairs\n\nStairs of Dogwood. No bark, no bite.\n\nMindeca",
        slab = "Dogwood Slab\n\nA slab of Dogwood. No bark, no bite.\n\nMindeca"
    },
    ash = {
        trunk = "Ash Tree Log\n\nA log of Ash. No, not the burnt ash.\n\nMindeca",
        wood = "Ash Wood\n\nAshen wood useful for building.\n\nMindeca",
        doord = "Ash Door\n\nA somewhat rickety looking door.\n\nMindeca",
        leaf = "Ash Leaves\n\nLeaves that ash-k no questions.\n\nMindeca",
        stair = "Ash Wood Stairs\n\nAshen stairs useful for building.\n\nMindeca",
        slab = "Ash Wood Slab\n\nAn ashen slab useful for building.\n\nMindeca"
    },
    --Autumn
    oak = {
        trunk = "Oak Tree Log\n\nA sturdy Oak log.\n\nMindeca",
        wood = "Oak Wood\n\nSturdy Oak wood for building.\n\nMindeca",
        doord = "Oak Door\n\nA solid, sturdy door of Oak.\n\nMindeca",
        leaf = "Oak Tree Leaves\n\nOak leaves that signal the coming of fall.\n\nMindeca",
        leafa = "Oak Tree Leaves (Autumn)\n\nOak leaves that signal the coming of fall.\nThese are already in fall colours.\n\nMindeca",
        stair = "Oak Wood Stairs\n\nSturdy stairs made of Oak.\n\nMindeca",
        slab = "Oak Wood Slab\n\nA sturdy slab made of Oak.\n\nMindeca"
    },
    --Winter
    cedar = {
        trunk = "White Cedar Log\n\nA log of White Cedar. Very multipurpose.\n\nMindeca",
        wood = "White Cedar Wood\n\nWood of the versatile White Cedar.\n\nMindeca",
        doord = "White Cedar Door\n\nSee? Door!\n\nMindeca",
        leaf = "White Cedar Leaves\n\nLeaves with a dainty scent. Good as tea.\n\nMindeca",
        stair = "White Cedar Stairs\n\nStairs of versatile White Cedar wood.\n\nMindeca",
        slab = "White Cedar Slab\n\nA slab of versatile White Cedar wood.\n\nMindeca"
    }
}

for i in ipairs(mindeca.trees) do
    local minetree = mindeca.trees[i][1]
    local trunk = mindeca.trees[i][2]
    local doora = mindeca.trees[i][3]
    local fruit = mindeca.trees[i][4]
    local leafalt = mindeca.trees[i][5]
    local stair = mindeca.trees[i][6]
    local minetwig = mindeca.trees[i][7]

    minetest.register_node("mindeca:tree_"..minetree.."_leaves", {
        description = mindeca.treepart[minetree].leaf,
        drawtype = "allfaces_optional",
        waving = 1,
        tiles = {"mindeca_tree_"..minetree.."_leaves.png"},
        special_tiles = {"mindeca_tree_"..minetree.."_leaves_s.png"},
        paramtype = "light",
        is_ground_content = false,
        groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1},
        drop = {
            max_items = 1,
            items = {
                {
                    -- player will get sapling with 1/20 chance
                    items = {"mindeca:tree_"..minetree.."_sapling"},
                    rarity = 20,
                },
                {
                    -- player will get leaves only if he get no saplings,
                    -- this is because max_items is 1
                    items = {"mindeca:tree_"..minetree.."_leaves"},
                }
            }
        },
        sounds = default.node_sound_leaves_defaults(),
        after_place_node = after_place_leaves,
    })

    local trunkname = nil
    if trunk then
        minetest.register_node("mindeca:tree_"..minetree.."_log", {
            description = mindeca.treepart[minetree].trunk,
            tiles = {
                "mindeca_tree_"..minetree.."_trunk_top.png",
                "mindeca_tree_"..minetree.."_trunk_top.png",
                "mindeca_tree_"..minetree.."_trunk.png",
                },
            paramtype2 = "facedir",
            is_ground_content = false,
            groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2},
            sounds = default.node_sound_wood_defaults(),
            on_place = minetest.rotate_node
        })
        minetest.register_node("mindeca:wood_tree_"..minetree, {
            description = mindeca.treepart[minetree].wood,
            tiles = {"mindeca_wood_tree_"..minetree..".png"},
            is_ground_content = false,
            groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 3, wood = 1},
            flags = "force_placement",
            sounds = default.node_sound_wood_defaults(),
        })
        default.register_leafdecay({
            trunks = {"mindeca:tree_"..minetree.."_log"},
            leaves = {"mindeca:tree_"..minetree.."_leaves"},
            radius = 4,
        })
    end

    local leafaltname = nil
    if leafalt then
        minetest.register_node("mindeca:tree_"..leafalt.."_a_leaves", {
            description = mindeca.treepart[minetree].leaf,
            drawtype = "allfaces_optional",
            waving = 1,
            tiles = {"mindeca_tree_"..leafalt.."_a_leaves.png"},
            special_tiles = {"mindeca_tree_"..leafalt.."_a_leaves_s.png"},
            paramtype = "light",
            is_ground_content = false,
            groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1},
            drop = {
                max_items = 1,
                items = {
                    {
                        -- player will get sapling with 1/20 chance
                        items = {"mindeca:tree_"..minetree.."_sapling"},
                        rarity = 20,
                    },
                    {
                        -- player will get drop with 1/10 chance
                        items = {"mindeca:item_fruit_"..minetree},
                        rarity = 10,
                    },
                    {
                        -- player will get leaves only if he get no saplings,
                        -- this is because max_items is 1
                        items = {"mindeca:tree_"..minetree.."_leavesa"},
                    }
                }
            },
            sounds = default.node_sound_leaves_defaults(),
            after_place_node = after_place_leaves,
        })
    end

    local dooraname = nil
    if doora then
        doors.register("mindeca:door_"..minetree, {
            tiles = {{ name = "mindeca_door_"..minetree..".png", backface_culling = true }},
            description = mindeca.treepart[minetree].doord,
            inventory_image = "mindeca_item_door_"..minetree..".png",
            groups = {node = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
            gain_open = 0.06,
            gain_close = 0.13,
            recipe = {
                {"mindeca:wood_tree_"..minetree, "mindeca:wood_tree_"..minetree},
                {"mindeca:wood_tree_"..minetree, "mindeca:wood_tree_"..minetree},
                {"mindeca:wood_tree_"..minetree, "mindeca:wood_tree_"..minetree},
            }
        })
    end

    local stairname = nil
    if stair then
        stairs.register_stair_and_slab(
            "mindeca_wood_tree_"..minetree,
            "mindeca:wood_tree_"..minetree,
            { snappy=1, choppy=2, oddly_breakable_by_hand=2, flammable=3 },
            { "mindeca_wood_tree_"..minetree..".png" },
            mindeca.treepart[minetree].stair,
            mindeca.treepart[minetree].slab,
            default.node_sound_wood_defaults()
        )
    end

    local fruitname = nil
    if fruit then
        minetest.register_node("mindeca:item_fruit_"..fruit, {
            description = mindeca.treepart[minetree].fruit,
            drawtype = "plantlike",
            tiles = {"mindeca_item_fruit_"..minetree..".png"},
            inventory_image = "mindeca_item_fruit_"..minetree..".png",
            paramtype = "light",
            sunlight_propagates = true,
            walkable = false,
            is_ground_content = false,
            selection_box = {
                type = "fixed",
                fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
            },
            groups = {fleshy = 3, dig_immediate = 3, flammable = 2, leafdecay = 3, leafdecay_drop = 1, food_apple = 1},
            on_use = minetest.item_eat(2),
            sounds = default.node_sound_leaves_defaults(),
            after_place_node = function(pos, placer, itemstack)
                minetest.set_node(pos, {name = "mindeca:item_fruit_"..minetree, param2 = 1})
            end,
        })
    end

    local minetwigname = nil
    if minetwig then
        minetest.register_node("mindeca:tree_"..minetree.."_branch", {
            description = mindeca.treepart[minetree].branchd,
            drawtype = "nodebox",
            connects_to = {"group:tree", "group:leaves", "group:wood", "group:soil"},
            node_box = {
                type = "connected",
                fixed = {-4/16, -4/16, -4/16, 4/16, 4/16, 4/16},
                connect_top = {-4/16, -4/16, -4/16, 4/16, 8/16, 4/16},
                connect_bottom = {-4/16, -8/16, -4/16, 4/16, 4/16, 4/16},
                connect_front = {-4/16, -4/16, -8/16, 4/16, 4/16, 4/16},
                connect_left = {-8/16, -4/16, -4/16, 4/16, 4/16, 4/16},
                connect_back = {-4/16, -4/16, -4/16, 4/16, 4/16, 8/16},
                connect_right = {-4/16, -4/16, -4/16, 8/16, 4/16, 4/16},
                disconnected = {-4/16, -8/16, -4/16, 4/16, 8/16, 4/16},
                },
            tiles = {"mindeca_tree_"..minetree.."_trunk.png"},
            paramtype = "light",
            paramtype2 = "facedir",
            is_ground_content = false,
            sunlight_propagates = true,
            groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
            flags = "force_placement",
            sounds = default.node_sound_wood_defaults(),
            on_place = minetest.rotate_node
        })

        minetest.register_node("mindeca:tree_"..minetree.."_twig", {
            description = mindeca.treepart[minetree].twigd,
            drawtype = "nodebox",
            connects_to = {"group:tree", "group:leaves", "group:wood", "group:twig"},
            node_box = {
                type = "connected",
                fixed = {-2/16, -2/16, -2/16, 2/16, 2/16, 2/16},
                connect_top = {-2/16, -2/16, -2/16, 2/16, 8/16, 2/16},
                connect_bottom = {-2/16, -8/16, -2/16, 2/16, 2/16, 2/16},
                connect_front = {-2/16, -2/16, -8/16, 2/16, 2/16, 2/16},
                connect_left = {-8/16, -2/16, -2/16, 2/16, 2/16, 2/16},
                connect_back = {-2/16, -2/16, -2/16, 2/16, 2/16, 8/16},
                connect_right = {-2/16, -2/16, -2/16, 8/16, 2/16, 2/16},
                disconnected = {-2/16, -8/16, -2/16, 2/16, 8/16, 2/16},
            },
            tiles = {"mindeca_tree_"..minetree.."_trunk.png"},
            paramtype = "light",
            paramtype2 = "facedir",
            is_ground_content = false,
            groups = {tree = 1, choppy = 3, oddly_breakable_by_hand = 3, flammable = 3},
            flags = "force_placement",
            sounds = default.node_sound_wood_defaults(),
            on_place = minetest.rotate_node
        })

        minetest.register_node("mindeca:tree_"..minetree.."_twig_charred", {
            description = mindeca.treepart[minetree].chartwig,
            drawtype = "nodebox",
            connects_to = {"group:tree", "group:leaves"},
            node_box = {
                type = "fixed",
                fixed = {-2/16, -8/16, -2/16, 2/16, 8/16, 2/16},
                },
            tiles = {
                "mindeca_s_char_tip.png",
                "mindeca_tree_"..minetree.."_trunk.png",
                {name = "mindeca_tree_"..minetree.."_trunk.png^mindeca_overlay_charred.png",}
                },
            paramtype = "light",
            paramtype2 = "facedir",
            is_ground_content = false,
            groups = {tree = 1, choppy = 3, oddly_breakable_by_hand = 3, flammable = 3},
            flags = "force_placement",
            sounds = default.node_sound_wood_defaults(),
            on_place = minetest.rotate_node
        })
    end
end

-----
--Decay
-----

--Spring

default.register_leafdecay({
    trunks = {"mindeca:tree_cherry_log"},
    leaves = {"mindeca:tree_cherry_leaves"},
    radius = 4,
})

--

--

--

default.register_leafdecay({
    trunks = {"mindeca:tree_poplar_twig", "mindeca:tree_poplar_branch"},
    leaves = {"mindeca:tree_poplar_leaves"},
    radius = 4,
})


--Summer

default.register_leafdecay({
    trunks = {"mindeca:tree_peach_twig", "mindeca:tree_peach_branch"},
    leaves = {"mindeca:tree_peach_leaves"},
    radius = 4,
})

default.register_leafdecay({
    trunks = {"mindeca:tree_plum_twig", "mindeca:tree_plum_branch"},
    leaves = {"mindeca:tree_plum_leaves"},
    radius = 4,
})

default.register_leafdecay({
    trunks = {"mindeca:tree_magnolia_log"},
    leaves = {"mindeca:tree_magnolia_leaves"},
    radius = 4,
})

default.register_leafdecay({
    trunks = {"mindeca:tree_dogwood_log"},
    leaves = {"mindeca:tree_dogwood_leaves"},
    radius = 4,
})

default.register_leafdecay({
    trunks = {"mindeca:tree_ash_log"},
    leaves = {"mindeca:tree_ash_leaves"},
    radius = 4,
})


--Autumn

--

--

--

--

default.register_leafdecay({
    trunks = {"mindeca:tree_oak_log"},
    leaves = {"mindeca:tree_oak_leaves", "mindeca:tree_oak_a_leaves"},
    radius = 4,
})


--Winter

--

--

--

--

default.register_leafdecay({
    trunks = {"mindeca:tree_cedar_log"},
    leaves = {"mindeca:tree_cedar_leaves"},
    radius = 4,
})

User avatar
Blockhead
Member
Posts: 1622
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: [SOLVED?] Indexing nil value but not sure why

by Blockhead » Post

I put some print statements in to see which trees were actually getting leaf decay inside your loop:

Code: Select all

        local trunknodename = "mindeca:tree_"..minetree.."_log"
        print("Trunk node: " .. trunknodename)
        local leafnodename = "mindeca:tree_"..minetree.."_leaves"
        print("Leaf node: " .. leafnodename)

        default.register_leafdecay({
            trunks = {trunknodename},
            leaves = {leafnodename},
            radius = 4,
        })
which then lead to the outputs:

Code: Select all

Trunk node: mindeca:tree_cherry_log
Leaf node: mindeca:tree_cherry_leaves
Trunk node: mindeca:tree_cherry_log
Leaf node: mindeca:tree_cherry_leaves
Trunk node: mindeca:tree_magnolia_log
Leaf node: mindeca:tree_magnolia_leaves
Trunk node: mindeca:tree_dogwood_log
Leaf node: mindeca:tree_dogwood_leaves
Trunk node: mindeca:tree_ash_log
Leaf node: mindeca:tree_ash_leaves
Trunk node: mindeca:tree_oak_log
Leaf node: mindeca:tree_oak_leaves
Trunk node: mindeca:tree_cedar_log
Leaf node: mindeca:tree_cedar_leaves
Notice how this doesn't include plums, which you went and registered afterwards. You'll need to review your tables to see if you got something wrong I suppose.

and also a warning that's probably a sign of a bug:

Code: Select all

2022-08-08 13:14:15: WARNING[Main]: Undeclared global variable "after_place_leaves" accessed at /home/[redacted]/.minetest/mods/mindeca/init.lua:214
When your source files are getting this big, it's generally a good move to have them in source control like git, and put them on a website like GitHub, GitLab, or so on. Not only will that help you keep track of the versions properly, it'll help us get your code easier by just cloning it, instead of copying and pasting it into our own mod directories, a process fraught with potential errors. It will also potentially invite contributors more easily through Pull/Merge requests.

Hope that helps
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

Icalasari
Member
Posts: 166
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

Re: [SOLVED?] Indexing nil value but not sure why

by Icalasari » Post

Ah crap, warning style errors. Had fun with those when I did a mod for SRB2 - Never did figure out how to fix it for Tails Doll >.>

Guess when I get time again, I'll upload to GitHub

And odd, also peach and poplar are gone in that. Seems if the trunk isn't in it, it wants to ignore the leaves too. I have leaves at the top there specifically so it doesn't get caught up in any of the other checks, though?

EDIT: Checked my own debug, seems every leaf type is setting that off =/ Guess I need to also check minetest_game again

EDIT 2: ...Ok it's not in minetest_game where did I get that line then? Will need to see what happens if I remove it then

EDIT 3: Well got the errors reduced a lot

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests