0

Well I have a class like this as an example:

   --An External Library --UI.lua
    UI = {}
   function UI: new()
    local Group = display.newGroup;

    local inventory_frames = display.newImage("inventorybox.png") ;
    Group :insert( inventory_frames) ;

    function inventory_framesDown()

      local tr_down = transition.to(inventory_frames,{time = 150,alpha = 0, x=0 ,y =8})

    end 


    return Group
    end
    return UI    

Now from my actual scene.lua (using storyboard API) from corona.

1.local ui= require"UI.lua" After that in my create scene function()(The reason I have not put it in a group scene because I want to make it disappear manually)

local UI2 = UI:new()

Then inside my exit scene function.I want to call the function inventory_framesDown() from inside UI:new().

function scene:exitScene(e)

invent = UI:new() inventory_framesDown() --this dose not work

storyboard.purgeScene("scene2");
storyboard.removeAll()


end

So How can I call a global function inside a global function from a external library? Thanks in advance:)

Bo Dash
  • 113
  • 1
  • 3
  • 10
  • After playing around a lot I have figure this out – Bo Dash Oct 01 '12 at 14:51
  • I see in your code `UI:function new()` . This is not valid Lua syntax. Did you mean `function UI:new()` ?. Asking a question about a code that does not even compile minimize the probability to have a good answer. – prapin Oct 01 '12 at 15:01
  • Thanks,yes I did,I have just fixed it.These are signs of Too much of staying awake;) – Bo Dash Oct 01 '12 at 15:15

1 Answers1

0

Basically ;

--An External Library --UI.lua


  UI = {}
    function UI:new()
    local Group = display.newGroup;

    local inventory_frames = display.newImage("inventorybox.png") ;
    Group :insert( inventory_frames) ;

    function Group: inventory_framesDown() -- I rewrite the code like this.

      local tr_down = transition.to(inventory_frames,{time = 150,alpha = 0, x=0 ,y =8})

    end 


return Group
end
return UI   

then In my Scene.lua after requiring the library. In Creat scene function() I write local UI2 = UI:new() same as before and then:

function scene:exitScene(e)

UI2.inventory_framesDown()  --This Works

storyboard.purgeScene("scene2");
storyboard.removeAll()


end

I am still a bit confused why dose this work?Since there so many ways to create classes and objects.If you have a better solution I love to know Thanks again.

Bo Dash
  • 113
  • 1
  • 3
  • 10