how to execute multiple blocks when using phaser js?

103 views
Skip to first unread message

Vihang Kale

unread,
May 12, 2021, 3:23:14 AM5/12/21
to Blockly
When I execute the block, it doesn't execute the code multiple times when multiple blocks are attached and there's no error in the console. I just want to move the character/ spritesheet using the blocks. Kindly refer the code belowScreenshot at 2021-05-12 12-49-05.pngphaser.pngblock.png

Jason Schanker

unread,
May 12, 2021, 4:29:02 AM5/12/21
to Blockly
Hi,

I haven't used Phaser JS, but an easy way to check if moveRight is being called multiple times by the blocks you assemble is by opening the Developer console after you assemble the blocks and entering the following:

Blockly.JavaScript.workspaceToCode();

Then you can see the code that is being run.  I don't see anything wrong with your generator for the "right" block.  However, if the "when_run" block is a block with a statement input and the statement input is not also called when_run, then none of the code from the blocks contained in that stack will be part of the generated code, which could be causing your problem.

Best,
Jason

Vihang Kale

unread,
May 12, 2021, 7:49:58 AM5/12/21
to Blockly
I tried doing the console thing, it does call the function multiple times( output on the console "moveRight();\nmoveRight();\n") but effect is not seen on the screen and yes statement input is also called(refer the code above).

Jason Schanker

unread,
May 12, 2021, 10:49:08 AM5/12/21
to Blockly
Hi again,

I just checked the PhaserJS docs (https://photonstorm.github.io/phaser3-docs/Phaser.Animations.AnimationState.html#play), and it seems if you change true to false in moveRight, it might fix this issue because the second argument represents:

ignoreIfPlaying
boolean
<optional>

If this animation is already playing then ignore this call.

What I meant before is that your generator code would still work even if your block did not have a statement input; the block would simply generate no code.  But if it did have a statement input and that statement input were called something else like DO and you stacked the "right" blocks in the DO input of the "when_run" block, then those "right" blocks would not generate any code either.

Hope this helps.

Best,
Jason

lili loula

unread,
Jul 9, 2021, 11:01:26 AM7/9/21
to Blockly
hello ,please did you find a solution, im facing the same issue ,please help!
Reply all
Reply to author
Forward
0 new messages