Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Variable Scope — Gideros Forum

Variable Scope

ArtLeeAppsArtLeeApps Member
edited June 2013 in General questions
Hi all,

You really need a Category called "Regular Newbie Questions" :)

Knowing that "local" is best as its memory friendly.....

Question 1)

If you declare a variable in the main file using "local"
eg.
local gameHeight = application:getContentHeight()

Can scenes or Classes access the variable ?
* In some languages, the scope of the variable is known by called procedures.. etc.

Question 2)

If i were to use global variables for the application height and width. Given in this case i fix the orientation of the game to portrait. Can i get the size once in main and use it throughout the game... eg.

gameHeight = application:getContentHeight()


Comments

  • sslivkasslivka Member
    edited June 2013 Accepted Answer
    @ArtLeeApps
    -Can scenes or Classes access the variable ?
    No
    -- myclass.lua
    MyClass = Core.class()
    function MyClass:init()
    	print(myLocalVar)
    end
     
    -- main.lua
    local myLocalVar = "Hello, World!"
    local myClass = MyClass.new()
    print(myLocalVar)
     
    --[[ return
    main.lua is uploading.
    myclass.lua is uploading.
    Uploading finished.
    nil
    Hello, World!
    ]]
    -Can i get the size once in main and use it throughout the game...
    Yes, and you can:
    application.H = application:getContentHeight()
    print(application.H)
  • strictly speaking that's a Lua question, not a Gideros question...............
    http://esem.name/sound ♫ sound and music at ShadyLabs (Clouds of Steel, Aftermath Alvin)
  • @gmarinov I'm sure your absolutely correct.

    But then i would have to find a Lua forum, and i don't think i would find people more helpful and knowledgeable about Lua and Gideros in one place than here :-)

    Plus, I'm still green and the distinction between the two is like flour and icing sugar, you can't really tell until you taste it....... :)

    Likes: Platypus

    +1 -1 (+1 / -0 )Share on Facebook
  • @ArtLeeApps, I can't recommend Roberto Ierusalimchy's "Programming in Lua" enough. Read and practice for a weekend, it's like magic.
    http://esem.name/sound ♫ sound and music at ShadyLabs (Clouds of Steel, Aftermath Alvin)
  • @gmarinov thank you, i just downloaded it for reading on the train. i spend about 1.5hours everyday to work/back.
Sign In or Register to comment.