Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Labels and Serialization

89 views
Skip to first unread message

Max Stephen Russell

unread,
Jan 27, 2025, 10:08:42 AMJan 27
to Blockly
I wonder if someone could explain -- very simply and obviously and concretely with a single real-life example -- the difference between a "normal" label and a serializable label. Without using the word "serializable" to explain the difference. How would I decide to use one or the other in a particular real-life instance? I need plain English, not more code.

Thank you very much!

Steve

Neil Fraser

unread,
Jan 27, 2025, 10:35:18 AMJan 27
to blo...@googlegroups.com
Almost all the time you just want a 'normal' label.  Those are static pieces of text on a block.  E.g. "repeat" or "do".

Very occasionally you'll have a label that has text that can change as a result of some event handler.  An example might be the name of a function on a function call block (as opposed to a function definition block where that text is directly editable).  The text of this label is set dynamically. When saved to JSON or XML (using the 's' word), these rare labels need to have their text saved too, so that the text can be restored when loading the JSON or XML back to blocks.

--
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/bd6c97eb-4409-4916-87fc-a86a83bcb5c7n%40googlegroups.com.


--
Neil Fraser, Switzerland
https://neil.fraser.name

Max Stephen Russell

unread,
Jan 27, 2025, 10:43:12 AMJan 27
to Blockly
Now I think I get it! Thanks, Neil. "the 's' word" - ha ha. I hope I didn't sound too Monday-morning-grumpy.

-Steve

Max Stephen Russell

unread,
Feb 14, 2025, 8:14:28 AMFeb 14
to Blockly
In the absence of examples, could you provide the specific line of code, from within a function called by an event, that would set the text of a serializable label named STATUS to “Approved”?

Steve


On Monday, January 27, 2025 at 10:35:18 AM UTC-5 Neil Fraser wrote:

Mark Friedman

unread,
Feb 14, 2025, 1:39:56 PMFeb 14
to blo...@googlegroups.com
For all fields, setValue is what you use to set their value.  So in this case it would be myBlock.getField('STATUS').setValue('Approved').

-Mark


Max Stephen Russell

unread,
Feb 14, 2025, 2:00:56 PMFeb 14
to Blockly

Well thank you very much, Mark. I believe that is reminiscent of my old Microsoft Access days.

Max Stephen Russell

unread,
Feb 19, 2025, 7:24:35 AMFeb 19
to Blockly
For all fields, setValue is what you use to set their value.  So in this case it would be myBlock.getField('STATUS').setValue('Approved').”

Although I have used setValue a thousand times in other environments, may I ask for a demonstration of this method for the following block and its dateNUM field, and a note as to where the call is being made from?

const intervalDaysBlock = {
  'type': 'intervalDays',
  'message0': '%1 days',
  'args0': [
    {
      'type': 'field_number',
      'name': 'dateNUM',
      'value': 730
    },
  ],
  'output': 'Number',
  'colour': 225,
  'tooltip': 'Represents a duration in days.'
};

On Friday, February 14, 2025 at 1:39:56 PM UTC-5 mark.f...@gmail.com wrote:

Max Stephen Russell

unread,
Feb 19, 2025, 6:23:11 PMFeb 19
to Blockly
I have now seen some implementation examples of setValue and would not want to ask anyone here to go to that much trouble for me. Please disregard my request for a demonstration, unless such an effort has already begun. Thanks to all for so much assistance lately. I am finally picking up momentum.

-Steve

Mark Friedman

unread,
Feb 21, 2025, 6:26:24 PMFeb 21
to blo...@googlegroups.com
Steve,

  It's not really clear to me what you are asking for here.  Are you asking for an example of how you would use setValue to set the dateNUM field for a block that was defined using intervalDaysBlock as defined by you below?  If that's it, the answer is simply something like myBlock.getField('dateNum').setValue(750).  However, you are also asking where the call is being made from.  The, somewhat trite, answer is that it is called from wherever you, as the programmer, are calling it.  But, perhaps, what you're really asking is under what circumstances might you, as the programmer, call it.  One answer might be if your app received some date data from an external source (e.g. a database, or an API call) and therefore wanted to programmatically change the value of a block's dateNUM field with that data.

Does that make sense or have I still misunderstood your questions?  If it's the latter, please try to clarify what you're looking for.

-Mark


Max Stephen Russell

unread,
Feb 21, 2025, 6:58:57 PMFeb 21
to Blockly

Hi Mark,

Yes, it makes sense. What I was looking for was an example, a full and plain snippet from anywhere in a project, leaving nothing for me to imagine, not even a “myblock” or “myworkspace.” I was thinking that the workspace would be invoked, and as in this Blockly world I am not referencing a view or dialog or other window, I still am not sure when and how to get the workspace. Sometimes I do see how to get the workspace, such as when it’s being injected in index.js. But back to setValue(), from such a “real life” example I could extrapolate to event handlers and such. I am establishing a better footing these days.

Thank you for following up on my request.

Steve
Reply all
Reply to author
Forward
0 new messages