I’m a complete newbie to Lua. I’m starting with the Programming in Lua book and tried to get the factorial example to work. I created a lua script in User Scripts called Factorial.lua and typed the following.
function fact (n)
if n == 0 then
return 1
else
return n * fact(n-1)
end
end
print(“enter a number:”)
a = io.read("*number")
print(fact(a))
When I tried to run it, I got the following in Terminal with no opportunity to enter a number.
enter a number:
*** Factorial.lua:5: attempt to perform arithmetic on local ‘n’ (a nil value)
*** stack traceback:
*** Factorial.lua:5: in function ‘fact’
*** Factorial.lua:11: in main chunk
As far as I am aware it will not work in the terminal, though someone may correct me?
To get user input and output to your script you need to create something like a GUI/ or menu entry which has renoise notifiers attached.
If you are just starting to learn Lua in the renoise terminal then I would worry about that stuff later when looking at the example scripts and just test your functions by adding your values directly into the script/ Testpad i.e. print(fact(10)) in the following:
function fact (n)
if n == 0 then
return 1
else
return n * fact(n-1)
end
end
print(fact(10))
Edit: also if you want more beginners material on Lua, check out the links in my sig below: