Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Variables

edited July 2014 in General Posts: 2

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

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 9,725

    variableName=123 Is that what you mean.

  • Posts: 135

    Welcome to the forums by the way

  • IgnatzIgnatz Mod
    Posts: 5,396

    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.

    http://coolcodea.wordpress.com/2013/06/19/index-of-posts/

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

  • Posts: 2

    Thank you for the input! I much appreciate it.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @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!

  • edited July 2014 Posts: 127
    --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.
        end
    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! :-D

    @sccunin

  • 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

  • Posts: 2,051

    @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.
        end
    end
    
  • Posts: 1,976

    @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().
Sign In or Register to comment.