How am I wrong with this

Welcome to the forum :smile:

It appears to be an issue with Processing rather than your code.

Processing objects to the variable name open it also doesn’t like opens but I got it to accept shut so you could simply use
boolean shut = true;

The door would be open if shut = false and you could test this with

if(!shut){
    // door is open code
}

Update to last post:

It is definitely a Processing issue as your code is acceptable to Java. I suspect it is being incorrectly being flagged by the pre-processor as early versions of Processing used to have a function (over 10 years ago) called open but was replaced by launch.

1 Like
1 Like

How about?

  • boolean isOpen = false;
  • if (isOpen) return;
1 Like

Since you asked there is nothing wrong with using isOpen but since it is an attribute of the class Door I would prefer to reserve isOpen to be a method to interrogate the door state, open or shut. Since Processing doen’t want us to use open I envision the class structure to be something like

class Door{

  boolean shut = true;
   
  void tryOpen(Player p){
    if(!shut) return;
    if(lockType == LOCK_WIRE && p.hasWire) shut = false;
    if(lockType == KEY_CARDE && p.hasKeycard) shut = false;
  }
  
  boolean isOpen() {
    return !shut;
  }

}

I should point out this is my preference and is not a criticism of using isOpen.

I know I can be a little pedantic when it comes to syntax and semantics :innocent: and the OP can choose either approach or something else to avoid the Processing bug. :grinning_face:

2 Likes

What you call pedantic is really precision! Never change.

In coding and technical work, precision and correctness matter because small differences in syntax and semantics can change meaning and behavior.

:)

1 Like