- Learn
- Tutorials
- Algorithms
- Cocktail Shaker Sort
- Appendices
- A Logic Reference
Appendix A — Logic Reference
Every Logic Component and Function in Picture Puzzle, as it is in the finished game. Each entry stands on its own: read what it does, see what it needs, and build it from its card into your own game. A card’s Shared Variables and Per Instance Variables are the values you can change. A Shared Variable holds one value for the whole Object, under Variables in its Properties. A Per Instance Variable holds one for each placement in the Scene.
A.1 Arrange Board
Built in Chapter 1, The Picture and the Board.
Lays out a whole new arrangement when it is asked: Reset puts the starting arrangement back, Shuffle makes a new one, and so does a new piece count or a new picture. Then it tells every Piece that the board was arranged.
Any Object- Variable
$message- Value
data('Messages', 'reset', 'words')
- Cooldown Key
"pieceSlide"- Seconds
0
- Custom Event
boardArranged
- Variable
$message- Value
""
- Cooldown Key
"pieceSlide"- Seconds
0
- Custom Event
boardArranged
- Custom Event
shuffleRequested
- Custom Event
shuffleRequested
A.3 Count Pieces Home (Function)
Built in Chapter 1, The Picture and the Board.
Counts the pieces that are home (a piece is home when its ID equals its slot's row index) and stores the count in $piecesHome, which the Board Caption shows.
- Variable
$piecesHome- Value
0
$gridSize * $gridSizetimesdata('Board Slots', local.index, 'piece') == local.index- Variable
$piecesHome- Operator
+=- Value
1
A.4 Exchange Slots (Function)
Built in Chapter 1, The Picture and the Board.
Trades the pieces of two slots of Board Slots. Every piece is still on the board exactly once afterwards. Slots are row indices, 0 for the top-left slot.
- Name
firstPiece- Value
0
- Variable
firstPiece- Value
data('Board Slots', firstSlot, 'piece')
- Table
Board Slots- Row
firstSlot- Column
"piece"- Value
data('Board Slots', secondSlot, 'piece')
- Table
Board Slots- Row
secondSlot- Column
"piece"- Value
firstPiece
A.5 Lay Out Slot
Built in Chapter 1, The Picture and the Board.
Places this Piece or Outline for the board's piece count: on its slot's center and sized to the slot when the slot is on the board, hidden when it is not. drawnSlotSide is the slot side, in screen pixels, that the Object fits at scale 1 (70, a slot of the 64-piece board).
Any Objectself.slotNumber- slotObject
self- drawnSlotSide
@self.drawnSlotSide
- slotObject
self- drawnSlotSide
@self.drawnSlotSide
A.6 Make Board
Built in Chapter 1, The Picture and the Board.
Makes the board when the game begins: a row of Board Slots for each slot, holding the starting arrangement, and on the screen an Outline with a Piece in front of it for each slot. The board is made once, for the largest piece count (the last row of Piece Counts); a smaller piece count uses its first slots and hides the rest (Lay Out Slot). The starting arrangement takes every fifth piece; a board where that would not hold each piece once (a piece count that is a multiple of 5, or a game that starts at a smaller count) starts with a Shuffle instead. slotCount is how many slots it makes; outline and piece are the Objects it makes.
Any Objectself.makeBoardData- Name
largestGridSize- Value
0
- Variable
largestGridSize- Value
data('Piece Counts', dataCount('Piece Counts') - 1, 'gridSize')
- Component Value
self.makeBoardData.slotCount- Value
largestGridSize * largestGridSize
self.makeBoardData.slotCounttimes- Action Name
addedRow- Table
Board Slots- Row
text("Slot ", local.index + 1)
- Table
Board Slots- Row
local.index- Column
"piece"- Value
(5 * local.index + 3) % self.makeBoardData.slotCount
- Table
Board Slots- Row
local.index- Column
"startPiece"- Value
data('Board Slots', local.index, 'piece')
- Custom Event
boardMade
$gridSize != largestGridSize || (self.makeBoardData.slotCount % 5) == 0- Custom Event
shuffleRequested
self.makeBoardData.slotCounttimes- Object to Create
@self.outline- X
0- Y
0- Created As
newOutline
- Variable
newOutline.slot- Value
local.index
- Applies to
newOutline- Custom Event
placedOnBoard
- Object to Create
@self.piece- X
0- Y
0- Created As
newPiece
- Variable
newPiece.slot- Value
local.index
- Applies to
newPiece- Custom Event
placedOnBoard
A.7 Pieces Home
Built in Chapter 1, The Picture and the Board.
Keeps $piecesHome, the count the Board Caption shows, equal to the number of pieces in their home slots.
Any ObjectA.8 Puzzle Commands
Built in Chapter 1, The Picture and the Board.
The keys ask for the same things as the Buttons: R for Reset, N for a new arrangement. Escape cancels a selection. Space asks the computer for one Step. A starts or pauses the computer's sort, and F opens the How it works panel.
Any Object- puzzleRules
@self.puzzleRules
- puzzleRules
@self.puzzleRules
- Custom Event
selectionCanceled
- puzzleRules
@self.puzzleRules
- puzzleRules
@self.puzzleRules
- puzzleRules
@self.puzzleRules
A.9 Request Reset (Function)
Built in Chapter 1, The Picture and the Board.
Asks Puzzle Rules to put the starting arrangement back. The Reset Button and the Reset Command both use it.
- Applies to
puzzleRules- Custom Event
resetRequested
A.10 Request Shuffle (Function)
Built in Chapter 1, The Picture and the Board.
Asks Puzzle Rules for a new random arrangement. The Shuffle Button and the New Arrangement Command both use it.
- Applies to
puzzleRules- Custom Event
shuffleRequested
A.11 Restore Start Arrangement (Function)
Built in Chapter 1, The Picture and the Board.
Puts every slot's starting piece (startPiece) back in the slot.
$gridSize * $gridSizetimes- Table
Board Slots- Row
local.index- Column
"piece"- Value
data('Board Slots', local.index, 'startPiece')
A.12 Show Piece
Built in Chapter 1, The Picture and the Board.
Shows the picture frame of the piece that Board Slots puts in this Piece's slot, cut for the chosen piece count. Make Board gives each Piece its slot in its Slot Number (0 is the top-left slot, counting right, then down).
Any Objectself.slotNumber- piece
self
- Frame
data('Board Slots', self.slotNumber.slot, 'piece')
- piece
self
- Frame
data('Board Slots', self.slotNumber.slot, 'piece')
- Frame
data('Board Slots', self.slotNumber.slot, 'piece')
- Frame
data('Board Slots', self.slotNumber.slot, 'piece')
A.13 Shuffle Board (Function)
Built in Chapter 1, The Picture and the Board.
Makes a new random arrangement with the game's random numbers and keeps it as the starting arrangement that Reset puts back. It is the Fisher-Yates shuffle: every arrangement is equally likely, and every piece stays on the board exactly once.
- Name
lastSlot- Value
0
$gridSize * $gridSizetimes- Table
Board Slots- Row
local.index- Column
"piece"- Value
local.index
$gridSize * $gridSize - 1times- Variable
lastSlot- Value
$gridSize * $gridSize - 1 - local.index
- Action Name
partner- Minimum
0- Maximum
lastSlot
- firstSlot
lastSlot- secondSlot
partner.value
$gridSize * $gridSizetimes- Table
Board Slots- Row
local.index- Column
"startPiece"- Value
data('Board Slots', local.index, 'piece')
A.14 Slot Center (Function)
Built in Chapter 1, The Picture and the Board.
Answers where the center of a slot lies on the screen, in screen pixels. A Screen UI Object is placed from the top-left corner of the screen with +Y up, so x counts right and y is negative below the top edge. The board is a square of boardSide pixels whose top-left corner is boardLeft from the left edge and boardTop from the top edge; gridSize slots fill each row.
- Name
slotSide- Value
0
- Name
column- Value
0
- Name
row- Value
0
- Name
centerX- Value
0
- Name
centerY- Value
0
- Variable
slotSide- Value
$boardSide / $gridSize
- Variable
column- Value
slot % $gridSize
- Variable
row- Value
floor(slot / $gridSize)
- Variable
centerX- Value
$boardLeft + (column + 0.5) * slotSide
- Variable
centerY- Value
-($boardTop + (row + 0.5) * slotSide)
- x
centerX- y
centerY
A.15 Choose Slot (Function)
Built in Chapter 2, Your Hands on the Board.
Tells Puzzle Rules that the player chose a slot, as a tap on a piece does. Keys 1 to 9 and Enter use it. A key also lets the player play, even while pieces slide.
- puzzleRules
puzzleRules
- Action Name
slideDone- Applies to
puzzleRules- Cooldown Key
"pieceSlide"
slideDone.value == true- Variable
$chosenSlot- Value
slot
- Applies to
puzzleRules- Custom Event
pieceChosen
A.16 Clear Selection (Function)
Built in Chapter 2, Your Hands on the Board.
Forgets the selected piece: the words "Choose another piece." leave the Message Line, and the Outlines are told.
- Variable
$selectedSlot- Value
-1
$message == data('Messages', 'selected', 'words')- Variable
$message- Value
""
- Custom Event
selectionChanged
A.17 Input Interruptions
Built in Chapter 2, Your Hands on the Board.
Cancels a selection and a press under way when the player's input is cut off: the game window lost focus, or a touch was cut off. Either way it sends selectionCanceled, as Escape does.
Any Object- Custom Event
selectionCanceled
- Custom Event
selectionCanceled
A.18 Keyboard Focus
Built in Chapter 2, Your Hands on the Board.
The keyboard plays like the pointer: keys 1 to 9 choose a slot, the arrow keys move a blue focus over the board, and Enter chooses the focused slot.
Any Object- puzzleRules
@self.puzzleRules- slot
0
- puzzleRules
@self.puzzleRules- slot
1
- puzzleRules
@self.puzzleRules- slot
2
- puzzleRules
@self.puzzleRules- slot
3
- puzzleRules
@self.puzzleRules- slot
4
- puzzleRules
@self.puzzleRules- slot
5
- puzzleRules
@self.puzzleRules- slot
6
- puzzleRules
@self.puzzleRules- slot
7
- puzzleRules
@self.puzzleRules- slot
8
- distance
-1
- distance
1
- distance
-$gridSize
- distance
$gridSize
$focusSlot >= 0- puzzleRules
@self.puzzleRules- slot
$focusSlot
A.19 Make Player Exchange (Function)
Built in Chapter 2, Your Hands on the Board.
The player's exchange: the pieces of two slots trade places, Moves counts it, the two pieces slide over slideSeconds, and every Piece is told.
- firstSlot
firstSlot- secondSlot
secondSlot
- Variable
$moves- Operator
+=- Value
1
- puzzleRules
puzzleRules- firstSlot
firstSlot- secondSlot
secondSlot- seconds
slideSeconds
- Custom Event
piecesExchanged
A.20 Move Focus (Function)
Built in Chapter 2, Your Hands on the Board.
Moves the keyboard focus by distance slots in reading order: 1 is one slot right, -1 one slot left, gridSize one row down. The focus stops at the first and the last slot of the board.
- Name
nextSlot- Value
0
$focusSlot == (-1)- Variable
$focusSlot- Value
0
- Variable
nextSlot- Value
$focusSlot + distance
nextSlot >= 0 && nextSlot < ($gridSize * $gridSize)- Variable
$focusSlot- Value
nextSlot
- Custom Event
selectionChanged
A.21 Picture Complete
Built in Chapter 2, Your Hands on the Board.
Sets the Game State: Solved once every piece is home, Playing while any piece is away from home.
Any Object$piecesHome == ($gridSize * $gridSize)- Game State
Solved
- Variable
$message- Value
data('Messages', 'solved', 'words')
- Game State
Playing
A.22 Piece Pointer
Built in Chapter 2, Your Hands on the Board.
Tells Puzzle Rules when the pointer is pressed on this Piece and when it is released on it. Puzzle Rules decides what the press and the release mean. While the How it works panel is open, the Piece tells nothing.
Any Objectself.slotNumber- Action Name
controlsOnAtPress- Input Context
Puzzle Controls
controlsOnAtPress.value == true- Variable
$chosenSlot- Value
self.slotNumber.slot
- Applies to
@self.puzzleRules- Custom Event
piecePressed
- Action Name
controlsOnAtRelease- Input Context
Puzzle Controls
controlsOnAtRelease.value == true- Variable
$chosenSlot- Value
self.slotNumber.slot
- Applies to
@self.puzzleRules- Custom Event
pieceReleased
A.23 Piece Press
Built in Chapter 2, Your Hands on the Board.
Follows one press of the pointer on a piece: released on the same piece it is a tap, released on another piece it is a drag, and released anywhere else it is forgotten. A press cut off (the game lost focus, or the touch was cut off) is forgotten too, when Input Interruptions sends selectionCanceled.
Any Object- Action Name
slideDone- Cooldown Key
"pieceSlide"
slideDone.value == true- Variable
$pressedSlot- Value
$chosenSlot
- Custom Event
selectionChanged
$pressedSlot >= 0$pressedSlot == $chosenSlot- Custom Event
pieceChosen
- Custom Event
piecesDropped
- Variable
$pressedSlot- Value
-1
- Custom Event
selectionChanged
- Event
On End Step- Mode
Release Seen
- Variable
$pressedSlot- Value
-1
- Custom Event
selectionChanged
- Event
On End Step- Mode
No Release
- Variable
$pressedSlot- Value
-1
- Custom Event
selectionChanged
A.24 Player Exchange
Built in Chapter 2, Your Hands on the Board.
The player exchanges two pieces: the first piece chosen is selected, the second one trades places with it (choosing the selected piece again cancels). A drag from one piece to another exchanges them at once. exchangeSlideSeconds is how long the two pieces of an exchange slide.
Any Object- Variable
$selectedSlot- Value
$chosenSlot
- Variable
$message- Value
data('Messages', 'selected', 'words')
- Event
On Piece Chosen- Mode
One Selected
- Custom Event
selectionChanged
$chosenSlot != $selectedSlot- firstSlot
$selectedSlot- secondSlot
$chosenSlot- puzzleRules
@self.puzzleRules- slideSeconds
@self.exchangeSlideSeconds
- Variable
$message- Value
""
- Event
On Piece Chosen- Mode
Nothing Selected
- firstSlot
$pressedSlot- secondSlot
$chosenSlot- puzzleRules
@self.puzzleRules- slideSeconds
@self.exchangeSlideSeconds
- Variable
$message- Value
""
- Event
On Piece Chosen- Mode
Nothing Selected
- Event
On Piece Chosen- Mode
Nothing Selected
- Event
On Piece Chosen- Mode
Nothing Selected
- Variable
$moves- Value
0
- Event
On Piece Chosen- Mode
Nothing Selected
A.25 Show Outline
Built in Chapter 2, Your Hands on the Board.
Colors this Outline whenever what it shows may have changed: the player's selection, focus or press, or the computer's compared pair and unsorted range, or who plays.
Any Objectself.slotNumber- outline
self
- outline
self
- outline
self
- outline
self
- outline
self
A.26 Check Board Valid (Function)
Built in Chapter 3, The Computer Compares.
Answers whether the board holds every piece ID exactly once, so the computer can sort it. isValid is true when it does.
- Type
Boolean- Name
isValid- Value
true
$gridSize * $gridSizetimes- Action Name
found- pieceId
local.index
found.value != 1- Variable
isValid- Value
false
- Value
isValid
A.27 Clear Sort (Function)
Built in Chapter 3, The Computer Compares.
Starts the computer's sort fresh: the counters go back to 0, no pair is shown as compared, and the next Step checks the board and begins a new forward pass.
- Variable
$comparisons- Value
0
- Variable
$swaps- Value
0
- Variable
$comparedSlot- Value
-1
- Custom Event
sortCleared
A.28 Color Outline (Function)
Built in Chapter 3, The Computer Compares.
Colors one Outline from what is shown on the board now: a settled slot is green, the keyboard focus and a pressed piece are blue, the selected piece is gold, the pair the computer compared last is amber, and every other Outline keeps the normal color. Green and amber are the computer's colors: they show only while the computer plays ($whoPlays).
slotNumberData StructureSlot Number- Name
outlineSlot- Value
0
- Variable
outlineSlot- Value
outline.slotNumber.slot
- Applies to
outline- Value
data('Outline Colors', 'normal', 'color')
$whoPlays == "Computer" && $comparedSlot >= 0 && outlineSlot < $rangeStart- Applies to
outline- Value
data('Outline Colors', 'settled', 'color')
$whoPlays == "Computer" && $comparedSlot >= 0 && outlineSlot > $rangeEnd- Applies to
outline- Value
data('Outline Colors', 'settled', 'color')
outlineSlot == $focusSlot || outlineSlot == $pressedSlot- Applies to
outline- Value
data('Outline Colors', 'focus', 'color')
outlineSlot == $selectedSlot- Applies to
outline- Value
data('Outline Colors', 'selected', 'color')
$whoPlays == "Computer" && $comparedSlot >= 0 && outlineSlot >= $comparedSlot && outlineSlot <= ($comparedSlot + 1)- Applies to
outline- Value
data('Outline Colors', 'compared', 'color')
A.29 Compare Next Pair (Function)
Built in Chapter 3, The Computer Compares.
One comparison of the computer: it reads the pieces of a slot and the slot to its right, and swaps them when the left piece's ID is larger. It counts the comparison and any swap, and tells the board.
- Variable
$comparisons- Operator
+=- Value
1
data('Board Slots', leftSlot, 'piece') > data('Board Slots', leftSlot + 1, 'piece')- firstSlot
leftSlot- secondSlot
leftSlot + 1
- Variable
$swaps- Operator
+=- Value
1
- puzzleRules
puzzleRules- firstSlot
leftSlot- secondSlot
leftSlot + 1- seconds
data('Sort Speeds', $speed, 'slideSeconds')
- Variable
$message- Value
data('Messages', 'swapped', 'words')
- Variable
$message- Value
data('Messages', 'kept', 'words')
- Variable
$comparedSlot- Value
leftSlot
- Custom Event
pairCompared
A.30 Computer Sort
Built in Chapter 3, The Computer Compares.
The computer's cocktail shaker sort, one comparison per Step. The first Step on a board checks it and begins a forward pass from the first slot. Passes then go back and forth over the unsorted range, which shrinks by one slot at the end of each pass, until every piece is home or a pass makes no swaps. When the sort is finished, or the board cannot be sorted, it sends sortEnded.
Any Objectself.computerSortData- Action Name
boardCheck
boardCheck.value == true- Variable
$rangeStart- Value
0
- Variable
$rangeEnd- Value
$gridSize * $gridSize - 1
- Component Value
self.computerSortData.swapsBeforePass- Value
$swaps
- leftSlot
$rangeStart- puzzleRules
@self.puzzleRules
- Event
On Step Requested- Mode
Forward Pass
- Custom Event
forwardPassStarted
- Variable
$message- Value
data('Messages', 'invalid', 'words')
- Custom Event
sortEnded
- leftSlot
$comparedSlot + 1- puzzleRules
@self.puzzleRules
($comparedSlot + 1) == $rangeEnd- Variable
$rangeEnd- Operator
-=- Value
1
- Action Name
forwardPassEnd- swapsBeforePass
self.computerSortData.swapsBeforePass
forwardPassEnd.value == false- Event
On Step Requested- Mode
Finished
- Custom Event
sortEnded
- Custom Event
passFinished
forwardPassEnd.value == true- Event
On Step Requested- Mode
Backward Pass
- Custom Event
backwardPassStarted
- Component Value
self.computerSortData.swapsBeforePass- Value
$swaps
- leftSlot
$comparedSlot - 1- puzzleRules
@self.puzzleRules
$comparedSlot == $rangeStart- Variable
$rangeStart- Operator
+=- Value
1
- Action Name
backwardPassEnd- swapsBeforePass
self.computerSortData.swapsBeforePass
backwardPassEnd.value == false- Event
On Step Requested- Mode
Finished
- Custom Event
sortEnded
- Custom Event
passFinished
backwardPassEnd.value == true- Event
On Step Requested- Mode
Forward Pass
- Custom Event
forwardPassStarted
- Component Value
self.computerSortData.swapsBeforePass- Value
$swaps
- Event
On Step Requested- Mode
Fresh
- Event
On Step Requested- Mode
Fresh
$piecesHome == ($gridSize * $gridSize)- Event
On Step Requested- Mode
Finished
- Custom Event
sortEnded
A.31 Count Piece Copies (Function)
Built in Chapter 3, The Computer Compares.
Answers how many slots of the board hold one piece ID. On a sound board the answer is always 1.
- Name
copies- Value
0
$gridSize * $gridSizetimesdata('Board Slots', local.index, 'piece') == pieceId- Variable
copies- Operator
+=- Value
1
- Value
copies
A.32 Request Step (Function)
Built in Chapter 3, The Computer Compares.
Asks Puzzle Rules to pause a running sort, then for one Step of the computer's sort once no piece is sliding. The Step Button and the Step Command (Space) both use it.
- Applies to
puzzleRules- Custom Event
pauseRequested
- Action Name
slideDone- Applies to
puzzleRules- Cooldown Key
"pieceSlide"
slideDone.value == true- Applies to
puzzleRules- Custom Event
stepRequested
A.33 Finish Sort Pass (Function)
Built in Chapter 4, The Way Back.
Ends one pass of the computer's sort, after the unsorted range has moved in by one slot. When the pass made no swaps, the range has no pair left to compare, or every piece is home, the sort is finished: sortGoesOn answers false. Otherwise it answers true so Computer Sort can begin the next pass.
- Type
Boolean- Name
sortGoesOn- Value
true
$swaps == swapsBeforePass || $rangeStart >= $rangeEnd || $piecesHome == ($gridSize * $gridSize)- Variable
sortGoesOn- Value
false
- Variable
sortGoesOn- Value
true
- Value
sortGoesOn
A.34 Choose Picture
Built in Chapter 5, The Finished Puzzle.
Clicking or tapping a Picture Button makes its picture the one the board shows: $picture becomes the Button's row of Pictures, and a new arrangement is shuffled. Each placement sets its picture (a row of Pictures) and its Sprite. While the How it works panel is open, the Button does nothing.
Any Object- Action Name
puzzleControlsOn- Input Context
Puzzle Controls
puzzleControlsOn.value == true- picture
self.picture
A.35 Choose Piece Count
Built in Chapter 5, The Finished Puzzle.
Clicking or tapping a Count Button makes its piece count the board's: $gridSize becomes the count's gridSize, and a new arrangement of that size is shuffled. Each placement sets its count (a row of Piece Counts) and its text. While the How it works panel is open, the Button does nothing.
Any Object- Action Name
puzzleControlsOn- Input Context
Puzzle Controls
puzzleControlsOn.value == true- Variable
$gridSize- Value
data('Piece Counts', self.pieceCount, 'gridSize')
- Custom Event
pieceCountChosen
A.36 Choose Piece Sprite (Function)
Built in Chapter 5, The Finished Puzzle.
Gives a Piece the Sprite of the chosen picture cut for the chosen piece count: Piece Counts names the column of Pictures for the board's gridSize, and $picture names the row.
- Name
countRow- Value
0
- Type
Text- Name
piecesColumn
- Variable
countRow- Value
dataFind('Piece Counts', 'gridSize', $gridSize)
countRow >= 0- Variable
piecesColumn- Value
data('Piece Counts', countRow, 'piecesColumn')
- Applies to
piece- Sprite
data('Pictures', $picture, piecesColumn)
A.37 Choose Speed
Built in Chapter 5, The Finished Puzzle.
Clicking or tapping a Speed Button makes its speed the chosen one. Each placement sets its speed (a row of Sort Speeds) and its text. While the How it works panel is open, the Button does nothing.
Any Object- Action Name
puzzleControlsOn- Input Context
Puzzle Controls
puzzleControlsOn.value == true- Variable
$speed- Value
self.speed
- Custom Event
speedChosen
A.38 Close Lesson
Built in Chapter 5, The Finished Puzzle.
Clicking or tapping the Close Button asks Puzzle Rules to close the How it works panel.
Any Object- Applies to
@self.puzzleRules- Custom Event
lessonCloseRequested
A.39 Close Lesson Panel (Function)
Built in Chapter 5, The Finished Puzzle.
Closes the How it works panel: the Lesson Panel Controls go off and the Puzzle Controls on again, and the panel's parts are told (lessonToggled).
- Input Context
Lesson Panel Controls- Active
false
- Input Context
Puzzle Controls
- Custom Event
lessonToggled
A.40 Hide Focus (Function)
Built in Chapter 5, The Finished Puzzle.
Hides the keyboard focus ($focusSlot -1), and tells the Outlines.
- Variable
$focusSlot- Value
-1
- Custom Event
selectionChanged
A.41 Lay Out One Slot (Function)
Built in Chapter 5, The Finished Puzzle.
Lays out one Piece or Outline for the board's piece count: a slot on the board is shown at its center and sized to the slot; a slot beyond the piece count is hidden, so it shows nothing and answers no input. drawnSlotSide is the slot side, in screen pixels, that the Object fits at scale 1.
slotNumberData StructureSlot Number- Name
slotSide- Value
0
slotObject.slotNumber.slot < ($gridSize * $gridSize)- Applies to
slotObject- Visible
true
- Action Name
center- slot
slotObject.slotNumber.slot
- Applies to
slotObject- Position Relative To
Screen- X
center.x- Y
center.y
- Variable
slotSide- Value
$boardSide / $gridSize
- Applies to
slotObject- Horizontal Scale
slotSide / drawnSlotSide- Vertical Scale
slotSide / drawnSlotSide
- Applies to
slotObject- Visible
false
A.42 Lesson Lines
Built in Chapter 5, The Finished Puzzle.
Keeps the words of the How it works panel's two lines about the computer's sort up to date: the pass it is in ($lessonPass) and what its last comparison did ($lessonOutcome).
Any Object- Variable
$lessonOutcome- Value
$message
- Variable
$lessonPass- Value
data('Messages', 'forwardPass', 'words')
- Variable
$lessonPass- Value
data('Messages', 'backwardPass', 'words')
A.43 Lesson Panel Switch
Built in Chapter 5, The Finished Puzzle.
Opens the How it works panel when it is asked, and closes it on Close, F or Escape. While the panel is open the computer is stopped and only the Lesson Panel Controls are on, so the puzzle answers no key, Button or piece.
Any Object- Custom Event
selectionCanceled
- Input Context
Puzzle Controls- Active
No
- Input Context
Lesson Panel Controls
- Custom Event
lessonToggled
A.44 Let Computer Play (Function)
Built in Chapter 5, The Finished Puzzle.
The computer takes over from the player: $whoPlays becomes Computer, a half-done selection ends, and the Outlines are told (whoPlaysChanged). When the computer is already playing, nothing changes.
$whoPlays == "Player"- Variable
$whoPlays- Value
'Computer'
- Applies to
puzzleRules- Custom Event
clearSelectionRequested
- Custom Event
whoPlaysChanged
A.45 Let Player Play (Function)
Built in Chapter 5, The Finished Puzzle.
The player takes over from the computer: $whoPlays becomes Player, a running sort pauses where it is, and the Outlines are told (whoPlaysChanged). When the player is already playing, nothing changes.
$whoPlays == "Computer"- Variable
$whoPlays- Value
'Player'
- Applies to
puzzleRules- Custom Event
pauseRequested
- Custom Event
whoPlaysChanged
A.46 Request Lesson (Function)
Built in Chapter 5, The Finished Puzzle.
Asks Puzzle Rules to open the How it works panel. The How it works Button and the How It Works Command (F) both use it.
- Applies to
puzzleRules- Custom Event
lessonRequested
A.47 Request Sort (Function)
Built in Chapter 5, The Finished Puzzle.
Asks Puzzle Rules to start the computer's sort, or to pause it while it runs. The Sort Button and the Run or Pause Command (A) both use it.
- Applies to
puzzleRules- Custom Event
sortRequested
A.48 Request Upload (Function)
Built in Chapter 5, The Finished Puzzle.
Asks Puzzle Rules to let the player choose a picture of their own. The Upload Button uses it.
- Applies to
puzzleRules- Custom Event
uploadRequested
A.49 Show Count Underline
Built in Chapter 5, The Finished Puzzle.
Shows this underline under the chosen piece count's Button only. Each placement sets the count it stands for.
Any Object- underline
self- pieceCount
self.pieceCount
- underline
self- pieceCount
self.pieceCount
A.50 Show If Lesson Open (Function)
Built in Chapter 5, The Finished Puzzle.
Shows one part of the How it works panel while the panel is open (the Lesson Panel Controls are on), and hides it otherwise.
- Action Name
lessonOpen- Input Context
Lesson Panel Controls
lessonOpen.value == true- Applies to
part- Visible
true
- Applies to
part- Visible
false
A.51 Show If Sort Under Way (Function)
Built in Chapter 5, The Finished Puzzle.
Shows one line about the computer's sort while the How it works panel is open and the sort is under way, and hides it otherwise. Before the first comparison on a board ($comparedSlot is -1) the line has nothing to tell yet.
- Action Name
lessonOpen- Input Context
Lesson Panel Controls
lessonOpen.value == true && $comparedSlot >= 0- Applies to
line- Visible
true
- Applies to
line- Visible
false
A.52 Show Picture
Built in Chapter 5, The Finished Puzzle.
Shows the chosen picture whole ($picture's preview in Pictures). The Picture Preview and the Whole Picture both use it.
Any Object- Sprite
data('Pictures', $picture, 'preview')
- Sprite
data('Pictures', $picture, 'preview')
A.53 Show Sort Lines
Built in Chapter 5, The Finished Puzzle.
Shows this line about the computer's sort while the How it works panel is open and the sort is under way, in front of the game. The Lesson State and the Lesson Result use it.
Any Object- Depth Amount
200
- line
self
- line
self
- line
self
- line
self
A.54 Show Speed Underline
Built in Chapter 5, The Finished Puzzle.
Shows this underline under the chosen speed's Button only. Each placement sets the speed it stands for.
Any Object- underline
self- speed
self.speed
- underline
self- speed
self.speed
A.55 Show Whole Picture
Built in Chapter 5, The Finished Puzzle.
Shows the whole picture, without the gaps between the pieces, once every piece is home and no piece is sliding.
Any Object- picture
self- puzzleRules
@self.puzzleRules
- picture
self- puzzleRules
@self.puzzleRules
- picture
self- puzzleRules
@self.puzzleRules
- picture
self- puzzleRules
@self.puzzleRules
A.56 Show With Lesson Panel
Built in Chapter 5, The Finished Puzzle.
Shows this part of the How it works panel only while the panel is open, in front of the game. The panel, its title, its lines and its Close Button use it.
Any Object- Depth Amount
200
- part
self
- part
self
A.57 Slide Piece
Built in Chapter 5, The Finished Puzzle.
Slides this Piece onto its slot when its slot was one of the two in a slide: it starts at the other slot and moves in a straight line to its own over slideSeconds, then stands exactly on its slot. While the Piece slides, only this Logic moves it.
Any Objectself.slotNumberself.slidePieceDataself.slotNumber.slot == $slideFrom || self.slotNumber.slot == $slideTo- Component Value
self.slidePieceData.otherSlot- Value
$slideFrom
self.slotNumber.slot == $slideFrom- Component Value
self.slidePieceData.otherSlot- Value
$slideTo
- Action Name
start- slot
self.slidePieceData.otherSlot
- Position Relative To
Screen- X
start.x- Y
start.y
- Depth Amount
1
- Action Name
home- slot
self.slotNumber.slot
- Value
self.transform- Property
position.x- Target
home.x- Duration
$slideSeconds
- Value
self.transform- Property
position.y- Target
home.y- Duration
$slideSeconds
- Event
Every Step- Mode
Sliding
- Action Name
slideDone- Applies to
@self.puzzleRules- Cooldown Key
"pieceSlide"
slideDone.value == true- Depth Amount
0
- Event
Every Step- Mode
Resting
- Custom Event
slideEnded
- Depth Amount
0
- Event
Every Step- Mode
Resting
A.58 Slide Pieces (Function)
Built in Chapter 5, The Finished Puzzle.
Shows two slots trading pieces as a slide: each of the two pieces starts at the other slot and moves to its own over seconds. The board has already changed; the slide only shows it. While the pieceSlide cooldown of Puzzle Rules runs, new moves wait.
- Variable
$slideFrom- Value
firstSlot
- Variable
$slideTo- Value
secondSlot
- Variable
$slideSeconds- Value
seconds
- Applies to
puzzleRules- Cooldown Key
"pieceSlide"- Seconds
seconds
- Custom Event
slideStarted
A.59 Sort Timer
Built in Chapter 5, The Finished Puzzle.
Runs the computer's sort by itself: Sort lets the computer play and starts the pictureSort timer, and every ring of the timer asks Computer Sort for Steps at the chosen speed. Sort again, a Step, the player taking over, a player exchange, Reset, Shuffle, Escape or opening the How it works panel pauses it, and it stops when the sort has ended. The board, the pass and the counters are kept.
Any Object- Event
On Sort Requested- Mode
Stopped
- Event
On Speed Chosen- Mode
Stopped
- puzzleRules
@self.puzzleRules
$piecesHome < ($gridSize * $gridSize)- puzzleRules
@self.puzzleRules
- Variable
$message- Value
""
- Event
On Sort Requested- Mode
Running
- Event
On Speed Chosen- Mode
Running
- puzzleRules
@self.puzzleRules
- Event
On Sort Requested- Mode
Stopped
- Event
On Speed Chosen- Mode
Stopped
- puzzleRules
@self.puzzleRules
- Variable
$message- Value
data('Messages', 'paused', 'words')
- Event
On Sort Requested- Mode
Running
- Event
On Speed Chosen- Mode
Running
- puzzleRules
@self.puzzleRules
data('Sort Speeds', $speed, 'comparisonsPerTick')times- Action Name
slideDone- Cooldown Key
"pieceSlide"
$piecesHome < ($gridSize * $gridSize) && slideDone.value == true- Custom Event
stepRequested
- Event
On Sort Requested- Mode
Stopped
- Event
On Speed Chosen- Mode
Stopped
- puzzleRules
@self.puzzleRules
- Event
On Sort Requested- Mode
Stopped
- Event
On Speed Chosen- Mode
Stopped
- puzzleRules
@self.puzzleRules
- Event
On Sort Requested- Mode
Stopped
- Event
On Speed Chosen- Mode
Stopped
- puzzleRules
@self.puzzleRules
- Event
On Sort Requested- Mode
Stopped
- Event
On Speed Chosen- Mode
Stopped
- puzzleRules
@self.puzzleRules
- Event
On Sort Requested- Mode
Stopped
- Event
On Speed Chosen- Mode
Stopped
- puzzleRules
@self.puzzleRules
A.60 Start Sort Timer (Function)
Built in Chapter 5, The Finished Puzzle.
Starts the pictureSort timer at the chosen speed (or starts it again at a new speed) and makes the Sort Button read Pause.
- Applies to
puzzleRules- Timer Name
"pictureSort"- Repeat Every (s)
data('Sort Speeds', $speed, 'intervalSeconds')
- Variable
$sortButtonLabel- Value
data('Messages', 'pauseButton', 'words')
A.61 Stop Sort Timer (Function)
Built in Chapter 5, The Finished Puzzle.
Stops the pictureSort timer and makes the Sort Button read Sort. The board, the pass and the counters stay as they are.
- Applies to
puzzleRules- Timer Name
"pictureSort"
- Variable
$sortButtonLabel- Value
data('Messages', 'sortButton', 'words')
A.62 Underline Chosen Count (Function)
Built in Chapter 5, The Finished Puzzle.
Shows one piece-count underline when its count is the board's, and hides it otherwise.
data('Piece Counts', pieceCount, 'gridSize') == $gridSize- Applies to
underline- Visible
true
- Applies to
underline- Visible
false
A.63 Underline Chosen Speed (Function)
Built in Chapter 5, The Finished Puzzle.
Shows one speed underline when its speed is the chosen one, and hides it otherwise.
speed == $speed- Applies to
underline- Visible
true
- Applies to
underline- Visible
false
A.64 Update Whole Picture (Function)
Built in Chapter 5, The Finished Puzzle.
Shows the whole picture over the board when the picture is complete (Game State Solved) and no piece is sliding, and hides it otherwise.
- Action Name
isSolved- Game State
Solved
- Action Name
slideDone- Applies to
puzzleRules- Cooldown Key
"pieceSlide"
isSolved.value == true && slideDone.value == true- Applies to
picture- Visible
true
- Applies to
picture- Visible
false
A.65 Upload Picture
Built in Chapter 5, The Finished Puzzle.
Lets the player rebuild a picture of their own. Upload opens the file chooser; a PNG, JPEG, WebP or AVIF picture up to 25 MB is cut to a square from its middle and becomes the picture the board shows, for this session only, with a new arrangement. A picture that cannot be opened changes nothing but the message; canceling changes nothing.
Any Object- Java Script
const host=window.__mythBabylon,scene=host&&host.controller;
- Action Name
lessonOpenAtUpload- Input Context
Lesson Panel Controls
lessonOpenAtUpload.value == true- Custom Event
lessonCloseRequested
- picture
"Uploaded"
- Variable
$message- Value
data('Messages', 'uploaded', 'words')
- Variable
$message- Value
data('Messages', 'uploadFailed', 'words')
A.66 Use Picture (Function)
Built in Chapter 5, The Finished Puzzle.
Makes a row of Pictures the picture the board shows: $picture becomes that row, and everyone who shows the picture is told (pictureChosen). Arrange Board then shuffles a new arrangement of it.
- Variable
$picture- Value
picture
- Custom Event
pictureChosen
A.67 Who Plays
Built in Chapter 5, The Finished Puzzle.
Hands the game to the player or to the computer ($whoPlays): H and a press on a piece let the player play, and C and a comparison of the computer let the computer play. Keys that choose a piece let the player play through Choose Slot, and Sort through Sort Timer. The board never changes when who plays changes.
Any Object- puzzleRules
@self.puzzleRules
- puzzleRules
@self.puzzleRules
- puzzleRules
@self.puzzleRules
- puzzleRules
@self.puzzleRules
