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

better block events #139

Closed RedMan13 closed 1 year ago

RedMan13 commented 1 year ago

the ability to point to an event name instead of requiring a function to return true or false if a event has happend basicaly

                    {
                        opcode: 'onTurboMode',
                        blockType: Scratch.BlockType.HAT,
                        event: Scratch.vm.runtime.TURBO_MODE_OFF,
                        text: 'when turbo mode is turned off'
                    }

instead of

    let turboModeChanged = false
    Scratch.vm.runtime.on(Scratch.vm.runtime.TURBO_MODE_OFF, () => turboModeChanged = true)
                    ...
                    {
                        opcode: 'onTurboMode',
                        blockType: Scratch.BlockType.HAT,
                        text: 'when turbo mode is turned off'
                    }
                    ...
        onTurboMode() {
            const oldState = turboModeChanged
            turboModeChanged = false
            return oldState;
        }

and for custom events its the exact same

                    {
                        opcode: 'onCustomEvent',
                        blockType: Scratch.BlockType.HAT,
                        event: 'customEvent',
                        text: 'when a custom event is fired'
                    },
                    {
                        // demo block just to show that you can fire the event from within the extension
                        opcode: 'fireCustomEvent',
                        blockType: Scratch.BlockType.COMMAND
                    }
                    ...
        fireCustomEvent() {
            Scratch.vm.runtime.emit('customEvent');
        }

and to be clear i am not saying it must be done this way, only that it would be nice if you could use actual events for hat blocks

GarboMuffin commented 1 year ago

already exists https://docs.turbowarp.org/development/extensions/hats