Storyboard and tables

Hi there,

Sorry if this is a simple question. I am creating an app based on a storyboard (3 or 4 tabs). I want to create a table that will store product information that will be accessed in every scene (tab 1 - add product, tab 2 - list products, tab 3 orders based of these products, tab 4 - submit). What is the best way to achieve this? At the moment I am thinking that I could either go global (which I feel is poor practice), attach is as a storyboard table (storyboard.products = {}) - I was wondering if this is good practice as I am likely to store quite a bit of information about each product, or use a sqLite DB?

Thanks in advance.

Craig

[import]uid: 184705 topic_id: 33994 reply_id: 333994[/import]

Hi Craig,
This is a simple question, but a very good question! Global is definitely not a “great” approach and should be avoided if possible (however, it’s not as awful as some claim it is).

If you have a huge number of products, I suggest you create an SQLite database because it’s easy to manage the data within, and it sounds like you’re going to be changing/updating that data often. However, if you will have a reasonable amount of products (less than 100) and each product won’t have a VAST amount of sub-properties, I personally think it’s easier to just set up a nicely-organized Lua table/subtables and pass it as a Storyboard table. I guess it depends on how complex your products table will be.

Best regards,
Brent

[import]uid: 200026 topic_id: 33994 reply_id: 135141[/import]

Let me give you an alternate thought to this.

At the end of the day, the “storyboard” object is just a big table and you can add things to it. So say your data table is called “myData” you can do:

storyboard.myData = myData  

Then from any storyboard scene you can access your data like:

 myValue = storyboard.myData.someValueInTheTable  

It’s kinda like global without being global! See this blog post:

http://www.coronalabs.com/blog/2012/08/07/managing-state-between-scenes/
[import]uid: 199310 topic_id: 33994 reply_id: 135196[/import]

Hi Craig,
This is a simple question, but a very good question! Global is definitely not a “great” approach and should be avoided if possible (however, it’s not as awful as some claim it is).

If you have a huge number of products, I suggest you create an SQLite database because it’s easy to manage the data within, and it sounds like you’re going to be changing/updating that data often. However, if you will have a reasonable amount of products (less than 100) and each product won’t have a VAST amount of sub-properties, I personally think it’s easier to just set up a nicely-organized Lua table/subtables and pass it as a Storyboard table. I guess it depends on how complex your products table will be.

Best regards,
Brent

[import]uid: 200026 topic_id: 33994 reply_id: 135141[/import]

Let me give you an alternate thought to this.

At the end of the day, the “storyboard” object is just a big table and you can add things to it. So say your data table is called “myData” you can do:

storyboard.myData = myData  

Then from any storyboard scene you can access your data like:

 myValue = storyboard.myData.someValueInTheTable  

It’s kinda like global without being global! See this blog post:

http://www.coronalabs.com/blog/2012/08/07/managing-state-between-scenes/
[import]uid: 199310 topic_id: 33994 reply_id: 135196[/import]