I am creating a game which has a level selection page. It shows the level numbers from 1 to 20. I am wondering if it is possible to lock levels on the level selection page that the player hasn't reached yet. I was thinking of hiding the level numbers on the level selection page that the player didn't reach. And revealing the level numbers on the level selection page that the player has finished already. I really need help with the script for the locking and unlocking the level procedure.
Offline
Hello, you have quite a simple problem, the solution is to use variables to lock your levels. Make a variable called 'lock' for all the levels but level one and another called 'level'.
when you finish level 1, set level to '2' and program lock to unlock once level = 2
this is probably confusing so I'll visualise it.
if <(level) = 2> set [lock v] to (1) end if <(lock ) = 1> if [ level 2 v] touching [mouse-pointer v] and <mouse-down? > broadcast [level 2] end
Last edited by SimplyMelee (2012-07-30 04:43:07)
Offline
SimplyMelee wrote:
Hello, you have quite a simple problem, the solution is to use variables to lock your levels. Make a variable called 'lock' for all the levels but level one and another called 'level'.
when you finish level 1, set level to '2' and program lock to unlock once level = 2
this is probably confusing so I'll visualise it.if <(level) = 2> set [lock v] to (1) end if <(lock ) = 1> if [ level 2 v] touching [mouse-pointer v] and <mouse-down? > broadcast [level 2] end
I fixed it for you
when gf clicked if <(level) = [2]> set [lock v] to [1] end if <(level) = [1]> if <<touching [mouse-pointer v]?> and <mouse down?>> broadcast [level 2 v] end end
Last edited by daniel_j (2012-07-30 06:01:34)
Offline
daniel_j wrote:
SimplyMelee wrote:
Hello, you have quite a simple problem, the solution is to use variables to lock your levels. Make a variable called 'lock' for all the levels but level one and another called 'level'.
when you finish level 1, set level to '2' and program lock to unlock once level = 2
this is probably confusing so I'll visualise it.if <(level) = 2> set [lock v] to (1) end if <(lock ) = 1> if [ level 2 v] touching [mouse-pointer v] and <mouse-down? > broadcast [level 2] endI fixed it for you
when gf clicked if <(level) = [2]> set [lock v] to [1] end if <(level) = [1]> if <<touching [mouse-pointer v]?> and <mouse down?>> broadcast [level 2 v] end end
You forgot to add the forever loop:
when gf clicked forever if <(level) = [2]> set [lock v] to [1] end if <(level) = [1]> if <<touching [mouse-pointer v]?> and <mouse down?>> broadcast [level 2 v] end end
Offline
daniel_j wrote:
Yes.
There are other ways. For example:
when gf clicked set [level v] to (0) set [lock v] to (2)This is what you tag on to the end of the script that sees if the player beat the level or not.
if <<(beat level?) = true> and <(lock) = <(level) + (1)>>> change [lock v] by (1) endThis is what you have on whether or not you can play a level:
if <<touching [mouse pointer v]?> and <mouse down?>> if <(lock) = 1> set [level v] to (2) broadcast [Start level! v] end end
if <<touching [mouse pointer v]?> and <mouse down?>> if <(lock) = 2> nothing else set [level v] to (2) broadcast [Start level! v] end end
if <<touching [mouse pointer v]?> and <mouse down?>> if <(lock) = 3> nothing else set [level v] to (3) broadcast [Start level! v] end endAnd this goes on until level 20.
Last edited by ErnieParke (2012-07-30 10:14:44)
Offline
I was thinking of hiding the levels until they were unlocked. So using what you guys told me, I changed the script a little into:
when I receive [Level Selection v] forever if <(level) is less than 2> hide when I receive [Level Selection v] if <<(level) is greater than 2> or <(level)=2>> show forever if <<touching [mouse-pointer v]?> and <mouse down?>> broadcast [level 2 v]The variable level is set to one in level 1 and increases by one every level.
when I receive [level 1 v] set [level v] to [1] when I receive [level 2 v] change [level v] by [1] when I receive [level 3 v] change [level v] by [1]It worked when i tried playing the game. Now you can go back to level 2. But every time you go back to level 2, the variable level changes by 1. This means you can repeat level 2 many times and the value of level will be 15 or something allowing you to skip all levels and go directly to level 15. Is there any script I can use to allow the value of level to change by 1 only once on level 2?
Offline
Try adding an if into your script. For example:
when I receive [level 2 v] if <(level) = (1)> change [level v] by (1) end when I receive [level 3 v] if <(level) = (2)> change [level v] by (1) end
Last edited by ErnieParke (2012-07-30 11:22:02)
Offline
Thanks a lot. I didn't even think of that. That really helps. Now I understand what my script was missing. I have another question. I have the script for the moving platform (thanks to a person's scratch project). But when I move on the moving platform, I go through it. Can you help me with the script to be able to move around on a moving platform?
This is the script I currently have to be able to stand on a moving platform:
when gf clicked forever wait until <touching [moving platform v]?> set [attached to v] to [moving platform] wait until <not<touching [moving platform v]?>> set [attached to v] to [] when gf clicked set [attached to v] to [] forever wait until <not<(attached to)=[]>> set [last x v] to ([x position v] of (attached to)) set [last y v] to ([y position v] of (attached to)) repeat until <(attached to)=[]> go to x: ((x position)+(([x position v] of (attached to))-(last x))) y: ((y position)+(([y position v] of (attached to))-(last y))) set [last x v] to ([x position v] of (attached to)) set [last y v] to ([y position v] of (attached to)) end wait (0.2) secsHere is the website from which I got the script from: http://scratch.mit.edu/projects/JSO/1105685
Last edited by shrey15 (2012-07-30 12:30:53)
Offline
shrey15 wrote:
Thanks a lot. I didn't even think of that. That really helps. Now I understand what my script was missing. I have another question. I have the script for the moving platform (thanks to a person's scratch project). But when I move on the moving platform, I go through it. Can you help me with the script to be able to move around on a moving platform?
This is the script I currently have to be able to stand on a moving platform:when gf clicked forever wait until <touching [moving platform v]?> set [attached to v] to [moving platform] wait until <not<touching [moving platform v]?>> set [attached to v] to [] when gf clicked set [attached to v] to [] forever wait until <not<(attached to)=[]>> set [last x v] to ([x position v] of (attached to)) set [last y v] to ([y position v] of (attached to)) repeat until <(attached to)=[]> go to x: ((x position)+(([x position v] of (attached to))-(last x))) y: ((y position)+(([y position v] of (attached to))-(last y))) set [last x v] to ([x position v] of (attached to)) set [last y v] to ([y position v] of (attached to)) end wait (0.2) secsHere is the website from which I got the script from: http://scratch.mit.edu/projects/JSO/1105685
Can you tell me how to modify this so my character can also move while standing on the platform?
Try changing your script so that it looks like this:
when gf clicked forever wait until <touching [moving platform v]?> set [attached to v] to [moving platform] wait until <not<touching [moving platform v]?>> set [attached to v] to (0) when gf clicked set [attached to v] to (0) forever if<not<(attached to)=(0)>> set [last x v] to ([x position v] of (attached to)) set [last y v] to ([y position v] of (attached to)) repeat until <(attached to)=(0)> go to x: ((x position)+(([x position v] of (attached to))-(last x))) y: ((y position)+(([y position v] of (attached to))-(last y))) set [last x v] to ([x position v] of (attached to)) set [last y v] to ([y position v] of (attached to)) end wait (0.2) secs endIf your still having problems, tell me. Then I will look again at the script and try to fix it.
Last edited by ErnieParke (2012-07-30 13:20:31)
Offline
shrey15 wrote:
I tried but it still doesn't work. I just put my project online so you can download the scripts and see what's wrong.
Here is the link:
http://www.scratch.mit.edu/projects/shrey15/2704600
That should help a lot. Anyway, I'll look at your project, though not today due to the fact that I've used up all of my computer time, but maybe I'll get an extension. I'll upload an updated version of your project in up to two days from now.
Offline
shrey15 wrote:
Thanks for the help.
Your welcome.
De nado.
Last edited by ErnieParke (2012-07-30 14:05:01)
Offline
It sounds like you solved it, but on your level selection question I think your code might be simplified if you used a list to keep track of the locked status for each level.
Start by creating a list (levelList) and filling it with a 0 for each level except for the 1st level (since it will start unlocked). Add an extra 0 at the end so your last level can signal when it has been cleared as well. Each level now has a spot in the list to track its status.
When a level is completed, use "replace item (level+1) of levelList with 1". (level+1) will cause the next levels status to change to 1 in the list.
Now in you level selection screen, each level (which I assume is a sprite) will just have to check it's place in the list to see if it should show or not.
I like the list because you just have 1 data structure to track everything. You can also use numbers other than 0 and 1 to represent other statuses of the levels. Maybe the user completed the level but didn't get all the stars or whatever. The level is cleared but maybe you show it in Red because they didn't fully complete it. You would put a 2 in the list for that set.
Offline
mwiedmann wrote:
It sounds like you solved it, but on your level selection question I think your code might be simplified if you used a list to keep track of the locked status for each level.
Start by creating a list (levelList) and filling it with a 0 for each level except for the 1st level (since it will start unlocked). Add an extra 0 at the end so your last level can signal when it has been cleared as well. Each level now has a spot in the list to track its status.
When a level is completed, use "replace item (level+1) of levelList with 1". (level+1) will cause the next levels status to change to 1 in the list.
Now in you level selection screen, each level (which I assume is a sprite) will just have to check it's place in the list to see if it should show or not.
I like the list because you just have 1 data structure to track everything. You can also use numbers other than 0 and 1 to represent other statuses of the levels. Maybe the user completed the level but didn't get all the stars or whatever. The level is cleared but maybe you show it in Red because they didn't fully complete it. You would put a 2 in the list for that set.
You could just use one variable to tell what is the highest level unlocked. Other than that, I like your idea, but I don't think that Shrey15 will be implementing stars into his levels.
Offline
mwiedmann wrote:
It sounds like you solved it, but on your level selection question I think your code might be simplified if you used a list to keep track of the locked status for each level.
Start by creating a list (levelList) and filling it with a 0 for each level except for the 1st level (since it will start unlocked). Add an extra 0 at the end so your last level can signal when it has been cleared as well. Each level now has a spot in the list to track its status.
When a level is completed, use "replace item (level+1) of levelList with 1". (level+1) will cause the next levels status to change to 1 in the list.
Now in you level selection screen, each level (which I assume is a sprite) will just have to check it's place in the list to see if it should show or not.
I like the list because you just have 1 data structure to track everything. You can also use numbers other than 0 and 1 to represent other statuses of the levels. Maybe the user completed the level but didn't get all the stars or whatever. The level is cleared but maybe you show it in Red because they didn't fully complete it. You would put a 2 in the list for that set.
The stars sound like a good idea but I am not creating a game with score. You just need to get to the next level. I might create a game based on this one and I might use the stars idea. But thanks for trying.
Offline
ErnieParke wrote:
That should help a lot. Anyway, I'll look at your project, though not today due to the fact that I've used up all of my computer time, but maybe I'll get an extension. I'll upload an updated version of your project in up to two days from now.
When you upload the updated version, can you post the website to it?
Offline
shrey15 wrote:
ErnieParke wrote:
That should help a lot. Anyway, I'll look at your project, though not today due to the fact that I've used up all of my computer time, but maybe I'll get an extension. I'll upload an updated version of your project in up to two days from now.
When you upload the updated version, can you post the website to it?
Sure, I can. It shouldn't be too hard to do that. Just curious, do you know how to get a smiley into a comment? Kind of like this: Thanks!
Last edited by ErnieParke (2012-07-30 17:36:43)
Offline
ErnieParke wrote:
shrey15 wrote:
ErnieParke wrote:
That should help a lot. Anyway, I'll look at your project, though not today due to the fact that I've used up all of my computer time, but maybe I'll get an extension. I'll upload an updated version of your project in up to two days from now.
When you upload the updated version, can you post the website to it?
Sure, I can. It shouldn't be too hard to do that. Just curious, do you know how to get a smiley into a comment? Kind of like this: Thanks!
I just made my first smiley!
Offline
You have to do
when I receive [level won v] if <(level) = (last unlocked level)> change [last unlocked level v] by (1) change [level v] by (1) broadcast [play level v] endand then on the level selection sprites, you do
wheni receive [select level v] if <(level number of this sprite) > (last level unlocked)> switch to costume [locked v] else switch to costume [unlocked v] end show when i receive [play level v] //hide when a level is in progress hide when [level <whatever> button] clicked if <(costume #) = (whatever costume the "unlocked" costume is)> set [level v] to (level number of this sprite) broadcast [play level v]
Offline
63 sprites and 342 scripts!
I need to do some serious simplifying...
Offline
ErnieParke wrote:
63 sprites and 342 scripts!
I need to do some serious simplifying...
I luckily got some extra time, so I worked on your project. So far, I've done:
1). Removed 19 sprites.
2). Removed over 100 scripts.
3). Made it so that you can't jump through platforms.
4). Various bug fixes.
What I maybe will do tomorrow and maybe the next day:
1). Fix (squash) more bugs.
2). Simplify the game more.
If your wondering, I haven't fixed your glitch yet, but I'm working on it. So far, I don't know what's causing it, but I'm doing some tests and will hopefully have this fixed tomorrow. Right now, it's late, so I can't do anything more till after I sleep.
Last edited by ErnieParke (2012-07-30 20:31:08)
Offline