Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Storyboard API Questions
Started by jonathanbeebe Nov 16 2011 06:37 AM

- - - - -
207 replies to this topic
[TOPIC CONTROLS]
« Page 9 of 9 7 8 9
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#201

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

Here's how Lua's require() function works, which should help you understand how modules such as storyboard work internally, and will hopefully answer your questions.

When you call require() in Lua, the global package.loaded table will be searched for the module you requested. If it cannot be found (e.g. it was never previously loaded), then the actual file will be loaded instead.

If the module is found in package.loaded, however, then the already-loaded module from the global package.loaded table will be returned instead.

So if you're calling:


local storyboard = require "storyboard"
[/code]

At the top of several files. As long as you never did this:


package.loaded["storyboard"] = nil
[/code]

(which you probably didn't do)

Then the module was only actually loaded the first time you called require(), and any subsequent times is simply creating a local reference to the already-loaded table (which existed in package.loaded).

@robmiracle: You nailed it. :-)

-----------------------

For additional explanation, you can do the following to get a better understanding of how the module system works in Lua.

module_a.lua

local t = {}

print( "Module is loaded." )

function t.hello()
print( "Hello world" )
end

return t
[/code]


main.lua


local a = require "module_a"
-- OUTPUT: "Module is loaded."

local a_again = require "module_a"
-- OUTPUT: ((nothing))

a, a_again = nil, nil
package.loaded[ "module_a" ] = nil

local a_again = require "module_a"
-- OUTPUT: "Module is loaded."

a_again.hello()
-- OUTPUT: "Hello world"
[/code]


Notice how the second time we called: require "module_a", we got nothing in the terminal? That's because the module was already loaded, so we simply got a reference to the table (returned in module_a.lua) that existed in the global package.loaded table.

Once we unloaded the module from package.loaded by setting it to nil, then the next time we called require() on the module, we got the print statement again.
uid: 52430 topic_id: 17828 reply_id: 108326


[TOPIC: post.html]
#202

potsifera

[GLOBAL: userInfoPane.html]
potsifera
  • Enthusiast

  • 51 posts
  • Corona SDK

hi guys,

Is there any way to stop an active "for loop" when exiting a scene?

My problem is that I am sending requests to the facebook api using a for loop to check which facebook friends have installed my app.

function scene:enterScene( event ){
for k, v in pairs(data) do  
facebook.request(data[k].id, "GET", { fields="installed"})
end
}

But if I change scenes before the loop has finished talking to facebook, my app crashes as the "for loop" continues running after I change scenes generating this error message is: bad argument #1 to 'ipairs' (table expected, got nil)

any ideas would be appreciated, thanks
uid: 74667 topic_id: 17828 reply_id: 120949


[TOPIC: post.html]
#203

marble68

[GLOBAL: userInfoPane.html]
marble68
  • Contributor

  • 170 posts
  • Corona SDK

Hi potsifera

Moving your Facebook request outside the scope of the enterScene event to it's own scope should solve this. Then, you can gracefully terminate it it on the exitScene event.

HTH

uid: 13784 topic_id: 17828 reply_id: 120951


[TOPIC: post.html]
#204

@RSCdev

[GLOBAL: userInfoPane.html]
@RSCdev
  • Corona Geek

  • 1,489 posts
  • Corona SDK

Hi @potsifera,

Just an idea: what would happen if you let this for loop under
scene:createScene()
instead of the enterScene and also not "purging" the scene that has the for loop (until you are sure that the loop has finished at least - setting a flag into it for example). Would it broken your project as well or cause you unexpected results anyway?
Cheers,
Rodrigo.
uid: 89165 topic_id: 17828 reply_id: 120952


[TOPIC: post.html]
#205

potsifera

[GLOBAL: userInfoPane.html]
potsifera
  • Enthusiast

  • 51 posts
  • Corona SDK

thanks for the ideas @marble68 and @RSCdev, after 3 days trying to come up with a solution I ended creating a new file where I make all my facebook calls and when they are finished I transfer the results to scenes requiring the info, that way I don't have to deal with the incomplete facebook.requests() breaking up my code
cheers!
uid: 74667 topic_id: 17828 reply_id: 121494


[TOPIC: post.html]
#206

@RSCdev

[GLOBAL: userInfoPane.html]
@RSCdev
  • Corona Geek

  • 1,489 posts
  • Corona SDK

@potsifera

Glad to help!
Cheers,
Rodrigo.
uid: 89165 topic_id: 17828 reply_id: 121512


[TOPIC: post.html]
#207

jeremy75

[GLOBAL: userInfoPane.html]
jeremy75
  • Enthusiast

  • 45 posts
  • Corona SDK

Just to put in my view on this info.

 

Please dont put important information in blogs. I do not look at developer blogs as they are almost impossible to search for specifics.

This applies to many developer blogs on many technologies. They are listed and filed by date alone.

They make it easy to post information but not really easy to find anything.... creator focused not user focused.

 

Please simply update the docs and tutorials as that is the recognised documentation.

 

Thanks.



[TOPIC: post.html]
#208

Corona Esta Tecnologia

[GLOBAL: userInfoPane.html]
Corona Esta Tecnologia
  • Observer

  • 19 posts
  • Corona SDK

Dear @Luciane and @Bladko, how about page curl with Storyboard ?

 

Thank you.




[topic_controls]
« Page 9 of 9 7 8 9
 
[/topic_controls]