Edit/Debug

JavaScript has a nice feature - you can easily add or remove new commands from an already running script. You can also use MicroScript - it's cool because it speeds up the writing of the code. Instead of killing the program, add a line, compile and run - how much time it takes.

https://microstudio.dev/i/Paul59/voronoi2/

This 'Voronoi Sprites' program will show that there is a bug in MicroStudio. I don't know if it's a parsing error or something more complicated.

  1. Run this program.
  2. The Voronoi diagram is displayed.
  3. Start editing the code, for example comment out code lines 28

// screen.drawSprite ("sprite1." + temp, x, y, 4, 4) 4. The diagram is not drawn - this is what you expect. 5. Now uncomment code line 28. 6. Oooooooh, there's just a big green square.

The same error occurs in MicroScript 1.0, MicroScript 1.0 + Transpiler, MicrosScript 2.0 beta. You will get the same result if you stop the program while commenting. The error occurs in Firefox 101 and Chrome 102.

This error is very hard to spot because sometimes you comment a line of code in one place and something you don't touch stops showing (doesn't work). If you are new to programming, you don't know what is happening or why.


I also have a second 'Sound' code - instability.

  1. If I run it by clicking the mouse on the "Run project" button - the model melody is played - at the beginning.
  2. Don't click anywhere else. Just keep pressing the "A" key when the melody is over. The computer plays the same tune in the same way over and over again.
  3. a) Click now on the source code. b) You don't need to add anything to the code or comment on the line. c) Now click on the place where the program works - the right side of the page.
  4. Press the "A" key - now the music is sped up. It is also tearing (it has distortion).

If you start the program with the "Restart project" button and quickly click on the field where the program works, the music will stop playing immediately! Why ? . After pressing the "A" key - playback is accelerated.

midi = "sin loop 2 C2 C F G G G F end"
init = function()
  runPlay = false
  firstPlay = true
end

play = function( string )
  audio.beep( string )
end

update = function()
  if (keyboard.press.A and ( not runPlay )) then 
    runPlay = true
    print( 'Press A ')
  end
end

draw = function()
  if firstPlay then 
    firstPlay = false
    play( midi ) 
  end
  print( system.time() + '  '+ system.fps + ' Press A to play')
  if runPlay then
    runPlay = false
    audio.cancelBeeps()
     play( midi )
  end
end