Turn off mutator

38 views
Skip to first unread message

Alan Smith

unread,
Jan 27, 2025, 11:43:49 AMJan 27
to Blockly
How can I turn off the mutator icon on a block?  
(I have a block that either allows it or disallows it based off of extraState).  

The code seems to say to pass in a null, but I am in typescript and the typescript defintiion doesn't allow passing in null.

Thanks,

Alan


Mark Friedman

unread,
Jan 27, 2025, 1:30:05 PMJan 27
to blo...@googlegroups.com
Hm, it certainly looks from the source code for setMutator that you should be able to pass in null to remove the mutator.

-Mark


--
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 visit https://groups.google.com/d/msgid/blockly/049b9dd6-14dd-4222-a090-37d494e03b73n%40googlegroups.com.

Alan Smith

unread,
Jan 27, 2025, 2:36:14 PMJan 27
to blo...@googlegroups.com
The problem is if you have a Blockly.Block, this is how setMutator is defined:

It also needs the | null

Thanks,

Alan


Mark Friedman

unread,
Jan 27, 2025, 2:41:59 PMJan 27
to blo...@googlegroups.com
I agree, but in the short run you should be able to declare/cast it as a BlockSvg, right?

-Mark


Mark Friedman

unread,
Jan 27, 2025, 2:50:58 PMJan 27
to blo...@googlegroups.com
Or you could use the non-null assertion operator, which should be pretty safe, since you should actually have a BlockSvg object.

-Mark

Alan Smith

unread,
Jan 27, 2025, 3:30:59 PMJan 27
to blo...@googlegroups.com
I can't use the non-null assertion operator, because I am trying to pass in a null for the Mutator.  I think the right answer is probably to cast it as a BlockSvg object instead of Block.

--Alan


Alan Smith

unread,
Jan 27, 2025, 3:31:11 PMJan 27
to blo...@googlegroups.com
Is there a place for putting in issues with the blockly library that I should file this?

--Alan

Mark Friedman

unread,
Jan 27, 2025, 3:34:35 PMJan 27
to blo...@googlegroups.com
On Mon, Jan 27, 2025 at 12:30 PM Alan Smith <al...@randomsmiths.com> wrote:
I can't use the non-null assertion operator, because I am trying to pass in a null for the Mutator. 

Ah yes, of course.  That was your whole point!  Sorry about that.  Somehow by the fourth email reply I lost sight of the original goal :-(

I think the right answer is probably to cast it as a BlockSvg object instead of Block.

Indeed.

-Mark

Reply all
Reply to author
Forward
0 new messages