I’ve been trying to get this simple Factorial program that takes a numeral and returns it’s factorial…it keeps telling me (n) is a nil value, what am I doing wrong?
function setup ()
-- defines a factorial function
if n == 0 then
return n * fact(n-1)
print ("enter a number:")
a = io.read("*n") --reads a number
@D4rk_Code Codea doesn’t use io.read from the keyboard in that manner. Here’s a different approach for input of a value. Enter a value into the “value” area and then press “factorial”.
function setup ()
print(value.." factorial is ",fact(value))
if n==0 then
Thanks, I’m working through book from lua.org “Programming in Lua” to grasp a better understanding of the language, this was one of it’s tutorials, I was wondering why it never worked on my iPad
While the Lua book gives you a good understanding of how to program in Lua, Codea doesn’t do everything in the book. You might also want to go thru the built in documentation of what Codea does so you have an idea of what you can and can’t do. If there’s something you don’t understand, there are plenty of people here that will help.
okie, I was just a little confused because it worked on linux Lua compiler
I am an absolute beginner on coding and I too am following the book but I don’t understand how I am going to learn when It comes to this stuff. Is there a book or something that I can start by that will teach me everything that I need to know when it comes to Codea as well? I don’t get why I would have to learn Codea and then learn Lua as well. Is this one of the only differences? Is there a source that I can use to get all of the differences in the book to the program?
See the links at the top of the forum page. Select Wiki and look at those.
Ignatz I recently started reading one of you’re books. I love it so far! But the loops are not working and it is frustrating me lol. Thank you for your response.
@abstractartist07 Here’s an example of 2 simple loops.
for a=1,10 do -- loop to do something 10 times
print(a,a*a) -- prints a number and that number times itself
for nbr,value in pairs(t) do -- loop to print values in a table.
print(nbr,value) -- print a table position and the value there.