openblockcc / openblock-desktop

Graphic programming software for hardware like: arduino, microbit, esp32, esp8266...
MIT License
244 stars 106 forks source link

Bug: Variable adding with custom blocks #40

Closed ircbloqcc closed 2 years ago

ircbloqcc commented 2 years ago

While adding change variable blocks in custom block, global keyword should add. but in OB is not happening. so it gives error.

Expected Behavior

def on_button_a(): global test test += 5

def on_pin0(): global test test += 20`

Actual Behavior

Screenshot 2022-01-04 194710

i have tried with python code. that also gives error.

Screenshot 2022-01-04 200109

zhengyangliu commented 2 years ago

You are right. The code should be like this:

from microbit import *

test = 0

test = 0

def repeat():
  if button_a.is_pressed():
    on_button_a()

def on_button_a():
  global test
  test += 1

while True:
  repeat()
zhengyangliu commented 2 years ago

I will fix this soon.