I want to put operator values in a block

27 views
Skip to first unread message

도노반

unread,
Nov 10, 2022, 12:23:34 AM11/10/22
to Blockly
I want to automatically add values for x, y, z coordinates when placing a block.
Is there any way?

Maribeth Bottorff

unread,
Nov 10, 2022, 11:22:27 PM11/10/22
to Blockly
Hello,

I'm not certain what you're asking here, but I think you mean you have a block with x,y,z coordinates as inputs (something the user should fill in). If that's not true, let me know and please clarify, but if it is what you're asking, then yes this is definitely possible. How to do it depends on what your block looks like:

If the coordinates are part of a field on the block, like a text input box a user can type into, then you can specify an initial value for that field. For example, for a number field, this code initializes the value to 100, so when the block is first created the value will be 100 until the user changes it: https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/number#creation

If the coordinates are separate blocks that can be connected, like the addition [] + [] block, then you can specify preset blocks in the toolbox so that the parent block automatically contains the child blocks. This is a great use case for shadow blocks, which are like placeholders that are easily replaced if users want to drag other blocks to replace them. These preset blocks would be defined in the toolbox so that a group of blocks appears in the toolbox and can be dragged out together. Read more here: https://developers.google.com/blockly/guides/configure/web/toolbox#preset_blocks

If you need more help with this topic, then posting a picture of the block you're talking about would be very useful.


If i've misunderstood and you are actually asking about controlling the location of the block on the workspace, then that is also possible (except in the z axis, I can't help you there) but I would need to know more about what you mean and how the blocks are being created, so please reply with more information if so.

Hope that helps,
Maribeth

Reply all
Reply to author
Forward
0 new messages