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

2021/5/19

Counters not working

1
2
3
4
HELP HELP

2021/5/19

#
my counter goes away when i get to the next level. please help it’s urgent.
HELP HELP

2021/5/19

#
My world has many levels and i need the counter to stay in certain levels in the same position. but it disappears when i get to the next level (which happens when my main character hits the edge of the wall).
HELP HELP

2021/5/19

#
Please someone tell me how to have a world with 1 counter that is used across multiple levels and the score on it is the same on each level when certain events happen to update this.
HELP HELP

2021/5/19

#
I couldn’t find somewhere where there is a counter on multiple levels
Gbasire Gbasire

2021/5/19

#
make the variables your counter is using static and add it on every world
HELP HELP

2021/5/19

#
when i update the counter after a specific event it says this to update it “ Level5 level5World = (Level5) getWorld(); Counter theCounter = level5World.getCounter theCounter.add(10) “ because this is only for level5 how do i change this?
HELP HELP

2021/5/19

#
as in how do i change this for all the levels i use it for (ie levels 5-10)
HELP HELP

2021/5/19

#
in level 5 i also have public counter theCounter; public Counter getCounter() { return theCounter; } public void prepare() { theCounter = new Counter(); addObject(new Counter(), 42, 485); } public Level5(){ prepare();}
HELP HELP

2021/5/19

#
by the way your instructions fixed a quite a bit for me but i don’t understand the thing i said above. Please Help!
danpost danpost

2021/5/19

#
HELP wrote...
how do i change this for all the levels i use it for (ie levels 5-10)
in level 5 i also have
public counter theCounter;
public Counter getCounter()
{ return theCounter; }
public void prepare() {
theCounter = new Counter();
addObject(new Counter(), 42, 485); 
}
public Level5(){
prepare();}
Change all lines respecttively to:
public static Counter theCounter;
public static Counter getCounter()



addObject(theCounter, 42, 485);
After adjusting those 3 lines, you can use the following in ANY class:
Counter theCounter = Level5.getCounter();
For adding counter in higher levels, use:
addObject(Level5.getCounter(), 42, 485);
HELP HELP

2021/5/19

#
Great thats working now thanks a lot Dan. However there is a class called button1 and a class called Button2. and i cant pass the strings over to button2 from button1. i.e. String x1 = JOptionPane.showInputDialog("enter your name."); that line is done four times but its x1,x2,x3,x4. And when on button 2 i say public void act() if(Greenfoot.mouseClicked(this)) { String y = JOptionPane.showInputDialog("Please enter your name."); if (y .equals(x1 || x2 || x3 || x4)) // here is the error its underlined in x1 x2 x3 x4 and it says it cant find those variables. thats the error. Any chance you could explain why it cant find the variables and how to fix it?
HELP HELP

2021/5/19

#
PLEASE ITS URGENT!
Gbasire Gbasire

2021/5/19

#
share the full code of the button classes (you can use the "code" tool when you paste your code here, so we can view it easily)
HELP HELP

2021/5/19

#
Okay one second.
HELP HELP

2021/5/19

#
import greenfoot.*; 
import javax.swing.JOptionPane;
public class SignUp extends Actor
{

public void act() 
{  
if (Greenfoot.mouseClicked(this)) 
    {
        String uname1 = JOptionPane.showInputDialog("Please enter the first username.");    
        String uname2 = JOptionPane.showInputDialog("Please re-enter the first username.");
        String pword1 = JOptionPane.showInputDialog("Please enter the first password.");
        String pword2 = JOptionPane.showInputDialog("Please re-enter the first password.");
        
        String uname3 = JOptionPane.showInputDialog("Please enter the second username.");    
        String uname4 = JOptionPane.showInputDialog("Please re-enter the second username.");
        String pword3 = JOptionPane.showInputDialog("Please enter the second password.");
        String pword4 = JOptionPane.showInputDialog("Please re-enter the second password.");
        
        String uname5 = JOptionPane.showInputDialog("Please enter the third username.");    
        String uname6 = JOptionPane.showInputDialog("Please re-enter the third username.");
        String pword5 = JOptionPane.showInputDialog("Please enter the third password.");
        String pword6 = JOptionPane.showInputDialog("Please re-enter the third password.");
        
        String uname7 = JOptionPane.showInputDialog("Please enter the forth username.");    
        String uname8 = JOptionPane.showInputDialog("Please re-enter the forth username.");
        String pword7 = JOptionPane.showInputDialog("Please enter the forth password.");
        String pword8 = JOptionPane.showInputDialog("Please re-enter the forth password.");
if(uname1.equals(uname2) & pword1.equals(pword2) & uname3.equals(uname4) & pword3.equals(pword4) & uname5.equals(uname6) & pword5.equals(pword6) & uname7.equals(uname8) & pword7.equals(pword8)) 
{
Greenfoot.setWorld(new Level2()); 
}    
else Greenfoot.setWorld(new Level3());        
}
}
}
There are more replies on the next page.
1
2
3
4