Save/Load - Lock/Unlock help

Here’s what i’m trying to accomplish…

On my level select menu, I want one level unlocked, and the rest to be locked.

Inside of my first level I have 3 object that need to be collected, and you have to hit a goal.
If you hit the goal the next level will unlock.

How can I go about accomplishing this the fastest and easiest way?

And the other thing would be, if all 3 objects are collected within that level, then a star will spawn over the level button, kind of like in Bubble Ball.

Please help me so I can finish up this app

Thanks! [import]uid: 42126 topic_id: 8743 reply_id: 308743[/import]

For saving and loading data, here is a level unlocked/locked tutorial and example; http://techority.com/2011/04/02/how-to-save-and-load-data-in-your-app/

You could do the stars in a similar fashion. [import]uid: 10144 topic_id: 8743 reply_id: 31884[/import]

That worked perfectly thank you nnow what about this.
I have a runtime event that moves an object:

local rotationDirection = 1
local _W = display.contentWidth / 2
local _H = display.contentHeight / 2

local function moveObject ( event )
if(object.x > _W - 100) then
object.x = object.x + 1 * rotationDirection
end

if(object.x >= _W + 100) then
rotationDirection = -1
elseif (object.x <= _W - 100) then
rotationDirection = 1
end
end

** I want to collide with the object and add 1 to the level count but when I try to remove the object or remove the runtime listener I get an error and the program crashes.

**Can someone help me with this?

local function collide1 ( event )
if event.phase == “began” then
print(“Collision 1 occuring”)
levelCount = levelCount + 1
Runtime:removeEventListener(“enterFrame”, moveObject)
object:removeSelf()
end
end

Runtime:addEventListener(“enterFrame”, moveObject)
[import]uid: 42126 topic_id: 8743 reply_id: 31911[/import]

How do you use that save / load onelock, twolock code to lock and unlock multiple levels?
[import]uid: 42126 topic_id: 8743 reply_id: 31932[/import]

The tutorial explains how to use it. It saves data to/loads data from a file you write.

For the removal of an object, it’s when you are trying to remove that is a problem - if an object has a reference to it remaining, is in transition, etc. it wont work.

If you don’t have any references to it further along then an easy fix is using a timer to remove it a split second after it’s done being used. [import]uid: 10144 topic_id: 8743 reply_id: 31935[/import]

Ok so I’ve read the info you’ve provided in the files that you recommended and I just want to know how to go from level 2 to a level 3. What do i need to do for that? [import]uid: 42126 topic_id: 8743 reply_id: 31939[/import]

See the references to leveltwo? Right after them add levelthree. It is the exact same. [import]uid: 10144 topic_id: 8743 reply_id: 31942[/import]

Ok I did that. Last thing would be on the menu when creating the rest of the buttons…

i have the seticontwo() function but when i want the seticonthree() function, do I use different global variables? like _G.threelock? Or what do i do?

You only have to explain once then i can apply that to the rest of them.

Thanks.

Sorry for being a nuisance [import]uid: 42126 topic_id: 8743 reply_id: 31950[/import]

Hey again, it’s fine :slight_smile:

You’re right in your question; you’d simply do _G.threelock rather than _G.twolock and seticonthree() rather than seticontwo().

It’s just repeating everything that level two has for every other level.

Let me know if you get it :slight_smile: [import]uid: 10144 topic_id: 8743 reply_id: 31972[/import]

In the saveit.lua file, do i need to change the file:write?

Something like this?

file:write( _G.onelock …", “… _G.twolock …”, "… _G.threelock) [import]uid: 42126 topic_id: 8743 reply_id: 31983[/import]

@peach: I didn’t realize you had already made a tutorial about this, cool now I probably won’t bother:
http://developer.anscamobile.com/forum/2011/01/21/show-user-level-has-been-completed#comment-29382 [import]uid: 12108 topic_id: 8743 reply_id: 31989[/import]

I figured the level unlock out. Now if I want to create the stars on the level buttons, how can I do that?

In each level.lua file, i have a local levelCount = 0, which increases by one every time I hit an object.
If the levelCount = 3, then in the levelMenu, I want to create a star on the the corresponding level button.

Should I use a global variable like _G.Total1. where:

if(levelCount == 3) then
_G.Total1 = levelCount
end

Or what would you suggest [import]uid: 42126 topic_id: 8743 reply_id: 31995[/import]

Hey jhocking - my apologies, I wasn’t aware that anyone else was planning one. Sorry if I stepped on your toes :frowning:

mdk5316, you worked out levels so you know how to save and load data now.

Add each levels stars - _G.levelonestars or the like.

Save these in the exact same was as you did with the levels, then load them the same way as well.

Rather than displaying an unlocked icon you will display a number of a stars. [import]uid: 10144 topic_id: 8743 reply_id: 31996[/import]

Im having trouble with wanting to play the level again and setting the best score. In the function resumeStart() where you are loading the data, is there anything I can do to save the highest score? If this works, then I will play around with it to try to find any bugs.

Thanks [import]uid: 42126 topic_id: 8743 reply_id: 31999[/import]

You might find this post helpful

Link: http://developer.anscamobile.com/forum/2011/01/21/show-user-level-has-been-completed

I tried to explained it as simple as possible, hopefully it helps you out.

But I do recommend PeachPellen Tutorials I found it helpful when I was very new
to programming. I have not seen her save/load tutorial (I already implemented
my own save/load to my game and it worked)but I would not doubt is as
good as other tutorials from her for you guys to get you going.

~Best of Luck from LeivaGames [import]uid: 30314 topic_id: 8743 reply_id: 32005[/import]

Save levelonehighscore or the like. Each time if the current level score is higher than levelonehighscore then you save that as the new highscore.

Beyond that I don’t know how else to explain it. Save values, replace values when needed, load values.

Kurosaki, thanks for the kind words - I’m sure your tutorial will be very helpful :slight_smile: [import]uid: 10144 topic_id: 8743 reply_id: 32098[/import]

Peach, thanks for all your work, you’re a true asset to this community.

I’m using this tutorial, but keep running into a problem and I wonder if anyone else is having this issue. Unlock for level 2 works great. I can usually get level 3 to work the first time also, but then I add level 4, or even change anything in level 3’s button / icon (even something simple like location), then reload the game, I get only a level 1 icon, no others, and even the level 1 icon doesn’t do anything.

So, I figured I did something wrong… I “undo” everything back to when it worked, and now even that state won’t work (same problem, only non-functional level 1) So I figured I must not be clearing the data file and that is hanging things up? Only problem is I don’t see the data file to clear it. The only way I can fix it so far, is to delete the project and start again.

Anyone else run into this? I hope it was clearly stated. I can supply code it needed.

Thanks all! I usually try everything I can think of before asking in a forum…

EDIT: deleting the ourdata.txt file in the project sandbox doesn’t seem to help! [import]uid: 18951 topic_id: 8743 reply_id: 34286[/import]

I haven’t run into issues unless I’ve not changed the code correctly; if using my example/tutorial try using CMD+F and searching for onelock (if you’re using my names) and make sure that your references to level three match up.

As in, if level one is referenced 8 times, is level 3?

As to the data issue (deleting the project to clear it) I change the file name when testing as it seems easiest. Whack a number on the end, or the like, is my advice :slight_smile:

I hope that helps.

Thanks for the kind words, too - had a long day and it’s always nice to be appreciated :slight_smile:

Peach [import]uid: 52491 topic_id: 8743 reply_id: 34364[/import]

Thanks Peach!

Your tip about renaming the data file did the trick!

Techority, by the way, is the best! I’ll gladly be donating (as soon as I have money :slight_smile: [import]uid: 18951 topic_id: 8743 reply_id: 34419[/import]

Thanks for the praise :slight_smile:

Donations are always appreciated but so are kind words; so don’t feel obligated as you’ve already given me the latter.

Peach :slight_smile: [import]uid: 52491 topic_id: 8743 reply_id: 34530[/import]