jdf / Processing.py-Bugs

A home for all bugs and feature requests about Python Mode for the Processing Development Environment.
41 stars 8 forks source link

class problem #297

Closed coachbyers closed 4 years ago

coachbyers commented 4 years ago

I have been getting an error setting up my own class. So I went to the tutorial, copied and pasted the code and got the exact same error message.

class HLine(object): # class definition
    def _init_(self, ypos, stroke_color): # object constructor
        self.ypos = ypos
        self.stroke_color = stroke_color

    def display(self): # display method
        stroke(self.stroke_color)
        line(0, self.ypos, width, self.ypos)

# Declare and construct two objects (h1 and h2) of the class HLine(object)
h1 = HLine(20,0)
h2 = HLine(50,255)

background(127)
h1.display()
h2.display()

Error Message: TypeErrror: objectnew() takes no parameters

GoToLoop commented 4 years ago

I believe it's __init__ instead of _init_. :smirk_cat:

coachbyers commented 4 years ago

So there are 2 underscores before and after. I couldn't find that information anywhere in the documentation.

Thank you very much.

GoToLoop commented 4 years ago

I couldn't find that information anywhere in the documentation.

https://Py.Processing.org/reference/class.html

Processing's forum: https://Discourse.Processing.org