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

2022/5/5

Can Someone help me with this bug?

Kingrko23 Kingrko23

2022/5/5

#
public void check(){
        if(getOneIntersectingObject(Scanner.class) != null && !checked){
            checked = true;
            System.out.println(Scanner.lastNum);
            if((input-Scanner.lastNum) < input&&Scanner.lastNum == Scanner.lastNum++){
                getWorld().addObject(new GameOver(), 405, 310);
                Greenfoot.stop();
            }
            Scanner.lastNum++;
        }
    }
This code is supposed to check for a scanner when it is in the correct order but it either just passes through or stops at the second block is there an easier way
Spock47 Spock47

2022/5/5

#
I don't understand what your source code should do, but I can tell that the expression
Scanner.lastNum == Scanner.lastNum++
is wrong. (and the expression
(input-Scanner.lastNum) < input
can be simplified to
Scanner.lastNum > 0
, which implies that it probably is not what you want it to be, too.) To understand your question, the following infos would be helpful: 1. What is variable "input"? 2. What is the meaning of variable "Scanner.lastNum"? 3. What does "is in the correct order" mean for a scanner? (And what is a scanner?) 4. Presumably, seeing the source code of the complete class is necessary to solve the problem. 5. Very likely the variable "Scanner.lastNum" should instead be a private attribute of this class (except if it is used in other places, too, in which case the source code of Scanner would be needed, too, to solve the problem). Live long and prosper, Spock47
You need to login to post a reply.