Cannot call method 'isVisible' of undefined

edited March 2014 in JavaScript Mode

Hi all, I made a P3D planetary model that I'm trying to convert to JS. The first issue I came across was that createShape didn't seem to work, so I replaced instances like sun = createShape(SPHERE, 100); with sun = sphere(100);

This seems to get me a step further, though I don't exactly understand why (does this cause a problem with PShape?). However, when I run my code now my browser's inspector tells me "Uncaught TypeError: Cannot call method 'isVisible' of undefined". 'isVisible' appears here in the JS:

PShape.prototype = { isVisible: function() { return this.visible }, setVisible: function(visible) { this.visible = visible },

Any idea what's going wrong here? Thank you!

Answers

  • edited March 2014

    with sun = sphere(100);

    According to its reference: http://processingjs.org/reference/sphere_/ , sphere() returns nothing!
    Therefore, sun would be undefined after that assignment I believe! :@)

    "Uncaught TypeError: Cannot call method 'isVisible' of undefined".

    Well, undefined isn't neither an object nor a function reference! Moreover, it's simply as nothing as null! :O)

    PShape.prototype = {};

    Pretty much, doing the above would place your code in JavaScript native territory rather than JS Mode! 8-|
    You'd completely lose Java Mode compatibility along too! :-<

    Hope it's just your browser's JS inspection and not your actual code! 8-X

  • Thanks for your reply! You've picked up on my deep confusion about this. Yes, the PShape.prototype bit was from my browser's inspector.

    Here's my original code before the sphere() changes. Any idea why it's not displaying?

  • It showed this in the browser console:
    uncaught exception: Processing.js: Unable to execute pjs sketch: ReferenceError: createShape is not defined

    I believe createShape() is Processing 2+ exclusive. Processing/JS is still v1.4.1 and is very similar to Processing/Java v1.5.1.

    I believe the Old v1 was only able to load ".svg" files, but not create 1 itself! :-&
    Perhaps you should try to run your code under Processing 1.5.1, since it's much closer to ProcessingJS 1.4.1. (~~)

  • Ah, that's too bad. I just tried it in 1.5.1 and once I get rid of all the setFill() and setStroke()s that apparently didn't exist at the time I get the following error:

    Display 0 does not exist, using the default display instead. createShape(), or this particular variation of it, is not available with this renderer. Exception in thread "Animation Thread" java.lang.NullPointerException at processing.core.PGraphics.shape(PGraphics.java:2970) at processing.core.PApplet.shape(PApplet.java:8735) at Planetary_motion_17_camera.draw(Planetary_motion_17_camera.java:71) at processing.core.PApplet.handleDraw(PApplet.java:1631) at processing.core.PApplet.run(PApplet.java:1530) at java.lang.Thread.run(Thread.java:695)

    I take it that I won't get this to work in PJS either then?

  • P1.5.1 got 4 distinct renderers -> JAVA2D, P2D, P3D & OPENGL.
    From those 4, only OPENGL uses OpenGL. To try that mode out, you gotta import it!

Sign In or Register to comment.