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

mouseButton #199

Closed brendanstuff closed 6 years ago

brendanstuff commented 6 years ago
from processing import *
from random import randint
x = 0
y = 0
def setup():
    size(1920,1080)
def draw():
    pass
def mousePressed():
    global x, y
    if mouseButton == LEFT:
        x += float(mouse.x - x)
        y += float(mouse.y - y)
        rect(x - 25, y - 25, 50, 50)
run()

throws us: Uncaught NameError: name 'mouseButton' is not defined on line 11

Came across this doing something my friend challenged me to do (we're both new to coding).

jdf commented 6 years ago

That example doesn't even run, as the function run() isn't defined, and neither is mouse, so that NameError can't be thrown. This program works for me:

def setup():
    size(400, 400)

def draw():
    pass

def mousePressed():
    if mouseButton == LEFT:
        rect(mouseX - 25, mouseY - 25, 50, 50)