Skip to content

Instantly share code, notes, and snippets.

@sgodycki
Created September 17, 2021 15:57
Show Gist options
  • Save sgodycki/e2a84c39f6b22dd3191d50cc7c543b26 to your computer and use it in GitHub Desktop.
Save sgodycki/e2a84c39f6b22dd3191d50cc7c543b26 to your computer and use it in GitHub Desktop.
Homework map error message
def setup():
size(800,375)
global mountainsImage
global hillsImage
global foregroundImage
global princesspeachImage
global moonImage
mountainsImage = loadImage("week03-mountains.png")
hillsImage = loadImage("week03-hills.png")
foregroundImage = loadImage("week03-foreground.png")
princesspeachImage =loadImage("princesspeach.png")
moonImage = loadImage("week03-moon.png")
def draw():
rg = map(mouseX, 0,width, 155,10)
b = map(mouseX, 0,width, 255,50)
background(rg,rg,b)
mtnX=map(mouseX,0,200,0,-20)
image(mountainsImage, mtnX, 50)
hillsX = map(mouseX, 0, width, -20,-200)
image(hillsImage, hillsX, 250)
fgX = map(mouseX, 0, width, 0, -2000)
image(foregroundImage, fgX, 225)
mode=Python
mode.id=jycessing.mode.PythonMode
@sgodycki
Copy link
Author

It keeps saying mouseX not defined. When I try to run the code and I don't know why? @rors
NameError: name 'mouseX' is not defined

@rors
Copy link

rors commented Sep 17, 2021

Hi Sasha. Looks like you have some issues with your indentation (the spaces at the start of each line).

Highlight lines 18-15 and press the TAB key. That should indent all of those lines to align with indentation of your draw() block. That should fix the mouseX error, but then I suspect you'll see another error message.

You also need to indent your loadImage() lines, i.e. lines 8-12. So again highlight those lines and hit TAB key to indent them.

If you try running the code at this point you'll get an error message that says "unindent does not match any outer indentation level". The issue here is that the first few lines of your setup() block are using 5 spaces, but Python Processing by default uses 4 spaces – i.e. when you hit TAB it indents with 4 spaces. You can actually use whichever you'd like – any number of spaces are valid for indentation, but you have to be consistent. And since the Python Processing default is 4, I would recommend / request that you use that. So, go through lines 2-7 and delete that extra space so each line starts with 4 spaces.

If you do all that and try running it I think it should work!

Good luck. Let me know if you get stuck.

@sgodycki
Copy link
Author

Hi Sasha. Looks like you have some issues with your indentation (the spaces at the start of each line).

Highlight lines 18-15 and press the TAB key. That should indent all of those lines to align with indentation of your draw() block. That should fix the mouseX error, but then I suspect you'll see another error message.

You also need to indent your loadImage() lines, i.e. lines 8-12. So again highlight those lines and hit TAB key to indent them.

If you try running the code at this point you'll get an error message that says "unindent does not match any outer indentation level". The issue here is that the first few lines of your setup() block are using 5 spaces, but Python Processing by default uses 4 spaces – i.e. when you hit TAB it indents with 4 spaces. You can actually use whichever you'd like – any number of spaces are valid for indentation, but you have to be consistent. And since the Python Processing default is 4, I would recommend / request that you use that. So, go through lines 2-7 and delete that extra space so each line starts with 4 spaces.

If you do all that and try running it I think it should work!

Good luck. Let me know if you get stuck.

I did all that but its still not working I'm getting this error message instead
NullPointerException
at processing.core.PGraphics.image(PGraphics.java:3814)
at processing.core.PApplet.image(PApplet.java:12813)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.python.core.PyReflectedFunction.call(PyReflectedFunction.java:188)
at org.python.core.PyReflectedFunction.call(PyReflectedFunction.java:206)
at org.python.core.PyObject.call(PyObject.java:534)
at org.python.core.PyObject.call(PyObject.java:540)
at org.python.core.PyMethod.call(PyMethod.java:171)
at org.python.pycode.pyx11.draw$2(map_.pyde:31)
at org.python.pycode.pyx11.call_function(map_.pyde)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyBaseCode.call(PyBaseCode.java:125)
at org.python.core.PyFunction.call(PyFunction.java:403)
at org.python.core.PyFunction.call(PyFunction.java:398)
at jycessing.PAppletJythonDriver.draw(Unknown Source)
at processing.core.PApplet.handleDraw(PApplet.java:2482)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)

@rors
Copy link

rors commented Sep 17, 2021

NullPointerException can be a tough one to debug because I would say that is one of the least informative error messages that you can get.

In this case, my guess is that one or more of the image files that you're referencing by name on lines 8-12 is missing from your sketch folder. Can you confirm that all 5 image files are present in your sketch folder and the the filenames precisely match the filenames that you are using in your code? (If you're unsure how to confirm this, from within Processing you can go to the menu and click Sketch > Show Sketch folder, or type ⌘K, then look for the files in the sketch folder, and also look inside the folder named data.)

If any of the files are missing or the names are different, either add them, rename them, or correct the filename in your code.

If you're sure all the files are in there with the same filenames that you're using, please create a new Gist and tag me in that, as I'd like to have a look at the code as you've updated it.

Let me know if that works!

@sgodycki
Copy link
Author

NullPointerException can be a tough one to debug because I would say that is one of the least informative error messages that you can get.

In this case, my guess is that one or more of the image files that you're referencing by name on lines 8-12 is missing from your sketch folder. Can you confirm that all 5 image files are present in your sketch folder and the the filenames precisely match the filenames that you are using in your code? (If you're unsure how to confirm this, from within Processing you can go to the menu and click Sketch > Show Sketch folder, or type ⌘K, then look for the files in the sketch folder, and also look inside the folder named data.)

If any of the files are missing or the names are different, either add them, rename them, or correct the filename in your code.

If you're sure all the files are in there with the same filenames that you're using, please create a new Gist and tag me in that, as I'd like to have a look at the code as you've updated it.

Let me know if that works!

Yes thank u that ended up working !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment