Storyboard API Questions

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.lualocal t = {}print( "Module is loaded." )function t.hello() print( "Hello world" )endreturn t[/code]main.lualocal a = require "module_a"-- OUTPUT: "Module is loaded."local a_again = require "module_a"-- OUTPUT: ((nothing))a, a_again = nil, nilpackage.loaded["module_a"] = nillocal 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. [import]uid: 52430 topic_id: 17828 reply_id: 108326[/import]

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 [import]uid: 74667 topic_id: 17828 reply_id: 120949[/import]

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

[import]uid: 13784 topic_id: 17828 reply_id: 120951[/import]

Hi @potsifera ,

Just an idea: what would happen if you let this for loop under [lua]scene:createScene()[/lua] 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. [import]uid: 89165 topic_id: 17828 reply_id: 120952[/import]

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! [import]uid: 74667 topic_id: 17828 reply_id: 121494[/import]

@potsifera

Glad to help!
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 17828 reply_id: 121512[/import]

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 [import]uid: 74667 topic_id: 17828 reply_id: 120949[/import]

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

[import]uid: 13784 topic_id: 17828 reply_id: 120951[/import]

Hi @potsifera ,

Just an idea: what would happen if you let this for loop under [lua]scene:createScene()[/lua] 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. [import]uid: 89165 topic_id: 17828 reply_id: 120952[/import]

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! [import]uid: 74667 topic_id: 17828 reply_id: 121494[/import]

@potsifera

Glad to help!
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 17828 reply_id: 121512[/import]

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.

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.

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

Thank you.

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

Thank you.