This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-07-30 01:16:08

shrey15
Scratcher
Registered: 2011-06-18
Posts: 13

Locking and Unlocking levels

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

 

#2 2012-07-30 04:32:55

SimplyMelee
Scratcher
Registered: 2012-01-14
Posts: 100+

Re: Locking and Unlocking levels

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
to
1
if
lock
= 1
if
level 2
touching
mouse-pointer
and
mouse-down?
broadcast
level 2

Last edited by SimplyMelee (2012-07-30 04:43:07)


http://oi48.tinypic.com/2czzjol.jpg

Offline

 

#3 2012-07-30 06:00:49

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Re: Locking and Unlocking levels

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
to
1
if
lock
= 1
if
level 2
touching
mouse-pointer
and
mouse-down?
broadcast
level 2

I fixed it for you  smile

when clicked
if
level
=
2
set
lock
to
1
if
level
=
1
if
touching
mouse-pointer
?
and
mouse down?
broadcast
level 2

Last edited by daniel_j (2012-07-30 06:01:34)


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

#4 2012-07-30 08:04:18

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Locking and Unlocking levels

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
to
1
if
lock
= 1
if
level 2
touching
mouse-pointer
and
mouse-down?
broadcast
level 2

I fixed it for you  smile

when clicked
if
level
=
2
set
lock
to
1
if
level
=
1
if
touching
mouse-pointer
?
and
mouse down?
broadcast
level 2

You forgot to add the forever loop:

when clicked
forever
if
level
=
2
set
lock
to
1
if
level
=
1
if
touching
mouse-pointer
?
and
mouse down?
broadcast
level 2


http://i46.tinypic.com/35ismmc.png

Offline

 

#5 2012-07-30 08:09:44

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Re: Locking and Unlocking levels

Woops  tongue


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

#6 2012-07-30 09:26:21

shrey15
Scratcher
Registered: 2011-06-18
Posts: 13

Re: Locking and Unlocking levels

So for every level except for level 1 I have to use this script?

Offline

 

#7 2012-07-30 09:35:44

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Re: Locking and Unlocking levels

Yes.


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

#8 2012-07-30 10:12:12

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Locking and Unlocking levels

daniel_j wrote:

Yes.

There are other ways. For example:

when clicked
set
level
to
0
set
lock
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
by
1

This is what you have on whether or not you can play a level:

if
touching
mouse pointer
?
and
mouse down?
if
lock
= 1
set
level
to
2
broadcast
Start level!

if
touching
mouse pointer
?
and
mouse down?
if
lock
= 2
nothing
else
set
level
to
2
broadcast
Start level!

if
touching
mouse pointer
?
and
mouse down?
if
lock
= 3
nothing
else
set
level
to
3
broadcast
Start level!

And this goes on until level 20.

Last edited by ErnieParke (2012-07-30 10:14:44)


http://i46.tinypic.com/35ismmc.png

Offline

 

#9 2012-07-30 10:47:42

shrey15
Scratcher
Registered: 2011-06-18
Posts: 13

Re: Locking and Unlocking levels

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
forever
if
level
is less than 2
hide
when I receive
Level Selection
if
level
is greater than 2
or
level
=2
show
forever
if
touching
mouse-pointer
?
and
mouse down?
broadcast
level 2

The variable level is set to one in level 1 and increases by one every level.

when I receive
level 1
set
level
to
1
when I receive
level 2
change
level
by
1
when I receive
level 3
change
level
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?

P.S. - I used the words greater than and less than in the scripts above because I couldn't use the signs < and >.

Offline

 

#10 2012-07-30 11:21:36

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Locking and Unlocking levels

Try adding an if into your script. For example:

when I receive
level 2
if
level
=
1
change
level
by
1
when I receive
level 3
if
level
=
2
change
level
by
1

Last edited by ErnieParke (2012-07-30 11:22:02)


http://i46.tinypic.com/35ismmc.png

Offline

 

#11 2012-07-30 11:57:37

shrey15
Scratcher
Registered: 2011-06-18
Posts: 13

Re: Locking and Unlocking levels

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 clicked
forever
wait until
touching
moving platform
?
set
attached to
to
moving platform
wait until
not
touching
moving platform
?
set
attached to
to
 
when clicked
set
attached to
to
 
forever
wait until
not
attached to
=
 
set
last x
to
x position
of
attached to
set
last y
to
y position
of
attached to
repeat until
attached to
=
 
go to x:
x position
+
x position
of
attached to
-
last x
y:
y position
+
y position
of
attached to
-
last y
set
last x
to
x position
of
attached to
set
last y
to
y position
of
attached to
wait
0.2
secs

Here 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?

Last edited by shrey15 (2012-07-30 12:30:53)

Offline

 

#12 2012-07-30 13:10:28

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Locking and Unlocking levels

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 clicked
forever
wait until
touching
moving platform
?
set
attached to
to
moving platform
wait until
not
touching
moving platform
?
set
attached to
to
 
when clicked
set
attached to
to
 
forever
wait until
not
attached to
=
 
set
last x
to
x position
of
attached to
set
last y
to
y position
of
attached to
repeat until
attached to
=
 
go to x:
x position
+
x position
of
attached to
-
last x
y:
y position
+
y position
of
attached to
-
last y
set
last x
to
x position
of
attached to
set
last y
to
y position
of
attached to
wait
0.2
secs

Here 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 clicked
forever
wait until
touching
moving platform
?
set
attached to
to
moving platform
wait until
not
touching
moving platform
?
set
attached to
to
0
when clicked
set
attached to
to
0
forever
if
not
attached to
=
0
set
last x
to
x position
of
attached to
set
last y
to
y position
of
attached to
repeat until
attached to
=
0
go to x:
x position
+
x position
of
attached to
-
last x
y:
y position
+
y position
of
attached to
-
last y
set
last x
to
x position
of
attached to
set
last y
to
y position
of
attached to
wait
0.2
secs

If 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)


http://i46.tinypic.com/35ismmc.png

Offline

 

#13 2012-07-30 13:33:23

shrey15
Scratcher
Registered: 2011-06-18
Posts: 13

Re: Locking and Unlocking levels

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

Offline

 

#14 2012-07-30 13:47:58

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Locking and Unlocking levels

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.


http://i46.tinypic.com/35ismmc.png

Offline

 

#15 2012-07-30 13:53:17

shrey15
Scratcher
Registered: 2011-06-18
Posts: 13

Re: Locking and Unlocking levels

Thanks for the help.

Offline

 

#16 2012-07-30 14:03:26

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Locking and Unlocking levels

shrey15 wrote:

Thanks for the help.

Your welcome.
De nado.

Last edited by ErnieParke (2012-07-30 14:05:01)


http://i46.tinypic.com/35ismmc.png

Offline

 

#17 2012-07-30 16:32:01

mwiedmann
New Scratcher
Registered: 2012-07-30
Posts: 12

Re: Locking and Unlocking levels

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

 

#18 2012-07-30 17:04:07

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Locking and Unlocking levels

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.


http://i46.tinypic.com/35ismmc.png

Offline

 

#19 2012-07-30 17:10:54

shrey15
Scratcher
Registered: 2011-06-18
Posts: 13

Re: Locking and Unlocking levels

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

 

#20 2012-07-30 17:13:55

shrey15
Scratcher
Registered: 2011-06-18
Posts: 13

Re: Locking and Unlocking levels

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

 

#21 2012-07-30 17:34:41

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Locking and Unlocking levels

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:  smile  Thanks!

Last edited by ErnieParke (2012-07-30 17:36:43)


http://i46.tinypic.com/35ismmc.png

Offline

 

#22 2012-07-30 17:37:16

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Locking and Unlocking levels

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:  smile  Thanks!

I just made my first smiley!


http://i46.tinypic.com/35ismmc.png

Offline

 

#23 2012-07-30 18:00:46

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Locking and Unlocking levels

You have to do

when I receive
level won
if
level
=
last unlocked level
change
last unlocked level
by
1
change
level
by
1
broadcast
play level

and then on the level selection sprites, you do

wheni receive
select level
if
level number of this sprite
>
last level unlocked
switch to costume
locked
else
switch to costume
unlocked
show
when i receive
play level
hide when a level is in progress
hide
when
level <whatever> button
clicked
if
costume #
=
whatever costume the "unlocked" costume is
set
level
to
level number of this sprite
broadcast
play level


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#24 2012-07-30 18:08:22

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Locking and Unlocking levels

63 sprites and 342 scripts!
I need to do some serious simplifying...


http://i46.tinypic.com/35ismmc.png

Offline

 

#25 2012-07-30 20:30:27

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Locking and Unlocking levels

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)


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer