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
5
HELP HELP

2021/5/20

#
I’ll show the code because it is probably an obvious bug i just can’t focus right now due to no sleep aha.
HELP HELP

2021/5/20

#
import greenfoot.*; import javax.swing.JOptionPane; public class Login extends Actor { public String uname1; public String uname3; public String uname5; public String uname7; public String pword1; public String pword3; public String pword5; public String pword7; public int rounds; public String username1; public String password1; public int value; public String xn1; public String xn2; public String xn3; public String xn4; public void act(String args) { if (Greenfoot.mouseClicked(this)) { String username1 = JOptionPane.showInputDialog("Please enter your username."); String password1 = JOptionPane.showInputDialog("Please enter your password."); boolean b1 = username1.equals(uname1); boolean b2 = username1.equals(uname3); boolean b3 = username1.equals(uname5); boolean b4 = username1.equals(uname7); boolean b5 = password1.equals(pword1); boolean b6 = password1.equals(pword3); boolean b7 = password1.equals(pword5); boolean b8 = password1.equals(pword7); rounds = 1; int list = new int; if (b1 || b2 || b3 || b4 || b5 || b6 || b7 || b8) { if (rounds == 1) { rounds = 2; list = value; value = 0; username1 = xn1; Greenfoot.setWorld(new Level12()); } if (rounds == 2) { rounds = 3; list = value; value = 0; username1 = xn2; Greenfoot.setWorld(new Level12()); } if (rounds == 3) { rounds = 4; list = value; value = 0; username1 = xn3; Greenfoot.setWorld(new Level12()); } if (rounds == 4) { rounds = 5; list = value; value = 0; username1 = xn4; Greenfoot.setWorld(new Level12()); } } else Greenfoot.setWorld(new Level13()); } } }
HELP HELP

2021/5/20

#
Dan please take a look, I the i can run the programme with this however it doesnt do ANYTHING at all when i click it.
danpost danpost

2021/5/20

#
No "String args" in:
public void act()
danpost danpost

2021/5/20

#
There is no:
list[4]
in an array of length 4. First index in an array is number zero (0).
HELP HELP

2021/5/21

#
I removed string args. It is saying it cannot find the variables as they haven't been declared properly. How would I define this array of list?
HELP HELP

2021/5/21

#
Dan its because I need this declared as an array because I'm using it for a bubble sorting algorithm later.
HELP HELP

2021/5/21

#
import greenfoot.*;  
import javax.swing.JOptionPane;

public class Login extends Actor
{
        public String uname1;
        public String uname3;
        public String uname5;
        public String uname7;
        public String pword1;
        public String pword3;
        public String pword5;
        public String pword7;
        public int rounds;
        public String username1;
        public String password1;
        public int value;
        
        public String xn1;
        public String xn2;
        public String xn3;
        public String xn4;
        public int number;
    public void act() 
    {
        if (Greenfoot.mouseClicked(this))
        {
        String username1 = JOptionPane.showInputDialog("Please enter your username.");    
        String password1 = JOptionPane.showInputDialog("Please enter your password.");
        boolean b1 = username1.equals(uname1);
        boolean b2 = username1.equals(uname3);
        boolean b3 = username1.equals(uname5);
        boolean b4 = username1.equals(uname7);
        boolean b5 = password1.equals(pword1);
        boolean b6 = password1.equals(pword3);
        boolean b7 = password1.equals(pword5);
        boolean b8 = password1.equals(pword7);   
        rounds = 1;
        int list = new int[];
        if (b1 || b2 || b3 || b4 || b5 || b6 || b7 || b8)
        {
            if (rounds == 1)
            {
                rounds = 2;
                list[1] = value;
                value = 0;
                username1 = xn1;
                Greenfoot.setWorld(new Level12());
            }
            if (rounds == 2)
            {
                rounds = 3;
                list[2] = value;
                value = 0;
                username1 = xn2;
                Greenfoot.setWorld(new Level12());
            }
            if (rounds == 3)
            {
                rounds = 4;
                list[3] = value;
                value = 0;
                username1 = xn3;
                Greenfoot.setWorld(new Level12());
            }
            if (rounds == 4)
            {
                rounds = 5;
                list[4] = value;
                value = 0;
                username1 = xn4;
                Greenfoot.setWorld(new Level12());
            }           
        }
        else Greenfoot.setWorld(new Level13());
        } 
    }    
}
HELP HELP

2021/5/21

#
here is the code what do i need to do in order to make this actually run?
HELP HELP

2021/5/21

#
Dan please its very important.
Gbasire Gbasire

2021/5/21

#
replace line 39 with
int[] list = new int[4];
and when you set a int of list, start with 0 and go up to 3 (an int array with a length of 4 will have 4 int : 0, 1, 2 and 3)
RcCookie RcCookie

2021/5/21

#
You can’t use args, because you don’t get any. You can create a string array like any other,
String[] args = new String[<size>];
but that ain’t fill it up with anything.
RcCookie RcCookie

2021/5/21

#
Also Java is zero-indexed, meaning you start counting at 0 and the first index of the array is 0. Also that means that an array of length 4 only has the indices 0, 2, and 3, not 4.
HELP HELP

2021/5/22

#
Thanks guys. Its fixed.
HELP HELP

2021/5/22

#
Guys quick question. Can you publish a game using greenfoot or is this platform not applicable.
There are more replies on the next page.
1
2
3
4
5