Blockhead wrote: ↑Mon Aug 15, 2022 04:18
The sooner you can figure out the actual syntax of Lua the sooner you'll stop butting your head against a brick wall looking at the weeds of what each error message tells you and looking more holistically at what's wrong on that particular line. Instead of "it tells me it expects this, I'll put one there", you can begin to think in terms like "this function declaration is wrong". In this case, Lua's syntax for the start of a function declaration takes only a few valid forms. Here's a tutorial on those:
SNIP
Code: Select all
-- 4. Assigning a function to be the value of a global variable. Equivalent in effect to (1)
name = function()
name = function(arg1)
name = function(arg1, arg2)
Code: Select all
function grow_minebush["grow_new_"..name.."_bush"] (pos)
Using the above syntax tutorial, can you tell me how you would reformat that line so it's valid Lua?
The name order there. Skamiz did answer it but I understand now. Guess most of my problems are syntax related, so going to pay extra close attention to that chapter tomorrow after work (woo it being too late at night to do any more trouble shooting nor looking at the links in detail)
All the help I am getting is greatly appreciated, but I like the way you help the most XD It's honestly helping me see the why of what I did wrong rather than just the what. Other help I do try to understand, or I try to backward engineer, but as you can see, it's... Not working out like it usually does for other problems I approach that way
Now I'm getting a new "error" but my god it... This makes me feel like a ton of weight is off my shoulders, I think it's because I am now understanding it instead of feeling like I'm
guessing at what is wrong?
I may need to stop looking at code for a few days after this just to get my head straight
Last part is getting it to refer to the growth cycle. I at least know what's going wrong here, just not sure how to go around it since well, both need to be function(pos), right?
can_grow(pos, def.grow) doesn't work
Code: Select all
grow_minebush["grow_new_"..name.."_bush"] = function(pos)
can_grow["can_grow_"..def.grow] = function(pos)
if not mindeca.can_grow(pos) then
-- try a bit later again
minetest.get_node_timer(pos):start(math.random(1, 1))
return
end
minetest.remove_node(pos)
minetest.place_schematic({x = pos.x-1, y = pos.y, z = pos.z-1}, minetest.get_modpath("mindeca").."/schematics/mindeca_bush_berry_"..name..".mts", "random", nil, false)
end
If I do try
can_grow(pos, def.grow, then I get this:
Error:
Code: Select all
AsyncErr: Lua: Runtime error from mod 'mindeca' in callback node_on_timer(): ...-5.5.1-win64\bin\..\mods\mindeca\Mindeca Main/bushes.lua:75: attempt to call upvalue 'can_grow_' (a table value)
stack traceback:
...-5.5.1-win64\bin\..\mods\mindeca\Mindeca Main/bushes.lua:75: in function <...-5.5.1-win64\bin\..\mods\mindeca\Mindeca Main/bushes.lua:74>
Lines 74-82 of the Code:
Code: Select all
grow_minebush["grow_new_"..name.."_bush"] = function(pos)
if not can_grow_(pos, def.grow) then
-- try a bit later again
minetest.get_node_timer(pos):start(math.random(1, 1))
return
end
minetest.remove_node(pos)
minetest.place_schematic({x = pos.x-1, y = pos.y, z = pos.z-1}, minetest.get_modpath("mindeca").."/schematics/mindeca_bush_berry_"..name..".mts", "random", nil, false)
end
The table in question + Local Functions that are declared:
Code: Select all
mindeca.mbush = {
--bush = {
--"Bush Desc",
--"Seedling Desc",
--"Fruit",
--"Berry Laden Bush Desc",
--"Grow Cycle",
--"Berry Grow Cycle",
--"Light Level",
--"Water Need"},
--Spring
--Summer
rasp = {
bushdesc = "Raspberry Bush Leaves\n\nLeaves that once bore raspberries.",
seeddesc = "Raspberry Bush Seedling\n\nA seedling to grow a bush of tart raspberries.",
fruit = "raspberry",
bushfdesc = "Raspberry Bush Leaves (Berry Laden)\n\n[Creative]",
grow = _spirit,
bgrow = rasp,
glow = nil,
water = nil},
--Autumn
--Winter
}
local grow_minebush = { }
local can_grow_ = { }
EDIT: Got finished getting ready faster than I expected and got a chance to look at the link and...
function in
can_grow["can_grow_"..def.grow] = function(pos) doesn't HAVE to be function, does it? I could have
function2(pos) instead, right?
EDIT 2: Nope misread. Looks like it has to be
function(pos) no matter what. Unless I'm still misreading from tiredness and mental exhaustion
Definitely need to come back to this tomorrow
EDIT 3: Just clicked this is the same as on_place = function(blah), after_dignode = function(blah), and so on
...I need to stop putting off sleep due to things occurring to me. Still a bit confused but I think I have an idea? I think. Not really confident
EDIT 4: Nope, I had no idea. But I know the issue is this part:
Code: Select all
grow_minebush["grow_new_"..name.."_bush"] = function(pos)
if not can_grow_(pos, def.grow) then
-- try a bit later again
minetest.get_node_timer(pos):start(math.random(1, 1))
return
end
I'm not sure how to make
if not can_grow_(pos, def.grow) then or
if not can_grow_["can_grow_"..name] then work. It feels like something obvious, like something I should be able to easily figure out from even my
own code, but something is not clicking