Hi Ok my problem is I’m trying to save level when there beaten. Like example you can on level the game in bubble ball, and you know how in that game it checks that you beat that level that it places a star telling that you beat it and also stores it. So How would I do that example? [import]uid: 17058 topic_id: 20312 reply_id: 320312[/import]
Assuming you are still using Ego and requiring it in main.lua as in the example I sent you last night, like so;
[lua]ego = require “ego”
saveFile = ego.saveFile
loadFile = ego.loadFile[/lua]
You would then put this at the start of your first screen after main, so that if it was the first time a user played the file would be created and set the current level as “1”.
[lua]local function checkForFile ()
currentLevel = loadFile (“currentLevel.txt”)
if currentLevel == “empty” then
currentLevel = 1
saveFile(“currentLevel.txt”, currentLevel)
end
end
checkForFile()[/lua]
This would mean level 1 was unlocked.
You would add your level icons and check whether or not currentLevel > the level icon you are setting.
Here is an example for 5 levels using director spawned in a loop;
[lua]–Table for levels
local level = {}
–Function for open levels
local function goLevel (event)
director:changeScene(event.target.scene)
end
local startX = 45
–Load level icons accordingly
local function setupLevels()
for i = 1, 6 do
if tonumber(currentLevel) >= i then
level[i] = display.newCircle( startX*i, 50, 20 )
level[i]:setFillColor(220, 220, 120)
localGroup:insert( level[i] )
level[i].scene = “level”…i…""
level[i]:addEventListener(“tap”, goLevel)
elseif tonumber(currentLevel) < i then
level[i] = display.newCircle( startX*i, 50, 20 )
level[i]:setFillColor(255, 255, 255)
localGroup:insert( level[i] )
end
end
end
setupLevels()[/lua]
This is plug and play. Yellow means unlocked, white means locked.
If you clicked on yellow it would go to level1.lua, if you clicked on white it would do nothing because it is still locked.
To unlocked level2 on completion of level1, you’d do this;
[lua]local function checkWin ()
if tonumber(currentLevel) < 2 then
saveFile(“currentLevel.txt”, 2)
end
end[/lua]
There you check if the level unlocked is less than 2. Currently it would be 1. So level 2 is then unlocked and that is saved.
Now if you went back to the level select screen two levels would be unlocked rather than 1.
Peach
[import]uid: 52491 topic_id: 20312 reply_id: 79363[/import]
hey peach this great, just one thing how can I control each circle instead of placing them next to each other like example. I place level 1 circle on one corner of the screen, then I place level 2 circle on the other corner of the screen etc… How do I do that example is what I mean [import]uid: 17058 topic_id: 20312 reply_id: 79400[/import]
Well my code spawns them in a loop that just changes the x and y.
So you could have an table holding the X and Y for each, eg;
[lua]iconPos = {}
iconPos[1] = {x=50, y=100}
iconPos[2] = {x=100, y=100}
iconPos[3] = {x=150, y=100}
iconPos[4] = {x=200, y=100}
iconPos[5] = {x=250, y=100}[/lua]
That’s just an example - but then in the loop to spawn them do;
level[i].x, level[i].y = iconPos[i].x, iconPos[i].y
That would go on lines 16 and 22 in the middle block of code I shared.
The iconPos stuff would go above that of course.
Peach
[import]uid: 52491 topic_id: 20312 reply_id: 79407[/import]
@peach basically what I’m trying to say is you know how I want my icon to be position anywhere. My problem is when you said put
level[i].x, level[i].y = iconPos[i].x, iconPos[i].y
on lines 16 and 22 between. I get an error when I put it on lines 22 which I say to myself it don’t make sense. Can you help me again please
I appreciate thanks
[import]uid: 17058 topic_id: 20312 reply_id: 79944[/import]
@peach pellen ok I understood my mistake you where right. So thanks for helping, I was busy for the past couple days so I just tested it finally today now I’m off to create my game and get some code done
[import]uid: 17058 topic_id: 20312 reply_id: 79946[/import]
OooOoOOOOooOOOoOOO.
Peach is FTW.
That’s all I can say about that.
ng [import]uid: 61600 topic_id: 20312 reply_id: 79961[/import]
@sebitttas - Well done on solving the problem.
@Nick - Thanks Nick 
Peach [import]uid: 52491 topic_id: 20312 reply_id: 79979[/import]
Hey Peach, could you provide an example of how you would place levels inside of Chapters. Basically, each level would be unlocked just as you’ve described above. But, when you finish a set of levels, you can unlock a whole new chapter levels…
-Steve [import]uid: 131412 topic_id: 20312 reply_id: 101133[/import]
@stevenanthony99 I can help you with that [import]uid: 17058 topic_id: 20312 reply_id: 101141[/import]
Thanks Seb, I was tinkering around with the code and I believe I got it working. I’ve laid out three volumes, each with 20 levels. Following the code from Peaches ego example, i set the levels.lua files to handle the first levels. Then I created 2 more called levels21_to_40.lua and 41_to_60.lua. I also created a volumes.lua with the accompanying volume lua files. In the checkForFile() functions in the levels21_to_40.lua and the levels41_to_60.lua files, I had to change it from if currentFile == “empty” to if currentFile == “20”, for the 21_to_40, and “40” for the 41_to_60.
It took me all dang day, but, if you know of a more efficient way of doing so, please, I beg of you…help…me ;D
-Steve [import]uid: 131412 topic_id: 20312 reply_id: 101145[/import]
Although…what would really be helpful is if you knew how to dynamically create level numbers to overlay the icons…
oy [import]uid: 131412 topic_id: 20312 reply_id: 101146[/import]
so what you want is the number icon on a level select to change when the person beats that level right. Also when the person beat like a whole chapter containing example 20 levels they unlock another chapter with 20 levels is that right? [import]uid: 17058 topic_id: 20312 reply_id: 101149[/import]
@stevenanthony99 I know an efficient way of doing it is simple and easy to understand just reply to my comment #12 to see if what I said is what you want so I can make it for you [import]uid: 17058 topic_id: 20312 reply_id: 101152[/import]
Not exactly, in volume 1, all 20 levels will me displayed, that way if someone wants to go back and play a certain level they can…right now it looks somewhat like this…
[] [] [] [] []
[] [] [] [] []
[] [] [] [] []
[] [] [] [] []
what I want it to look like is this…
[1] [2] [3] [4] [5]
[6] [7] [8] [9] [10]…and so on until level 20…
So instead of creating a separate icon for all 20, I have 1 icon with some text overlaid, 1-20
The 2nd part is right, when they beat level 20 in chapter 1, they unlock 20 more levels in chapter 2…
You know, for a minute there, I was like, yeah buddy, I got this…I can create levels really easy. It’s all this back-end stuff that requires work!
Sheesh!
[import]uid: 131412 topic_id: 20312 reply_id: 101153[/import]
me = be* [import]uid: 131412 topic_id: 20312 reply_id: 101154[/import]
ok to clear this up you want a number displayed in front the of the icon for all twenty levels right? If that what you want i will give you an example
[import]uid: 17058 topic_id: 20312 reply_id: 101155[/import]
Yes definitely!
I got it working for the first volume…I set up a table like so…
local text = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}
then in the for loop that reiterated the display icons, I wrote…
text[i] = display.newText(text[i], 0,0,nil,24)
text[i]:scale(0.5,0.5)
text[i]:setTextColor(0,0,0)
text[i].x, text[i].y = iconPos[i].x, iconPos[i].y
localGroup:insert( text[i] )
and it works great on this…but…for levels21_to_40, I’m getting an error…console is saying it expected a string and got nil. I turned all of the numbers into strings, but the same error is popping up… [import]uid: 131412 topic_id: 20312 reply_id: 101157[/import]
@stevenanthony99 can you provide me your email so when I’m done I can email it to [import]uid: 17058 topic_id: 20312 reply_id: 101158[/import]