This site requires JavaScript, please enable it in your browser!
Greenfoot back
Doge
Doge wrote ...

2014/1/5

Don't know how to title this question...

Doge Doge

2014/1/5

#
So what I am trying to achieve is using a variable to do something. For example: If I want the setWorld to go to lvl7, and I have a variable that counts what level your on, how can I make this happen.
//So I will start by declaring a variable that has the number 7 attached to it

lvlNum = 7;

//Now I will declare an if statement:

if (EXAMPLE = true)
{
    Greenfoot.setWorld(new lvl...
}

//WHAT DO I DO ?
Zamoht Zamoht

2014/1/5

#
Do you have every level as a new class? If so you will have to hardcode the levelchange.
        int level = 7;
        switch(level) {
            case 1:
            Greenfoot.setWorld(new lvl1());
            break;
            case 2:
            Greenfoot.setWorld(new lvl2());
            break;
            //and so on
        }
Doge Doge

2014/1/5

#
Oh that is a much better approach. Thanks man.
You need to login to post a reply.