Help How to have a sticker system?

Hello again

sorry to make a 3rd post in one day. Thanks for the people that helped on the other two forums. Anyways my help is I need help having a sticker system. What I’m creating is an educational app. Everybody knows that little kids like stickers right?

So what I’m trying to do is when the person finished five math problems they can pick a sticker. They do this every time they finish five questions. How would I make it so that the stickers they picked stay and not disappear? Also randomize the sticker every time?

Thanks [import]uid: 17058 topic_id: 30509 reply_id: 330509[/import]

You need to save the app state between sessions. My tool of choice is a database, but you could also do the same thing by saving the data in a text file.

Big-Picture Steps

  1. When you start the app, load the saved stickers into a table. Now you can display those at will.
  2. When an achievement is reached, add the newly chose sticker to that table. Again, you can display them at will and now that new sticker will also be shown.
  3. When the app ends, save the data in that table to a text file or database.

When you save the sticker data you’re not saving the actual sticker, you’re saving an index into a sticker table. So you’d do something like this:

local allStickers = { "goodjob.png", "greattry.png", "whatakid.png", "waytogo.png" }

Now you can just reference those stickers with a single number, an index into that table. If a kid chose the first and fourth stickers, the data you save would be this:

1,4

Loaded into a table it would be:

local pickedStickers = {1, 4}

When you want to display those stickers on the screen you’d do something like this:

for x=1, #pickedStickers do  
 local idx = pickedStickers[x]  
 local sticker = display.newImage( allStickers[idx] )  
 sticker.x = blah  
 sticker.y = blah  
end  

Hopefully that will give you a shove in the right direction. If you need info on saving and loading data, the “Share Your Code” section on this site is a wonderful resource. And one utility that may be just what you need is Ice: http://developer.coronalabs.com/code/ice

Jay
[import]uid: 9440 topic_id: 30509 reply_id: 122246[/import]

I understand what you are saying. Thanks for giving a structure of how its really done.

But can you please brake it down a little more for how to save and load it using Ice. I dont use Ice in my games instead I use ego. With Ice I could not get the clear picture of how it works. I hope you can break it down.

Also another question when doing this

local pickedStickers = {1, 4}  

Does that load the stickers between 1 through 4? Even if the player only choose stickers 2 and 3 would that load those stickers as well? [import]uid: 17058 topic_id: 30509 reply_id: 122248[/import]

I don’t use Ice, I almost always use a database for saving and loading data, but I imagine if you play with the examples that show up with Ice you can figure it out. Or, there may be some other utility that saves and loads tables (I think CrawlspaceLib does that – you can Google it). I could create a little tutorial to do that but I’m already late on a game for which I’ve already been paid, so I can’t really afford to do more than pass on some tips here. :slight_smile:

local pickedStickers = {1, 4}

That doesn’t load anything, it’s just an example of two stickers that the user would have chosen. Sticker 1 and sticker 4.

If they reached the next level and choose the third sticker, you’d add that 3rd sticker to the table like this:

pickedStickers[#pickedStickers+1] = 3

You’re adding the value to the end of that table so now your table will be: 1,4,3

When you save the pickedStickers table it will save those three values and the later when the user comes back you should be able to load them up to see which stickers they’ve already chosen.

Jay [import]uid: 9440 topic_id: 30509 reply_id: 122249[/import]

You need to save the app state between sessions. My tool of choice is a database, but you could also do the same thing by saving the data in a text file.

Big-Picture Steps

  1. When you start the app, load the saved stickers into a table. Now you can display those at will.
  2. When an achievement is reached, add the newly chose sticker to that table. Again, you can display them at will and now that new sticker will also be shown.
  3. When the app ends, save the data in that table to a text file or database.

When you save the sticker data you’re not saving the actual sticker, you’re saving an index into a sticker table. So you’d do something like this:

local allStickers = { "goodjob.png", "greattry.png", "whatakid.png", "waytogo.png" }

Now you can just reference those stickers with a single number, an index into that table. If a kid chose the first and fourth stickers, the data you save would be this:

1,4

Loaded into a table it would be:

local pickedStickers = {1, 4}

When you want to display those stickers on the screen you’d do something like this:

for x=1, #pickedStickers do  
 local idx = pickedStickers[x]  
 local sticker = display.newImage( allStickers[idx] )  
 sticker.x = blah  
 sticker.y = blah  
end  

Hopefully that will give you a shove in the right direction. If you need info on saving and loading data, the “Share Your Code” section on this site is a wonderful resource. And one utility that may be just what you need is Ice: http://developer.coronalabs.com/code/ice

Jay
[import]uid: 9440 topic_id: 30509 reply_id: 122246[/import]

I understand what you are saying. Thanks for giving a structure of how its really done.

But can you please brake it down a little more for how to save and load it using Ice. I dont use Ice in my games instead I use ego. With Ice I could not get the clear picture of how it works. I hope you can break it down.

Also another question when doing this

local pickedStickers = {1, 4}  

Does that load the stickers between 1 through 4? Even if the player only choose stickers 2 and 3 would that load those stickers as well? [import]uid: 17058 topic_id: 30509 reply_id: 122248[/import]

I don’t use Ice, I almost always use a database for saving and loading data, but I imagine if you play with the examples that show up with Ice you can figure it out. Or, there may be some other utility that saves and loads tables (I think CrawlspaceLib does that – you can Google it). I could create a little tutorial to do that but I’m already late on a game for which I’ve already been paid, so I can’t really afford to do more than pass on some tips here. :slight_smile:

local pickedStickers = {1, 4}

That doesn’t load anything, it’s just an example of two stickers that the user would have chosen. Sticker 1 and sticker 4.

If they reached the next level and choose the third sticker, you’d add that 3rd sticker to the table like this:

pickedStickers[#pickedStickers+1] = 3

You’re adding the value to the end of that table so now your table will be: 1,4,3

When you save the pickedStickers table it will save those three values and the later when the user comes back you should be able to load them up to see which stickers they’ve already chosen.

Jay [import]uid: 9440 topic_id: 30509 reply_id: 122249[/import]