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

2017/10/7

Map switching

Sweatleek Sweatleek

2017/10/7

#
Hello :) I'm try to make a system that switchs the map wen you hit a object, So my that was to make a system that counts up and than look with a IF stament witch map it needs to switch to. but the porblem is besacly it gose to it orgnal value Kind greatings, Sander
public void act() 
    {
        Nextmap();
    }  

 private void Nextmap(){
        int x;
        if(isTouching(Fish.class)){
        if(c==1){Greenfoot.setWorld(new Map1());}  
        if(c==2){Greenfoot.setWorld(new Map2());}
        if(c==3){Greenfoot.setWorld(new Map3());}
        x++;
        }
    }
danpost danpost

2017/10/7

#
Two strange things I see, (a) 'x', or lines 7 and 12, has no influence at all; (b) nowhere is 'c' shown to change values.
Sweatleek Sweatleek

2017/10/7

#
danpost wrote...
Two strange things I see, (a) 'x', or lines 7 and 12, has no influence at all; (b) nowhere is 'c' shown to change values.
Ye sorry was try some stuff but it supposed to be (x;) every ware. Im becasly trying to make a counting system that can hold a value. in Nextmap(){
Super_Hippo Super_Hippo

2017/10/8

#
Right now, you create x in the Nextmap method, so it will be gone when the method is finished. Next time the method is executed, a new x is created and so on. The question is what the condition for the different maps should be.
danpost danpost

2017/10/8

#
Probably just need to move line 7 to line 5.
Sweatleek Sweatleek

2017/10/8

#
Super_Hippo wrote...
Right now, you create x in the Nextmap method, so it will be gone when the method is finished. Next time the method is executed, a new x is created and so on. The question is what the condition for the different maps should be.
It's bescaly a counting system so every time a object is hit it will add 1 and than looks truw the if staments to look for new map. So Map 1= value 1 map 2= value 2 map 3= value 3 ect
danpost wrote...
Probably just need to move line 7 to line 5.
This dasn't work sadly it still louds map 1 every time (thats also the stating map)
danpost danpost

2017/10/8

#
Sweatleek wrote...
danpost wrote...
Probably just need to move line 7 to line 5.
This dasn't work sadly it still louds map 1 every time (thats also the stating map)
Make the 'int x' field static (as well as moving the line):
static int x;
Sweatleek Sweatleek

2017/10/8

#
danpost wrote...
Sweatleek wrote...
danpost wrote...
Probably just need to move line 7 to line 5.
This dasn't work sadly it still louds map 1 every time (thats also the stating map)
Make the 'int x' field static (as well as moving the line):
static int x;
Thanks it works now here take a win.rar full of web cookies :D
You need to login to post a reply.