System "applicationStart" event

Somebody asked this question in the comments of a blog post, but there was no answer. Not a big deal, but what is the difference between catching this event and calling your startup code, and just calling your startup code in your main function in main.lua? [import]uid: 58455 topic_id: 27223 reply_id: 327223[/import]

@davemikesell
“applicationStart” occurs when the application is launched and all code in main.lua is executed.

that’s different~ (priority)
[import]uid: 25057 topic_id: 27223 reply_id: 110631[/import]

OK, so calling your startup code as the last thing you do in main.lua would be equivalent, no? [import]uid: 58455 topic_id: 27223 reply_id: 110657[/import]

There is a difference :slight_smile:

Every time your application starts that event is fired, be it the initial startup, resuming from suspended state etc.

Your main.lua only does this the one time [import]uid: 84637 topic_id: 27223 reply_id: 110703[/import]

When resuming, are both applicationStart and applicationResume fired? [import]uid: 58455 topic_id: 27223 reply_id: 110710[/import]

There is no overlap between applicationStart and applicationResume. The code in main.lua is run when the application first starts and then applicationStart event is fired. When the main.lua code is executed the Lua engine is initializing so not all services are up and running. applicationStart occurs after the initialization process and the main.lua code has executed.

The proper way to architect your code would be to define variables and functions in main.lua and call any code that needs to execute in the applicationStart event. applicationResume is only called if your app is restarted after it has been suspended. None of the main.lua code is executed when the application is resume (unless the application was suspended while the main.lua code was running). [import]uid: 7559 topic_id: 27223 reply_id: 110714[/import]