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

2020/2/14

if counter

TakedaYeet TakedaYeet

2020/2/14

#
i want to know if i can execute a command if a counter is at a certain amount. this is my code for the counter (in a different class)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
private void KILL()
    {
        if(isTouching(human1.class))
        {
            if (getWorld() instanceof MyWorld)
            {
                removeTouching(human1.class);
                bumpCounter(1);
                Greenfoot.playSound ("scream1.1.mp3");
                if(counter == 0) {
                    Greenfoot.setWorld (level3.class);
                }
            }
            if (getWorld() instanceof level2)
            {
                removeTouching(human1.class);
                bumpCounter(1);
                Greenfoot.playSound ("scream1.1.mp3");
            }
            if (getWorld() instanceof level3)
            {
                removeTouching(human1.class);
                bumpCounter(1);
                Greenfoot.playSound ("scream1.1.mp3");
            }
        }
    }
    private void bumpCounter(int amount)
    {
        if (getWorld() instanceof level2)
            {
            level2 world;
            world = (level2)getWorld();
            Counter counter;
            counter = (Counter)world.getObjects(Counter.class).get(0);
            counter.add(amount);
             
        }
        if (getWorld() instanceof MyWorld)
            {
            MyWorld world;
            world = (MyWorld)getWorld();
            Counter counter;
            counter = (Counter)world.getObjects(Counter.class).get(0);
            counter.add(amount);
        }
        if (getWorld() instanceof level3)
            {
            level3 world;
            world = (level3)getWorld();
            Counter counter;
            counter = (Counter)world.getObjects(Counter.class).get(0);
            counter.add(amount);
        }
    }
TakedaYeet TakedaYeet

2020/2/14

#
please help
danpost danpost

2020/2/14

#
TakedaYeet wrote...
please help
Need Counter class codes (at minimum).
You need to login to post a reply.