Hello. I’m very new to Lua, and would like to know how to input a variable.( as var would be in other languages.)

variableName=123 Is that what you mean.

Welcome to the forums by the way

Hi @sccunin - we all start that way! Have a look at the links on the wiki, there is some good stuff there.

I found Coodea and Lua hard at first, so I wrote some ebooks to help. You can find them here, along with a blog about Codea.

I suggest you start with Lua, the language behind Codea, before getting into the graphics.

Thank you for the input! I much appreciate it.

@sccunin - assuming you come from another language, the big difference in Lua is (I believe) the table concept, which handles arrays, dictionaries, classes, ie basically everything except number and text variables. It’s worth mastering because it’s very powerful.

The big difference in Codea (the graphic part of the app) is how it refreshes the screen constantly. This takes some getting used to. I’ve tried to explain it in my Codea ebook.

Then you have the OpenGL graphics and Box2D physics engine which are woven neatly into Codea . There’s lots of fun to be had!

--The Variable Program

function setup()
    x = 10 --sets x to 10
    if x == 10 then --checks if x is 10
        print("x is " .. x) -- .. Concatenates the string "x is " with the var x.
output: x is 10

As you can see, a simple program demonstrating the usage of variables. Includes concatenation techniques, assignments, equality checks, and comments… EOL comments in Codea start with “–”.

Have fun with Codea! :smiley:


Like @Ignatz said, there are many different CRUDE types of variables, like…

A = "Hello World!" --Strings
B= 1 --integers
function c() end --Functions
D = userdata --userdata
E = {1, 10} --tables
F = parameter.integer(1, 10) --parameters
G = image(10, 10) --codea images 

And lots more. But the most common type of implemented variables are…

--class objects!!!
H= H()
H = class()

In my next comment, I will explain more about different variable types. Or is this getting to boring? XD

@aurumcoder2624, your first example won’t run because you left out a then and two ends

@scunnin, here is his example, runnable:

function setup()
    x = 10                        --sets x to 10

    if x == 10 then           --checks if x is 10
        print("x is " .. x)      -- .. Concatenates the string "x is " with the var x.

@aurumcoder2624 Also, in your variable types there are a few mistakes.

  1. function c() is just syntax candy for c = function()
  2. H = H() is replacing the H “class” with an instance of the H “class.” You need it to be something like instanceOfH = H()
  3. The previous mistake’s line should be after H = class, or you would get an “attempt to index nil value” error
  4. There are no “class objects” in Codea. class() is just a function to prepare a metatable with a bunch of variables, including init().