TurboWarp / scratch-vm

Scratch VM with a JIT compiler and more features
https://turbowarp.org/
Mozilla Public License 2.0
75 stars 72 forks source link

Global blockUtility #199

Closed veggiecan0419 closed 7 months ago

veggiecan0419 commented 7 months ago

Hi everyone,

I had a question: How can I access the util (blockUtility) object outside a block definition? (Like we can access the Scratch object outside of a block definition)

LilyMakesThings commented 7 months ago

it's literally just made up of functions from other places, made accessible there purely for convenience.

you can read where it's pulling stuff from here: https://github.com/TurboWarp/scratch-vm/blob/develop/src/engine/block-utility.js

if you really cannot live without it, you can trap it by doing something like this.util = util.

GarboMuffin commented 7 months ago

Most of the functions on block utility are just one line things that call or set something on a thread that you would already need to have access to. There is one block utility object and it is shared by every block for performance reasons, so you would need to reinitialize the object yourself. Easier to just use the methods directly.

veggiecan0419 commented 7 months ago

@LilyMakesThings

it's literally just made up of functions from other places, made accessible there purely for convenience.

you can read where it's pulling stuff from here: https://github.com/TurboWarp/scratch-vm/blob/develop/src/engine/block-utility.js

Thanks You solved my problem!

veggiecan0419 commented 7 months ago

@GarboMuffin You can mark the issue closed as planned as Lily answered my question