scratch


Fields

Here are the fields provided by this builtin:

Field name Field description
backdrop.name The name of the current backdrop
backdrop.number The costume number of the current backdrop
answer The answer given by the user to a scratch.ask(...) query
mouse_down If the left mouse button is clicked or the screen is touched
mouse_x The current X position of the mouse or finger on the screen
mouse_y The current Y position of the mouse or finger on the screen
loudness The current input volume of the microphone as a percentage
username The detected username of the user running the project

Methods

Here are the methods provided by this builtin that should be used in an expression rather than as a statement:

Method name Method parameters Method description
key_pressed key Returns whether or not key is currently pressed
get_attribute attribute, target Returns the attribute attribute of target

Possible values for key:

  • Any character in the range U+0021 to U+007E
  • C.SPACE
  • C.ENTER
  • C.UP_ARROW
  • C.DOWN_ARROW
  • C.LEFT_ARROW
  • C.RIGHT_ARROW

Possible values for attribute:

  • C.VOLUME
  • If target is the stage:
    • C.BACKDROP_NAME
    • C.BACKDROP_NUMBER
  • Otherwise:
    • C.X_POSITION
    • C.Y_POSITION
    • C.DIRECTION
    • C.COSTUME_NUMBER
    • C.COSTUME_NAME
    • C.SIZE

Possible values for target:

  • C.STAGE
  • Any sprite name

Here are the methods provided by this builtin that should be used as a statement rather than in an expression:

Method name Method parameters Method description
stop mode Stops a certain aspect of the project according to mode
ask query Asks query with a message box and waits for the user’s response, stored in scratch.answer
broadcast broadcast, [message] Broadcasts broadcast to the project with an optional message
broadcast_and_wait broadcast, [message] Broadcasts broadcast to the project with an optional message and waits for all listeners to finish running
clone [target] Creates a clone of the current sprite or another one
delete_clone None Deletes the clone this method is ran on

Possible values for mode:

  • C.ALL
  • C.OTHER_SCRIPTS
  • C.THIS_SCRIPT

Possible values for message:

  • Anything except a list

Possible values for target:

  • C.MYSELF (default for when called without any arguments)
  • Any sprite name