I'm messing around with some simple lua programming just for fun. The program I'm working on is simply supposed to take a single argument and print the relationship to oneself based on a number line. It's just a couple of simple formulae and a function to build and print strings from the data.
My problem is that every single 'if' statement in my program is coming back with the error " '=' expected near 'if' "
So far I've tried seeing if there's a known version issue (there isn't and I don't know why there would be)
I've messed around with my if statements, tried different comparators, replaced all variables with literals, stripped down to single clause statements, and none of this is working.
This is my first attempt to run lua from a terminal. In the past I've only written lua for Defold, and never run into something like this.
I'll put one instance of the issue as an example:
function number_of_greats(generation)
local var g = math.abs(generation)
local var num_greats
if generation > -2 or generation then
num_greats = 0
else
num_greats = g-2
end
return num_greats
end
the error is "expected '=' near 'if'"
the expected result is that the function returns either result for the function G(gen) depending on the range gen fits in.
generation is a position on a number. Negative represents ancestors, positive represents successors.
the mathematical function is: G(gen) = |gen| - 2 for gen < -2 and gen > 2 G(gen) = 0 for -2 < gen < 2 G(gen) is the number of "greats" in the relationship title
Aucun commentaire:
Enregistrer un commentaire