Having trouble with a method in G4P

Hi. So, I'm pretty much a noob here, and I was trying to get some flashlight effect code but it won't run. I have to use loadPixels but it won't recognize the image variable, saying "sala3 is not a global variable". I know I may be explaining horribly bad but I really don't know how to out the appc. in order to get it working. Thanks!

Tagged:

Answers

  • edited June 2017

    Also, how can I upload the code so you can see it?

  • Basically you copy and paste the code into the form comment edit box but tou should see the How to format code and text discussion and also at the Technical FAQs discussion before posting any more comments.

  • edited June 2017

    Thanks @quark, that came in handy. I've read everything on those posts yet I still don't manage to figure out what exactly is my problem. For anyone who might just get an idea I will put it down here:

    <pre lang="processing">
    PImage Sala3;
    
    public void setup() {
      size(800,800);
      Sala3=loadImage("SALA 3.png");
    }
    
    synchronized public void win_draw5(PApplet appc, GWinData data) 
    {
      appc.loadPixels();
      Sala3.loadPixels();
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          int loc = x + y * width;
          float r = appc.red(Sala3.pixels[loc]);
          float g = appc.green(Sala3.pixels[loc]);
          float b = appc.blue(Sala3.pixels[loc]);
    
          float d = dist(mouseX, mouseY, x, y);
          float factor = map(d,0, 100, 2, 0);
          pixels[loc] = color(r*factor, g*factor, b*factor);
        }
      }
      appc.updatePixels(); 
    }
    
    </pre>
    
  • Line 22 should be

    appc.pixels[loc] = color(r*factor, g*factor, b*factor);

    You should not be getting the error message "sala3 is not a global variable", are you in fact still getting it?

Sign In or Register to comment.