DexterO/S and Blocky programming: Local Variable 'gpg' referenced before assignment

I am attaching two bloxter programs to this message.

  1. Distance_Sensor_Test.blox
    a. This program causes the 'bot to drive forward to within a certain distance of an object and then stop. If the object gets too close, the GoPiGo backs away from it. If the object moves away, the GoPiGo moves forward until it is a certain distance away again.
    b. The “eyes” color indicate status:
    White is the initial state while it’s setting itself up and waiting to start.
    Green is “moving forward”
    Blue is “moving backward”
    Red is “stopped”.

  2. Avoid_Object-1.blox
    a. This program uses logic from the first program to move toward an object and, when it gets within a certain distance it stops, looks to the right and left to find an “escape route”, and when it finds it it turns in that direction, centers the servo, and continues moving until it confronts another object.

When I try the second program, it fails to run and reports that “Local Variable ‘gpg’ referenced before assignment” (See attached .jpg)

Two questions:

  1. Why?
  2. Where? I don’t see anything that tells me at what part of the program it stopped. I suspect it’s early on because the color of the “eyes” doesn’t change.

This may be related to two possible “bugs” I discovered while using the advanced bloxter editor:

  1. Once a variable is created, it cannot be deleted even if you select “delete variable” with it selected in the left-hand tools pane.
  2. Having created a function, you cannot delete it if you need to change it for some reason. (i.e. You need to change it to a function that returns a value, etc.) Likewise, you cannot change the type of function (i.e. change it from one that returns a value, or dosen’t, to the other.)

Jim “JR”

Avoid_Object-1.blox.txt (11.0 KB)

Distance_Sensor_Test.blox.txt (4.6 KB)

Local%20Variable%20'gpg'%20referenced%20before%20assignment

I cannot reproduce your issue (and I was able to delete the extra function by dragging it into the trashcan )

When you get that error, it is usually because the Start block is not the highest of all sequences. If you lower your functions, the issue should go away. It’s a known bug. Hopefully fixed in 2.3

What browser are you using? I was having trouble with Firefox.

I am sure that if I were to re-create the program from scratch, the issue would go away.  Is there some way to “sanitize” the bloxter code to clean up cruft and hopefully allow me to continue development?

Unfortunately, given the existing capabilities of the block editor, I do not know how to “lower [my] functions”?  How do I go about doing that?

Thanks!

Jim “JR”