[LVL SELECT] Problems

Bacon

  • Posts: 20
Hey everyone, ive got a question...again...yeah i know im a noobie. STFU!

The question is, how do i make it so that when you complete a level, it unlocks in the LEVEL SELECT SCREEN? That is the only part that is blocking me from finishing my game and i really want to get done with it....please help?

Example; Just completed level 15, level 15 was blocked in the LVLSELECT SCREEN, now that ive finished it, it is unlocked! Yay!

AnswersNeeded

  • Posts: 13
lawl same problem here  :-\

coleislazy

  • *
  • Posts: 2607
Make a game attribute which is a list. Each item in the list will represent a level, so item 1 is level 1 (lists actually start at 0, but it will be simpler if you ignore that one). When you complete a level, use the block "replace item __ with __ in list __" to set the level number with a value of "Unocked" (or whatever you want, in your game attribute list. It will look like this:
Code: [Select]
[replace item (1) with (Unlocked) in list [MyGameAttributeList]]
Then, in your level select screen. For each level, check if the corresponding item in the list is unlocked  or not by using a block like this:
Code: [Select]
if<[get item #(1) from list [MyGameAttributeList]] = (Unlocked)>

Bacon

  • Posts: 20
Mhm...confusing  :-\ Is there any tutorials around?

kuroi

  • Posts: 110
Hi,
I have a problem with 'unlocking' levels as well

@coleislazy or anyone
I have created a level select scene and it works well.
I have also a created list...
However, I do not know where I should put (into which boxes?)
Code: [Select]
[replace item (1) with (Unlocked) in list [MyGameAttributeList]] and
Code: [Select]
if<[get item #(1) from list [MyGameAttributeList]] = (Unlocked)>
Is there any possiblility to give a visual representation? (a screen would be helpful)
I can also give screens of my "code" if it is helpful.
Thank you in advance

coleislazy

  • *
  • Posts: 2607
Here is an example with blocks. I created two custom blocks to make things easier, but you could apply the same logic anywhere.

The "Unlock level" block just takes the level number you want to unlock and sets the index of that number in the list to "Unlocked". So, if you were to unlock 1 and 3, your list would look like this (lists actually start at 0, but we can ignore that for our purposes):
  • Unlocked
  • Unlocked
The other block checks to see if a level is locked. All it does is take what is in the index of the number of the level your checking in the list and checks to see if it has any value. If it does, it returns true, false if it doesn't. So, 1 and 3 in the above example would return true, while everything else would return false.

If you wanted to re-lock a level, you would replace the item in the list with nothing (e.g. type nothing in the box, not even a space).

I've also attached the image containing the behavior (the hammer) so you can import it into SW directly, if you want, by dragging the image into SW. If it doesn't work, try saving the image to your computer first, then dragging it in.

If you have any more questions, please let me know!

kuroi

  • Posts: 110
Hi,
Thanks for the reply
I've got 2 problems:
I cannot import your behaviour (but I can create the boxes on my own)
But I have a problem with the list, you said that I should do something like:
Quote
1.Unlocked
2.
3.Unlocked
but I cannot leave the list item without a text (SW wont let me click OK if I leave the value blank), or I am doing something wrong here  :o

coleislazy

  • *
  • Posts: 2607
Ah, I'm sorry I was unclear on that. You should not add anything yourself to the list. It will all be changed via the behavior. I was just trying to illustrate an example of what it would look like "behind-the-scenes" if you unlocked levels 1 and 3 using the behavior.

kuroi

  • Posts: 110
Thanks for the reply
I have created the blosck but I get 2 errors (chcek the screen, please)
and here is my code:
Code: [Select]
package scripts
{
import flash.display.BlendMode;
import flash.events.*;
import flash.net.*;
import flash.filters.*;

import Box2DAS.Collision.*;
import Box2DAS.Collision.Shapes.*;
import Box2DAS.Common.*;
import Box2DAS.Dynamics.*;
import Box2DAS.Dynamics.Contacts.*;
import Box2DAS.Dynamics.Joints.*;

import stencyl.api.data.*;
import stencyl.api.engine.*;
import stencyl.api.engine.actor.*;
import stencyl.api.engine.behavior.*;
import stencyl.api.engine.bg.*;
import stencyl.api.engine.font.*;
import stencyl.api.engine.scene.*;
import stencyl.api.engine.sound.*;
import stencyl.api.engine.tile.*;
import stencyl.api.engine.utils.*;

import org.flixel.*;
import mochi.as3.*;
import flash.ui.Mouse;



public dynamic class Design_16_16_lvlslct extends SceneScript
{
override public function init():void
{}
override public function update():void
{
}
override public function draw(g:Graphics, x:Number, y:Number):void
{
}
/* Params are:__LevelNumber */
public function l1(__LevelNumber:Number):void
{
    (getGameAttribute("Level List") as Array)[__LevelNumber] = "Unlocked";
}
/* Params are:__LevelNumber */
public function lv2(__LevelNumber:Number):void
{

    if (Boolean((getGameAttribute("Level List") as Array)[__LevelNumber]))
    {
        return true;
    }

    else
    {
        return false;
    }
}

public function Design_16_16_lvlslct(ignore:*, scene:GameState)
{
super(scene);

}

override public function forwardMessage(msg:String):void
{

}
}
}

I am not sure what is wrong there O_O

coleislazy

  • *
  • Posts: 2607
Ah, when you create the custom block for "Is level __ unlocked?", you need to set the return type to "Boolean" at the bottom of the window. Right now, its set as an action (no return type).

kuroi

  • Posts: 110
Thanks I fixed this :)

but when I put the behaviour to the level select scene nothing happens xD
I still can select all my levels

What should I do to find what I have done wrong?
Is there something that I should do with the list? or add something to the lvl?
Should I name levels somehow?
sorry for asking such silly questions ;/

coleislazy

  • *
  • Posts: 2607
You would probably want to have actors acting as buttons for each level. Create a behavior for these actors which will check if a certain level is unlocked, and if it is, switch to that scene when it is clicked. Create a number attribute and a scene attribute in this behavior to act as the level to check and the scene to switch to so you can use the same behavior for each button by customizing those attributes.

coleislazy

  • *
  • Posts: 2607
Ok, so I've been asked a few more questions related to this, so I'm going to post them here in case anyone else has the same questions.

First, the two green blocks in my screenshot are just what the custom blocks will look like when you place them in your logic. They aren't part of the behavior, and, in fact, anything not attached to a wrapper will be ignored anyway.

There is an excellent article about how to build custom blocks here that should answer question related to those: http://www.stencyl.com/help/viewArticle/106

Even though the "if" block normally requires a Boolean attribute or block (the ones with the pointed edges), you can actually drop other types of attributes in and it will convert it to the appropriate type automatically. This works with other attributes as well, and is quite common (e.g. converting a Number to a String to display the game score). The reason it works in this particular case is because of the way a value gets converted to a Boolean. If there is no value or it is null, 0, or less than 0, it will convert to "false". If it is a number greater than 0 or any text or any kind of valid object, it will convert to "true". In our case, it will be blank if the level is not unlocked, so it will evaluate to "false". Once we change the value to "unlocked", it will have some text and so evaluate to "true".

I hope I've cleared some things up, rather than made them more complicated!

slmmation

  • Posts: 4
ok so I think I've made some progress: In order for my levels to be completed, the player needs to collide with a specific actor (actor X). How would I set it up so that when the player collides with actor X (thus ending the level) the next level becomes unlocked?

In addition to this, do I attach this behavior to each of the levels that need unlocking or the scene that has a list of all of the levels in the game?

« Last Edit: December 24, 2011, 02:12:15 pm by slmmation »

coleislazy

  • *
  • Posts: 2607
It would be very simple. In the behavior your have now which switches to the next level, you simply need to insert the custom block to unlock the next level number right before the block which switches scenes. You would also make sure you attached the behavior containing that custom block to the current scene so it can be used.

You'll have to tell it which level number you want to unlock, as well. Since the behaviors you are using are probably not specific to one level, but get reused, it would make the most sense to make this a Number attribute and drop it into the custom block. You would create this attribute in the behavior which controls the scene switching, just remember to give it a value on the behaviors configuration page in the scene/actor it is attached to!

To answer your last question, you would attach this behavior to each scene that will unlock another scene. You would also attach this to a scene which needs to check if a level is unlocked (such as a menu).