Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CODED is not supported #209

Open
gaocegege opened this issue Aug 11, 2017 · 2 comments
Open

CODED is not supported #209

gaocegege opened this issue Aug 11, 2017 · 2 comments

Comments

@gaocegege
Copy link
Member

key is a char, and CODED is a int, I don't know how to compare those two things

fillVal <- 126

draw <- function() {
  fill(fillVal)
  rect(25, 25, 50, 50)
}

keyPressed <- function() {
  print(key)
  print(CODED)
  if (key == CODED) {
    if (keyCode == UP) {
      fillVal = 255
    } else if (keyCode == DOWN) {
      fillVal = 0
    } 
  } else {
    fillVal = 126
  }
}
@jeremydouglass
Copy link
Member

jeremydouglass commented Aug 14, 2017

Java automagically converts the char to an int for comparison -- for example, this works:

final int CODETEST = 99;
println(CODETEST);
int myKey = 'c';
println(myKey);
if(myKey == CODETEST){
  println("equal");
}

If this isn't working in R, perhaps due to precedence (?), then perhaps try:

Option 1: change CODED in the list of constants to a char type

Option 2: convert before check:

(key == as.character(CODED))

@jeremydouglass
Copy link
Member

Option 1: change CODED in the list of constants to a char type

Thinking about this further, I think that option 1 -- changing CODED to a char in Processing.R -- is the way we should go. The only way that CODED is used in the Processing API is to compare it to key, so this preserves the Processing style of writing

if (key == CODED) {

which is what we want. The char(CODED) value in Java should be equal to in renjin something like:

CODED <- as.character(65535)

@jeremydouglass jeremydouglass added this to the v1.0.8 milestone Aug 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants