Change value of field cause render bug

84 views
Skip to first unread message

pigeonmaléfique

unread,
Nov 4, 2021, 11:26:57 AM11/4/21
to Blockly
Hi, I have a custom block :
Blockly.Blocks['custom_block'] = {
 init: function () {
    this.setNextStatement(false);
    this.setPreviousStatement(false);
    this.setOutput(true);
   var fieldLabel = new Blockly.FieldLabel("Variable")
    this.appendDummyInput().appendField("Get ")
      .appendField(fieldLabel, "TEXT");
    this.setOnChange(function (changeEvent) {
      if (changeEvent.type == Blockly.Events.CREATE){
          fieldLabel.setValue("NEW VALUE");       
      }
    });
  }
}

That work but I have render bug :
Capture.PNG
Cause: update marks function in forcerender in setValue

How can fix that ?

Abby Schmiedt

unread,
Nov 4, 2021, 7:45:55 PM11/4/21
to Blockly
Hello!

What version of Blockly are you using? And can you provide more information on what steps you took to get into this state?

Thanks!
Abby

pigeonmaléfique

unread,
Nov 5, 2021, 8:13:04 AM11/5/21
to Blockly
I use google-blockly-d4196c1 , and I drag the custom_block from the flyout to the block. So that send a Create event, and I change the value of the field, but that create a render bug. But when I remove the block (after the render bug), that work fine

Beka Westberg

unread,
Nov 5, 2021, 12:28:43 PM11/5/21
to blo...@googlegroups.com
Ohh so are you setting the field value while the block is being dragged? Usually trying to make render changes while a block is dragging causes it to derp up.

Could you provide some more info about why you're using the change event? I think it should work if you just update the field in the init method, but I assume that there's a reason you don't want to do that (eg you want the field to look different while it's in the flyout?) Maybe instead of triggering it on the create event, you could trigger it on a move event (like when the block is first placed).

Hopefully that's the issue! But if it doesn't work or you have any further questions, please reply!
--Beka

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/e07eab97-67d5-4dc9-b189-404fbc4aa926n%40googlegroups.com.

pigeonmaléfique

unread,
Nov 5, 2021, 1:56:27 PM11/5/21
to Blockly
I wanted to use init as a base, except you can't use block.data. In fact, I use my own system of variables, so I have a data block (they are Getter Variable) which represents the block id of the main variable (initiator of the variable). So I wanted a block that as soon as it is dragged, it looks at the data of the block, it looks for the initiator of the variable, then looks at the name of the field input text, and finally it changes the field (.setValue as indicated in my old messages).
-> This allows that when it renames the variable, I can know what the getter variables are, so that I can rename them as well.

I tried several events like Create and Selected, but without success, the same bug. I think I have a little advanced variable system, do you have a solution to my problem (render bug) or even how I could make my system much better. Because I think putting <data> ID </data> in each bock getter is not the best solution.

Finally, the event with MOVE does indeed work without worries, however I would like that to change it from the start (if possible) (either in the toolbox, or as soon as it is dragged)

Sincerely, Pigeonmal.

Beka Westberg

unread,
Nov 7, 2021, 10:45:24 AM11/7/21
to blo...@googlegroups.com
Hello,

If you want to change how your block appears based on some serialize data (ie your .data property) I think you should look into using a mutator instead. Mutators are just ways of adding extra serialization to blocks (they don't have to change its shape or have the traditional gear icon). And as such they come with built-in callbacks muattionToDom and domToMutation. If you set your field value from these callbacks you shouldn't get any rendering problems =)

I hope that helps! If you have any further questions please reply!
--Beka

pigeonmaléfique

unread,
Nov 14, 2021, 1:40:10 PM11/14/21
to Blockly
Re, as i change the field text when a person changes the field input of the variable i think mutators is not the right thing. In fact, after modifying my code from above:
I detect important events (move, create, change, ...)
and see if the Get block has the same name as the variable
otherwise it changes it.
it allows me to synchronize everything in one place.
So I always have the same error
Reply all
Reply to author
Forward
0 new messages