Closed TheShovel closed 2 years ago
You can create/change variables and broadcast messages but not using Blockly. Rather, you'd use scratch-vm, an instance of which is made global via Scratch.vm
const stage = Scratch.vm.runtime.getTargetForStage()
const wowVar = stage.lookupOrCreateVariable(null, 'wow')
console.log(wowVar.value) // 0 by default
wowVar.value = 3
Scratch.vm.runtime.startHats('event_whenbroadcastreceived', {
BROADCAST_OPTION: 'message1'
})
Thanks a lot for the help!
I have another question on how you found the text representation to "run" scratch blocks. Because I searched a lot and didn't find anything.
Scratch blocks are represented as text in the form of JSON. If you download a project, rename it to a .zip, then extract it, the project.json file will contain the blocks' text representation
I tried running
Scratch.vm.runtime.startHats('event_whenbroadcastreceived', {
BROADCAST_OPTION: 'message1'
})
and it didn't work... It says Scratch is not defined. Shouldn't it be defined and all that?
Scratch
should be defined in HTMLified projects
Scratch
should be defined in HTMLified projects
I just did and vm.runtime.startHats('event_whenbroadcastreceived', { BROADCAST_OPTION: 'e' })
worked
Is there any documentation for more stuff? Like moving a sprite or modifying any of it's properties?
Thanks, but I still don't understand how to modify sprite properties. For example rotation or position. Wold you mind giving me some examples. Sorry for asking for so much help btw.
You can look at how the motion blocks are defined
Example that I could use for any of those? So I understand the syntax, since that is my main issues rn, I do not understand how to specify what sprite I wanna modify and all that.
You can use vm.runtime.getSpriteTargetByName(spriteName)
to get a sprite by its name or vm.runtime.getTargetForStage()
for the stage
thank you! That is exactly what I wanted.
You can use
vm.runtime.getSpriteTargetByName(spriteName)
to get a sprite by its name orvm.runtime.getTargetForStage()
for the stage
weird... that gives me an error, saying it isn't defined
vm.runtime.getSpriteTargetByName(Sprite1)
nvm, forgot to put it in ('Sprite1')
-Can you define a blockly variable using it? (after project is loaded)
-Can you modify already existent variables? (player position for example)
-Can you brodcast a message using it?
-If it is not possible with blockly, than is it possible with something else?
And if it is, than could you show me a example that I could test?
Thank you once again for your time.