Blockly Event Handler with Parameter Variables

150 views
Skip to first unread message

Blake

unread,
Jul 22, 2016, 12:57:43 AM7/22/16
to Blockly
All,

What is considered the best practice when handling events that have parameters?

My use case is handling the event when a player breaks a block in Minecraft. The event has the player and the block supplied as parameters.

I imagine a (hypothetical via Photoshop) block that looks like the following image that allows the user to drag the "Player" and "Block" supply blocks from their supply containers into their program

Inline image 1

This would generate code akin to this:

events.onBlockBreak(function(player, block) {
});

One might imagine code eventually looking like this:

events.onBlockBreak(function(player, block) {
    if (block.type == "dirt") {
        block.location = new Block('TNT');
    }
});

I know i could add new blockly field which could act as the"supply" area but is there a better way to handle events that have parameters?

Thanks,
Blake

Daaron Dwyer

unread,
Jul 22, 2016, 11:14:45 AM7/22/16
to Blockly
Hi Blake,
I'm not sure what question you're asking. One size doesn't fit all when it comes to passing data to your application, so if you need several parameters, use them. You may also be asking about mutators, which are also useful when the number or type of parameters change. Only you can decide what and how you want to make your magic happen.

Hope that helps,
Daaron

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages