_G Variable problem

Hi again ok I'm having a problem with global variable. I know people say stay away from it yeah I know but is there a way to control a global variable. Like unlocking levels using global var how do I control global var doing level unlock

why do you want to use globals to unlock levels? just save and load table
global vars will be useful just inside app, next run they will reset, no point in them

Can you show me how to check that someone beat that and then save it. All the levels are never locked there always unlocked.

I use ICE to achieve the same. Very easy ...

Its explained here http://developer.anscamobile.com/code/ice

can @mygamingproject you show me an example of using ice for checking that a level is won or anybody volunteer I get lots of help but somehow especially for how to save and I hope the last people that helped me don't get offended your help is awesome especially peach. I'm just asking other people If they have other alternatives way to do it.

In your game design what determines that a level should be unlocked?

An example of how it could work

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require( "ice" )
 
-- initialise your best score
 
scores = ice:loadBox( "scores" )
scores:storeIfNew( "best", 0 )
scores:save()
 
-- initialise your score to be used in game
myscore = scores:retrieve( "best" )
 
-- Then do a simple conditional to see if the score is big enough to make level available
 
if(myscore > 1000) then
 -- make level 1 available
end
if(myscore > 5000) then
 -- make level 2 available
end
 
-- Presumably you would have some local score being incremented
myscore = <do something here in your game to update score>
 
-- Later in your game update your score back to ice so its remembered on next load
scores:storeIfHigher("best", myscore)
scores:save()
views:1600 update:2012/1/15 11:04:51
corona forums © 2003-2011