Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcast vars #42

Merged
merged 7 commits into from
May 28, 2017
Merged

Broadcast vars #42

merged 7 commits into from
May 28, 2017

Conversation

towerofnix
Copy link
Owner

I can't remember the status of this but I think it's mostly finished. Scrap is essentially abandoned/finished anyways; may as well merge in one of the main features that makes it worth using.

These are basically custom blocks with a special prefix ("$$SCRAP:")
that get disguised as different blocks. Their procedure definitions
don't appear in the scripting area or script explorer.

Fun fact/misfeature: you can right-click on library blocks and get
access to the usual "define" block, letting you access the block's
code from your normal project! This is kind of interesting and does
inspire things like real modules (..ha..ha..). In order to consider
this a real feature I'll need to prevent those custom blocks from
being edited.

Also, this commit is S U P E R  C O N T R O V E R S I A L, because
the current only langauge block dynamically sets a variable using a
HACKED BLOCK! Which is somewhat against the idea of Scrap entirely.
But that's why this is on a different branch.

PS, of course, language blocks work in normal Scratch. They're only
*displayed* differently, they're not actual new blocks.

----

Scratch code changes:

* New constants, Specs.MAGIC_PROC_PREFIX ("$$SCRAP") and
  Specs.MAGIC_PROC_HUMAN ("(Scrap)")

* If the start of a block label is MAGIC_PROC_PREFIX, it will be
  replaced with MAGIC_PROC_HUMAN.

* Converted PaletteBuilder.as into normal whitespace instead of
  tabs, for convenience

* Added new "add library" button to More Blocks palette
  * Placed after normal custom blocks, before extensions
  * Adds blocks from the "Scrap library", through a new
    addJSONScripts ScratchObj method

* Added new "visibleScripts" method to ScratchObj
  * Returns scripts that should be visible for editing
  * "Visible" means all scripts, excluding procedures whose
    definitions start with MAGIC_PROC_PREFIX
  * Used anywhere obj.scripts would be looped through in
    relation to displaying blocks (i.e. script browser, script
    pane)

* Added new "magicProcedureDefinitions" method to ScratchObj
  * Returns the procedure definitions for library blocks
  * Includes only procedure definitions whose definitions start
    with MAGIC_PROC_PREFIX

* Edited procedureDefinitions method to not include library block
  procedure defintions

* Made variables that start with the text '$$broadcast' hidden
  in the block palette
  * To be continued further

* Added new addJSONScripts to ScratchObj
  * Adds scripts from script entries, following the format found in
    project.json files
    * [x, y, stack]
  * Used by instantiateFromJSON and PaletteBuilder's addScrapLibrary
This commit finishes the broadcast variables UI/blocks part of
broadcast variables. (Well, I guess that's all of it, since this
mod doesn't change anything in the runtime..)

-----

* Added new broadcastVar menu
  * Gets all the broadcast variables of a specific broadcast message
    * Message gotten from block's first input
  * Has 'new variable' option
    * Opens a broadcast variable maker dialog, similar to the
      variable maker dialog
  * Used in 'set broadcast var' block, part of Scrap library

* Updated 'set broadcast var' library block
  * Block spec now uses broadcast-specific menus instead of text
    inputs

* Added new collectBroadcastVarNames method to ScratchStage
  * Gets global/stage variables that have a name following format
    BROADCAST_VAR_PREFIX + msg + '>' + (some name)
  * Used in broadcastVar menu
  * Should be used in PaletteBuilder (TODO)

* Fixed duplicate variable 'b:Block' warning
* Added missing semicolon
When you open a sprite, the palette was updated *before* its scripts
were viewed, making the palette still think another script was viewed.

This fixes the issue by updating the palette *after* the scripts are
viewed in the script pane, rather than before.
This simplifies PaletteBuilder's broadcast variable code quite
significantly, removing redundant code.

It also updates collectBroadcastVarName's return format, and
changes the code in the broadcast variable menu accordingly.
This is just so that a new broadcast variable will appear in
the data palette as soon as you make it.
@towerofnix towerofnix merged commit ed374ca into master May 28, 2017
@towerofnix
Copy link
Owner Author

ah, if the world breaks, um, git reset

@towerofnix towerofnix deleted the broadcast-vars branch August 16, 2017 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant