- Learn
- Tutorials
- Algorithms
- Dijkstra’s Algorithm
- Appendices
- A Logic Reference
Appendix A — Logic Reference
Every Logic Component and Function in Weighted Maze, 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 Cell Picture (Function)
Built in Chapter 1, The Map and the Sidebar.
Which Terrain Tiles picture one cell shows. A cell shows its terrain, found by its cost in Terrains; a cost that no terrain lists is drawn as Road. The Camp and the Tower show their own pictures (Maze Layout campFrame and towerFrame) unless they are painted as Wall.
- Name
cost- Value
0
- Name
terrainRow- Value
-1
- Name
frame- Value
0
- Variable
cost- Value
data('Maze Cells', cell, 'cost')
- Variable
terrainRow- Value
dataFind('Terrains', 'cost', cost)
terrainRow >= 0- Variable
frame- Value
data('Terrains', terrainRow, 'frame')
- Variable
frame- Value
data('Terrains', 'Road', 'frame')
cell == data('Maze Settings', 'rules', 'startCell') && cost != data('Terrains', 'Wall', 'cost')- Variable
frame- Value
data('Maze Layout', 'board', 'campFrame')
cell == data('Maze Settings', 'rules', 'goalCell') && cost != data('Terrains', 'Wall', 'cost')- Variable
frame- Value
data('Maze Layout', 'board', 'towerFrame')
- Value
frame
A.2 Cell Screen Position (Function)
Built in Chapter 1, The Map and the Sidebar.
Where one cell's center is on the screen, in screen pixels. Cells count in reading order: Cell 00 is the top-left cell, and the numbers grow to the right, then down (a row holds Maze Settings columns cells). Maze Layout says where Cell 00 is and how far apart the cells are. x is measured right from the left edge of the screen; y is measured up from the top edge, so a cell below the top has a negative y, as Set Position takes it for a Screen UI Object anchored at the top-left corner.
- Name
column- Value
0
- Name
row- Value
0
- Name
right- Value
0
- Name
down- Value
0
- Variable
column- Value
cell % data('Maze Settings', 'rules', 'columns')
- Variable
row- Value
floor(cell / data('Maze Settings', 'rules', 'columns'))
- Variable
right- Value
column * data('Maze Layout', 'board', 'spacing')
- Variable
right- Operator
+=- Value
data('Maze Layout', 'board', 'originX')
- Variable
down- Value
row * data('Maze Layout', 'board', 'spacing')
- Variable
down- Operator
+=- Value
data('Maze Layout', 'board', 'originY')
- x
right- y
-down
A.3 Lay Out Map
Built in Chapter 1, The Map and the Sidebar.
Lays out the map when the Scene starts: for each row of Maze Cells it creates a Map Cell and a Search Outline, gives each the cell number (its Map Place cell) and tells it, with placedOnMap, that it is placed; the piece then stands on its cell and shows itself. mapCell and searchOutline are the Objects it makes.
Any ObjectdataCount('Maze Cells')times- Object to Create
@self.mapCell- X
0- Y
0- Created As
newCell
- Variable
newCell.cell- Value
local.index
- Applies To
newCell- Custom Event
placedOnMap
- Object to Create
@self.searchOutline- X
0- Y
0- Created As
newOutline
- Variable
newOutline.cell- Value
local.index
- Applies To
newOutline- Custom Event
placedOnMap
A.4 Reset Trial
Built in Chapter 1, The Map and the Sidebar.
Puts the trial in its Ready state, keeping the terrain, with the Function Clear Trial: when the Scene starts, when the learner presses Reset (the Reset Command, R in the Input Manager) or the Reset button (resetRequested), and whenever a cell's terrain changes (terrainChanged), so a search never mixes two maps.
Maze Rules- rules
self
- rules
self
- rules
self
- rules
self
A.5 Show Selection
Built in Chapter 1, The Map and the Sidebar.
Keeps the Selection, the ring around the cell the keyboard will paint, on the selected cell (the Project Global selectedCell). The Selection starts on the Camp (Maze Settings startCell).
Any Object- Variable
$selectedCell- Value
data('Maze Settings', 'rules', 'startCell')
- Action Name
campPosition- cell
$selectedCell
- Position Relative To
Screen- X
campPosition.x- Y
campPosition.y
- Action Name
cellPosition- cell
$selectedCell
- Position Relative To
Screen- X
cellPosition.x- Y
cellPosition.y
A.6 Change Terrain
Built in Chapter 2, Paint the Maze.
Changes the terrain of the selected cell when the learner paints it: with a click or a touch on a cell (paintRequested, sent by the cell), or with the Paint Command (Enter in the Input Manager).
Any ObjectA.7 Choose Brush (Function)
Built in Chapter 2, Paint the Maze.
Makes one terrain the brush, the terrain the learner paints with. terrain must be a row of Terrains (Road, Forest, Mud or Wall); a name Terrains does not list leaves the brush as it is.
- Action Name
isKnownTerrain- Table
"Terrains"- Row
terrain
isKnownTerrain.value == true- Variable
$brush- Value
terrain
A.8 Choose Terrain
Built in Chapter 2, Paint the Maze.
One terrain the learner can paint with. The button shows the terrain's name and, unless it is a Wall, what entering it costs (from Terrains); activating it makes that terrain the brush, and the button is highlighted while it is. Each Terrain Button placement sets terrain, a row of Terrains (Road, Forest, Mud or Wall). chosenTint and plainTint are the button colors with and without the highlight.
Any Objectself.chooseTerrainDataText / UISprite- Action Name
isKnownTerrain- Table
"Terrains"- Row
self.terrain
isKnownTerrain.value == true- Component Value
self.chooseTerrainData.label- Value
self.terrain
data('Terrains', self.terrain, 'cost') >= 0- Component Value
self.chooseTerrainData.label- Value
self.terrain + " " + data('Terrains', self.terrain, 'cost')
- Component Value
self.text.text- Value
self.chooseTerrainData.label
- button
self- terrain
self.terrain- chosenTint
@self.chosenTint- plainTint
@self.plainTint
- terrain
self.terrain
- button
self- terrain
self.terrain- chosenTint
@self.chosenTint- plainTint
@self.plainTint
A.9 Choose Terrain By Key
Built in Chapter 2, Paint the Maze.
Lets the keyboard choose the brush: Choose Road, Choose Forest, Choose Mud and Choose Wall (keys 1, 2, 3 and 4 in the Input Manager) each make their terrain the brush.
Any Object- terrain
Road
- terrain
Forest
- terrain
Mud
- terrain
Wall
A.10 Choose Terrain By Picture
Built in Chapter 2, Paint the Maze.
Shows the Terrain Tiles picture of one terrain beside its button (Terrains frame); activating the picture makes that terrain the brush, as its button does. Each Terrain Preview placement sets terrain, a row of Terrains (Road, Forest, Mud or Wall).
Any Object- Action Name
isKnownTerrain- Table
"Terrains"- Row
self.terrain
isKnownTerrain.value == true- Frame
data('Terrains', self.terrain, 'frame')
- terrain
self.terrain
A.11 Find Grid Neighbor (Function)
Built in Chapter 2, Paint the Maze.
The cell next to one cell in one direction (a row of Directions: Up, Right, Down or Left), or -1 when that side of the cell is the edge of the map. Cells count as Cell Screen Position counts them: Cell 00 is the top-left cell, and a row holds Maze Settings columns cells.
- Name
column- Value
0
- Name
row- Value
0
- Name
neighbor- Value
-1
- Variable
column- Value
cell % data('Maze Settings', 'rules', 'columns')
- Variable
row- Value
floor(cell / data('Maze Settings', 'rules', 'columns'))
- Variable
column- Operator
+=- Value
data('Directions', direction, 'columnStep')
- Variable
row- Operator
+=- Value
data('Directions', direction, 'rowStep')
column >= 0 && column < data('Maze Settings', 'rules', 'columns') && row >= 0 && row < data('Maze Settings', 'rules', 'rows')- Variable
neighbor- Value
row * data('Maze Settings', 'rules', 'columns')
- Variable
neighbor- Operator
+=- Value
column
- Variable
neighbor- Value
-1
- Value
neighbor
A.12 Highlight Terrain Choice (Function)
Built in Chapter 2, Paint the Maze.
Colors one Terrain Button: chosenTint while its terrain is the brush, plainTint otherwise.
spriteSpriteterrain == $brush- Applies To
button- Value
chosenTint
- Applies To
button- Value
plainTint
A.13 Move Selection
Built in Chapter 2, Paint the Maze.
Lets the arrow keys move the Selection: each direction of the Move Selection Command (the arrow keys in the Input Manager) moves it one cell up, right, down or left. At the edge of the map it stays.
Any Object- direction
Up
- direction
Right
- direction
Down
- direction
Left
A.14 Paint Map Cell
Built in Chapter 2, Paint the Maze.
One cell of the map the learner can paint. It shows the picture its cost calls for, and draws its picture again whenever the terrain changes. Activating it (a click or a touch) selects it and asks Maze Rules to paint it with the brush. Its cell number is its Map Place cell, which Lay Out Map gives it.
Any Objectself.mapPlace- Action Name
place- cell
self.mapPlace.cell
- Position Relative To
Screen- X
place.x- Y
place.y
- Action Name
picture- cell
self.mapPlace.cell
- Frame
picture.value
- Variable
$selectedCell- Value
self.mapPlace.cell
- Custom Event
paintRequested
- Action Name
newPicture- cell
self.mapPlace.cell
- Frame
newPicture.value
A.15 Paint Selected Cell (Function)
Built in Chapter 2, Paint the Maze.
Paints the selected cell (the Project Global selectedCell) with the brush: its cost in Maze Cells becomes the brush terrain's cost from Terrains, and terrainChanged tells every cell. The Camp and the Tower are never painted, and a cell that already has that cost is left alone, so nothing is told.
$selectedCell != data('Maze Settings', 'rules', 'startCell') && $selectedCell != data('Maze Settings', 'rules', 'goalCell') && data('Maze Cells', $selectedCell, 'cost') != data('Terrains', $brush, 'cost')- Table
"Maze Cells"- Row
dataRow('Maze Cells', $selectedCell)- Column
"cost"- Value
data('Terrains', $brush, 'cost')
- Custom Event
terrainChanged
A.16 Restore Defaults
Built in Chapter 2, Paint the Maze.
Puts the supplied map back when the learner presses the Restore Defaults Command (D in the Input Manager): every cell gets the cost written in Maze Cells in the editor, the Selection goes back to the Camp, and every cell draws its picture again.
Any Object- Table
"Maze Cells"
- Variable
$selectedCell- Value
data('Maze Settings', 'rules', 'startCell')
- Custom Event
terrainChanged
A.17 Select Neighbor (Function)
Built in Chapter 2, Paint the Maze.
Moves the selection (the Project Global selectedCell) one cell in one direction, a row of Directions. At the edge of the map the selection stays where it is.
- Action Name
next- cell
$selectedCell- direction
direction
next.value >= 0- Variable
$selectedCell- Value
next.value
A.18 Check Maze Input (Function)
Built in Chapter 3, Settle One Cheapest Cell.
Checks the map and Maze Settings before a search begins. problem is the Messages row of the first rule that is broken, or empty when every rule holds: the map has columns times rows cells (wrongMapSize); maxCost is a whole number from 0 to maxCostLimit, and unreached is larger than any route can cost and at most unreachedLimit (wrongSettings); the Camp and the Tower are cells of the map (wrongEndpoints); every cost is a Wall or a whole number from 0 to maxCost (wrongCost); neither the Camp nor the Tower is a Wall (blockedEndpoint).
- Type
Text- Name
problem
- Name
camp- Value
0
- Name
tower- Value
0
- Name
mapCells- Value
0
- Variable
camp- Value
data('Maze Settings', 'rules', 'startCell')
- Variable
tower- Value
data('Maze Settings', 'rules', 'goalCell')
- Variable
mapCells- Value
data('Maze Settings', 'rules', 'columns')
- Variable
mapCells- Operator
*=- Value
data('Maze Settings', 'rules', 'rows')
- Variable
problem- Value
""
data('Maze Cells', camp, 'cost') == data('Terrains', 'Wall', 'cost') || data('Maze Cells', tower, 'cost') == data('Terrains', 'Wall', 'cost')- Variable
problem- Value
'blockedEndpoint'
dataCount('Maze Cells')timesdata('Maze Cells', local.index, 'cost') < data('Terrains', 'Wall', 'cost') || data('Maze Cells', local.index, 'cost') > data('Maze Settings', 'rules', 'maxCost') || data('Maze Cells', local.index, 'cost') != floor(data('Maze Cells', local.index, 'cost'))- Variable
problem- Value
'wrongCost'
- Action Name
isCampOnMap- Table
"Maze Cells"- Row
camp
- Action Name
isTowerOnMap- Table
"Maze Cells"- Row
tower
isCampOnMap.value == false || camp != floor(camp) || isTowerOnMap.value == false || tower != floor(tower)- Variable
problem- Value
'wrongEndpoints'
data('Maze Settings', 'rules', 'maxCost') < 0 || data('Maze Settings', 'rules', 'maxCost') > maxCostLimit || data('Maze Settings', 'rules', 'maxCost') != floor(data('Maze Settings', 'rules', 'maxCost')) || data('Maze Settings', 'rules', 'unreached') <= (dataCount('Maze Cells') * data('Maze Settings', 'rules', 'maxCost')) || data('Maze Settings', 'rules', 'unreached') > unreachedLimit- Variable
problem- Value
'wrongSettings'
mapCells != dataCount('Maze Cells') || data('Maze Settings', 'rules', 'columns') < 1 || data('Maze Settings', 'rules', 'columns') != floor(data('Maze Settings', 'rules', 'columns')) || data('Maze Settings', 'rules', 'rows') != floor(data('Maze Settings', 'rules', 'rows'))- Variable
problem- Value
'wrongMapSize'
- Value
problem
A.19 Choose Cheapest Cell (Function)
Built in Chapter 3, Settle One Cheapest Cell.
The frontier cell with the smallest distance, or -1 when the frontier is empty. The frontier is every cell that is not a Wall, not settled, and already reached (its distance is less than Maze Settings unreached). On equal distances the lowest cell number wins.
- Name
cheapest- Value
-1
- Name
cheapestDistance- Value
0
- Variable
cheapest- Value
-1
- Variable
cheapestDistance- Value
data('Maze Settings', 'rules', 'unreached')
dataCount('Maze Cells')timesdata('Maze Cells', local.index, 'settled') == 0 && data('Maze Cells', local.index, 'cost') != data('Terrains', 'Wall', 'cost') && data('Maze Cells', local.index, 'distance') < cheapestDistance- Variable
cheapest- Value
local.index
- Variable
cheapestDistance- Value
data('Maze Cells', local.index, 'distance')
- Value
cheapest
A.20 Clear Trial (Function)
Built in Chapter 3, Settle One Cheapest Cell.
Puts the trial back to Ready, keeping the terrain: every cell of Maze Cells gets distance unreached (Maze Settings), no parent (-1) and settled 0 and no place on the Route (routeOrder -1), Visited goes back to 0, no cell is current (currentCell -1), the Marker's cell is the Camp (markerCell), Status asks the learner to paint terrain (the Messages ready words), and searchChanged clears every Search Outline. Last, trialCleared tells Step Trial on rules (Maze Rules) that the trial was cleared, so the next Step starts from Ready, and Find Route, so Find route stops.
dataCount('Maze Cells')times- Table
"Maze Cells"- Row
dataRow('Maze Cells', local.index)- Column
"distance"- Value
data('Maze Settings', 'rules', 'unreached')
- Table
"Maze Cells"- Row
dataRow('Maze Cells', local.index)- Column
"parent"- Value
-1
- Table
"Maze Cells"- Row
dataRow('Maze Cells', local.index)- Column
"settled"- Value
0
- Table
"Maze Cells"- Row
dataRow('Maze Cells', local.index)- Column
"routeOrder"- Value
-1
- Variable
$visited- Value
0
- Variable
$currentCell- Value
-1
- Variable
$status- Value
data('Messages', 'ready', 'words')
- Variable
$markerCell- Value
data('Maze Settings', 'rules', 'startCell')
- Custom Event
searchChanged
- Applies To
rules- Custom Event
trialCleared
A.21 Color Search Outline (Function)
Built in Chapter 3, Settle One Cheapest Cell.
Shows one cell's place in the search on its Search Outline: hidden while the search has not reached the cell, a thin ring in frontierTint once it is reached, a thick ring in settledTint once it is settled, and currentTint while it is the current cell (the one the last Step settled), and routeTint once it is on the Route (its routeOrder is 0 or more). A later rule wins: Route over current over settled over frontier. The thin and the thick ring are frames 0 and 1 of the Cell Outline picture, so a settled cell shows by its shape as well as by its color.
spriteSprite- Applies To
outline- Visible
false
data('Maze Cells', cell, 'distance') < data('Maze Settings', 'rules', 'unreached')- Applies To
outline- Visible
true
- Applies To
outline- Frame
0
- Applies To
outline- Value
frontierTint
data('Maze Cells', cell, 'settled') == 1- Applies To
outline- Visible
true
- Applies To
outline- Frame
1
- Applies To
outline- Value
settledTint
cell == $currentCell- Applies To
outline- Visible
true
- Applies To
outline- Value
currentTint
data('Maze Cells', cell, 'routeOrder') >= 0- Applies To
outline- Visible
true
- Applies To
outline- Value
routeTint
A.22 Relax Neighbor (Function)
Built in Chapter 3, Settle One Cheapest Cell.
Offers one neighbor of a settled cell a route through it. The neighbor is the cell next to cell in direction (a row of Directions). A neighbor on the map that is not a Wall and not settled gets distance (cell's distance plus the neighbor's cost) and cell as its parent, but only when that is strictly smaller than its distance so far, so an equal route keeps the parent it found first.
- Name
neighbor- Value
-1
- Name
newDistance- Value
0
- Action Name
next- cell
cell- direction
direction
- Variable
neighbor- Value
next.value
neighbor >= 0 && data('Maze Cells', neighbor, 'cost') != data('Terrains', 'Wall', 'cost') && data('Maze Cells', neighbor, 'settled') == 0- Variable
newDistance- Value
data('Maze Cells', cell, 'distance')
- Variable
newDistance- Operator
+=- Value
data('Maze Cells', neighbor, 'cost')
newDistance < data('Maze Cells', neighbor, 'distance')- Table
"Maze Cells"- Row
dataRow('Maze Cells', neighbor)- Column
"distance"- Value
newDistance
- Table
"Maze Cells"- Row
dataRow('Maze Cells', neighbor)- Column
"parent"- Value
cell
A.23 Relax Neighbors (Function)
Built in Chapter 3, Settle One Cheapest Cell.
Offers every neighbor of one settled cell a route through it (Relax Neighbor), in the order of Directions: Up, Right, Down, Left.
dataCount('Directions')times- cell
cell- direction
dataRow('Directions', local.index)
A.24 Request Reset
Built in Chapter 3, Settle One Cheapest Cell.
Lets the learner ask for a Reset with a click or a touch: activating the Reset button sends resetRequested, which Reset Trial on Maze Rules answers.
Any Object- Custom Event
resetRequested
A.25 Request Step
Built in Chapter 3, Settle One Cheapest Cell.
Lets the learner ask for one Step with a click or a touch on the Step button, or with the Step Command (Space in the Input Manager): each sends stepRequested, which Step Trial on Maze Rules answers. Each first sends pauseRequested, so a Step while Find route runs pauses it before the Step (the Function Ask For One Step).
Any ObjectA.26 Settle Cheapest Cell (Function)
Built in Chapter 3, Settle One Cheapest Cell.
Settles the cheapest frontier cell (Choose Cheapest Cell): marks it settled, adds 1 to Visited, and sends cellSettled, so the Status line can name it. The cell settled becomes the current cell (the Project Global currentCell), which is -1 when the frontier was empty and nothing was settled; cell gives the same number.
- Action Name
cheapest
- Variable
$currentCell- Value
cheapest.value
$currentCell >= 0- Table
"Maze Cells"- Row
dataRow('Maze Cells', $currentCell)- Column
"settled"- Value
1
- Variable
$visited- Operator
+=- Value
1
- Custom Event
cellSettled
- Value
$currentCell
A.27 Show Search Outline
Built in Chapter 3, Settle One Cheapest Cell.
One cell's ring that shows where the search is: whenever the search changes, it is hidden, a thin cyan ring (frontier), a thick blue ring (settled) or a thick white ring (the current cell), with Color Search Outline. Its cell is its Map Place cell, which Lay Out Map gives it. frontierTint, settledTint, currentTint and routeTint are the four colors: a cell on the Route is yellow.
Any Objectself.mapPlaceSprite- Action Name
place- cell
self.mapPlace.cell
- Position Relative To
Screen- X
place.x- Y
place.y
- outline
self- cell
self.mapPlace.cell- frontierTint
@self.frontierTint- settledTint
@self.settledTint- currentTint
@self.currentTint- routeTint
@self.routeTint
- outline
self- cell
self.mapPlace.cell- frontierTint
@self.frontierTint- settledTint
@self.settledTint- currentTint
@self.currentTint- routeTint
@self.routeTint
A.28 Show Settled Cell
Built in Chapter 3, Settle One Cheapest Cell.
The Status line while the search settles cells: each time Settle Cheapest Cell settles a cell (cellSettled), Status names the cell by its Maze Cells row and gives its distance, as in "Cell 52: cost 8". When the cell settled is the Tower, Status says the Route is being built instead (the Messages buildingRoute words).
Any Object$currentCell == data('Maze Settings', 'rules', 'goalCell')- Variable
$status- Value
data('Messages', 'buildingRoute', 'words')
- Variable
$status- Value
dataRow('Maze Cells', $currentCell)
- Variable
$status- Operator
+=- Value
data('Messages', 'cellSettled', 'words')
- Variable
$status- Operator
+=- Value
data('Maze Cells', $currentCell, 'distance')
A.29 Step Trial
Built in Chapter 3, Settle One Cheapest Cell.
Makes one Step of the trial each time stepRequested arrives (the Step button or the Step Command). What a Step does depends on the trial's phase, the Mode of stepRequested: Ready begins the search and settles the Camp, Searching settles the next cheapest cell, and Finished does nothing. Before the first settle, Ready checks the map and Maze Settings (Check Maze Input); maxCostLimit and unreachedLimit are the largest maxCost and unreached that check allows. Once the Tower is settled, Tracing marks one cell of the Route per Step, from the Tower back to the Camp, checking each link (Check Route Link); traceCell is the cell the next Step marks and routeLength how many cells are marked. Then Replaying moves the Marker one cell of the Route per Step, toward the Tower: it commits the next cell (markerCell) and waits (Waiting For Marker) until Slide Marker says it has landed (markerLanded). On the Tower the Route is complete. Every way the trial ends goes through End Trial, which also tells Find Route. markerOrder is the routeOrder of the Marker's cell. A cleared trial (trialCleared, from Clear Trial) starts again from Ready.
Maze Rules- Action Name
inputCheck- maxCostLimit
@self.maxCostLimit- unreachedLimit
@self.unreachedLimit
inputCheck.value == ""- Table
"Maze Cells"- Row
dataRow('Maze Cells', data('Maze Settings', 'rules', 'startCell'))- Column
distance- Value
0
- Component Value
self.stepTrialData.traceCell- Value
data('Maze Settings', 'rules', 'goalCell')
- Component Value
self.stepTrialData.routeLength- Value
0
- Action Name
firstSettle
firstSettle.value == data('Maze Settings', 'rules', 'goalCell')- Event
On Step Requested- Mode
Tracing
- cell
firstSettle.value
- Event
On Step Requested- Mode
Searching
- Custom Event
searchChanged
- rules
self- ending
inputCheck.value
- Event
On Step Requested- Mode
Finished
- Action Name
settle
settle.value >= 0settle.value == data('Maze Settings', 'rules', 'goalCell')- Event
On Step Requested- Mode
Tracing
- cell
settle.value
- rules
self- ending
noRoute
- Event
On Step Requested- Mode
Finished
- Custom Event
searchChanged
- Table
"Maze Cells"- Row
dataRow('Maze Cells', self.stepTrialData.traceCell)- Column
routeOrder- Value
self.stepTrialData.routeLength
- Component Value
self.stepTrialData.routeLength- Operator
+=- Value
1
self.stepTrialData.traceCell == data('Maze Settings', 'rules', 'startCell')- Variable
$status- Value
data('Messages', 'followRoute', 'words')
- Event
On Step Requested- Mode
Replaying
- Action Name
link- cell
self.stepTrialData.traceCell
link.value == 1 && self.stepTrialData.routeLength < dataCount('Maze Cells')- Component Value
self.stepTrialData.traceCell- Value
data('Maze Cells', self.stepTrialData.traceCell, 'parent')
- rules
self- ending
invalidRoute
- Event
On Step Requested- Mode
Finished
- Custom Event
searchChanged
- Name
markerOrder- Value
-1
- Variable
markerOrder- Value
data('Maze Cells', $markerCell, 'routeOrder')
markerOrder > 0- Variable
$markerCell- Value
dataFind('Maze Cells', 'routeOrder', markerOrder - 1)
- Event
On Step Requested- Mode
Waiting For Marker
- Custom Event
markerMoved
- rules
self- ending
cheapestRoute
- Event
On Step Requested- Mode
Finished
$markerCell == data('Maze Settings', 'rules', 'goalCell')- rules
self- ending
cheapestRoute
- Event
On Step Requested- Mode
Finished
- Event
On Step Requested- Mode
Replaying
- Event
On Step Requested
A.30 Check Route Link (Function)
Built in Chapter 4, Finish a Route.
Whether the link from cell back to its parent can be trusted. isValid is 1 when every check holds and 0 otherwise: the parent is one of cell's four neighbors on the map (Find Grid Neighbor), the parent is settled, and the parent's distance plus the cost of entering cell is exactly cell's distance.
- Name
parent- Value
-1
- Name
isNeighbor- Value
0
- Name
throughParent- Value
0
- Name
isValid- Value
0
- Variable
parent- Value
data('Maze Cells', cell, 'parent')
- Variable
isNeighbor- Value
0
- Variable
isValid- Value
0
dataCount('Directions')times- Action Name
side- cell
cell- direction
dataRow('Directions', local.index)
side.value == parent && parent >= 0- Variable
isNeighbor- Value
1
- Variable
throughParent- Value
data('Maze Cells', parent, 'distance')
- Variable
throughParent- Operator
+=- Value
data('Maze Cells', cell, 'cost')
isNeighbor == 1 && data('Maze Cells', parent, 'settled') == 1 && throughParent == data('Maze Cells', cell, 'distance')- Variable
isValid- Value
1
- Value
isValid
A.31 Draw Route Line (Function)
Built in Chapter 4, Finish a Route.
Shows one Route Line (or its backing) between two neighboring cells, cell and neighbor, only while both are on the Route (routeOrder 0 or more) and one comes right after the other (their routeOrder values differ by 1); otherwise hides it. So a line never joins two Route cells that do not follow each other.
spriteSprite- Name
cellOrder- Value
-1
- Name
neighborOrder- Value
-1
- Variable
cellOrder- Value
data('Maze Cells', cell, 'routeOrder')
- Variable
neighborOrder- Value
data('Maze Cells', neighbor, 'routeOrder')
cellOrder >= 0 && neighborOrder >= 0 && abs(cellOrder - neighborOrder) == 1- Applies To
line- Visible
true
- Applies To
line- Visible
false
A.32 Lay Out Route Lines
Built in Chapter 4, Finish a Route.
Lays out the Route Line when the Scene starts: it joins every two neighboring cells with a Route Line over a Route Line Backing, once, from the cell that comes first in reading order to its neighbor on the right or below. Each line gets its two cells (its Route Link) and is told, with placedOnMap, that it is placed; it then stands between its cells and shows itself. routeLineBacking and routeLine are the Objects it makes.
Any ObjectdataCount('Maze Cells')times- Name
thisCell- Value
local.index
dataCount('Directions')times- Action Name
next- cell
thisCell- direction
dataRow('Directions', local.index)
next.value > thisCell- Object to Create
@self.routeLineBacking- X
0- Y
0- Created As
newBacking
- Variable
newBacking.cell- Value
thisCell
- Variable
newBacking.neighbor- Value
next.value
- Applies To
newBacking- Custom Event
placedOnMap
- Object to Create
@self.routeLine- X
0- Y
0- Created As
newLine
- Variable
newLine.cell- Value
thisCell
- Variable
newLine.neighbor- Value
next.value
- Applies To
newLine- Custom Event
placedOnMap
A.33 Marker Screen Position (Function)
Built in Chapter 4, Finish a Route.
Where the Marker stands on one cell, in screen pixels: on the cell's lower-right corner, Maze Layout markerOffset pixels right of and below the cell's center (Cell Screen Position).
- Name
x- Value
0
- Name
y- Value
0
- Action Name
place- cell
cell
- Variable
x- Value
place.x + data('Maze Layout', 'board', 'markerOffset')
- Variable
y- Value
place.y - data('Maze Layout', 'board', 'markerOffset')
- x
x- y
y
A.34 Show Route Cost
Built in Chapter 4, Finish a Route.
The Cost readout: whenever the search changes, it shows the cost of the cheapest Route, which is the Tower's distance once the Tower is settled, or the Messages noCost words ("--") while it is not.
Any ObjectText / UI- Name
tower- Value
0
- Variable
tower- Value
data('Maze Settings', 'rules', 'goalCell')
data('Maze Cells', tower, 'settled') == 1- Component Value
self.text.text- Value
data('Maze Cells', tower, 'distance')
- Component Value
self.text.text- Value
data('Messages', 'noCost', 'words')
A.35 Show Route Line
Built in Chapter 4, Finish a Route.
One piece of the Route Line, the yellow line that joins the Route's cells: whenever the search changes it is shown only while its two cells follow each other on the Route (Draw Route Line). The Route Line and the Route Line Backing both use it. Its two cells are its Route Link cell and neighbor, which Lay Out Route Lines gives it; it stands halfway between them, upright when one is above the other. lineTint is its color: yellow on the Route Line, and dark on the Route Line Backing, each Object's own Shared Variable.
Any Objectself.routeLinkSprite- Action Name
from- cell
self.routeLink.cell
- Action Name
to- cell
self.routeLink.neighbor
- Position Relative To
Screen- X
(from.x + to.x) / 2- Y
(from.y + to.y) / 2
from.x == to.x- Degrees
90
- Value
@self.lineTint
- line
self- cell
self.routeLink.cell- neighbor
self.routeLink.neighbor
- line
self- cell
self.routeLink.cell- neighbor
self.routeLink.neighbor
A.36 Slide Marker
Built in Chapter 4, Finish a Route.
Shows the Marker on the cell markerCell names. When Step Trial commits the Marker's next cell (markerMoved), the Marker slides there in Maze Layout slideSeconds and sends markerLanded when it is exactly on it. When the search changes or is cleared (searchChanged), the Marker stands on markerCell at once, ending any slide.
Marker- Timer Name
markerSlide
- marker
self
- Action Name
spot- cell
$markerCell
- Value
self.transform.position.x- Target
spot.x- Duration
data('Maze Layout', 'board', 'slideSeconds')
- Value
self.transform.position.y- Target
spot.y- Duration
data('Maze Layout', 'board', 'slideSeconds')
- Timer Name
markerSlide- Repeat Every (s)
data('Maze Layout', 'board', 'slideSeconds')- Ring Once
Yes
- marker
self
- Custom Event
markerLanded
A.37 Stand Marker (Function)
Built in Chapter 4, Finish a Route.
Stops the Marker and puts it exactly on the cell markerCell names (Marker Screen Position).
- Applies To
marker
- Action Name
spot- cell
$markerCell
- Applies To
marker- Position Relative To
Screen- X
spot.x- Y
spot.y
A.38 Ask For One Step (Function)
Built in Chapter 5, Find and Pause.
Asks Maze Rules for one Step: first pauseRequested, so Find Route stops Find route if it is running, then stepRequested, which Step Trial answers with one transition. Both are heard at once, in the order they are sent, so the Step is the only transition the learner asked for.
- Custom Event
pauseRequested
- Custom Event
stepRequested
A.39 End Trial (Function)
Built in Chapter 5, Find and Pause.
Ends the trial on rules (Maze Rules). ending is the Messages row that says how it ended (cheapestRoute, noRoute, invalidRoute, or the row of a broken input rule): Status shows its words, and trialEnded tells Find Route on rules that the trial has ended. Step Trial, which calls it, then goes to Finished.
- Variable
$status- Value
data('Messages', ending, 'words')
- Applies To
rules- Custom Event
trialEnded
A.40 Find Route
Built in Chapter 5, Find and Pause.
Runs the trial by itself: each findRequested (the Find route button or the Find Route Command) starts Find route or pauses it, by the Mode of findRequested. While it runs, the searchTick timer sends stepRequested every Maze Settings tickSeconds, the same Step the Step button asks for, and the button reads Pause (findStarted). A cleared trial (trialCleared) stops it (Stop Finding), and so does pauseRequested (Escape, or a Step). A trial that has ended (trialEnded) stops it too, and the next findRequested then starts over: Start Over clears the trial before Start runs Find route on the new one. Whenever it stops (findStopped), Pause is taken out and Start put in.
Maze Rules- rules
self
- Variable
$status- Value
data('Messages', 'searching', 'words')
- Timer Name
searchTick- Repeat Every (s)
data('Maze Settings', 'rules', 'tickSeconds')
- Custom Event
findStarted
- Event
On Find Requested- Mode
Pause
- rules
self
- Variable
$status- Value
data('Messages', 'paused', 'words')
- Custom Event
stepRequested
- rules
self
- Event
On Find Requested- Mode
Start Over
- rules
self
- rules
self
- Event
On Find Requested- Mode
Start Over
- Event
On Find Requested- Mode
Pause
- Event
On Find Requested- Mode
Start
A.41 Request Find
Built in Chapter 5, Find and Pause.
Lets the learner start or pause Find route with a click or a touch on the Find route button, or with the Find Route Command (F in the Input Manager): each sends findRequested, which Find Route on Maze Rules answers. The Pause Command (Escape) only pauses: it sends pauseRequested.
Any Object- Custom Event
findRequested
- Custom Event
findRequested
- Custom Event
pauseRequested
A.42 Show Find Caption
Built in Chapter 5, Find and Pause.
The words on the Find route button: the Messages pauseCaption words ("Pause") while Find route runs (findStarted), and the findCaption words ("Find route") when it stops (findStopped).
Any ObjectText / UI- Component Value
self.text.text- Value
data('Messages', 'pauseCaption', 'words')
- Component Value
self.text.text- Value
data('Messages', 'findCaption', 'words')
A.43 Stop Finding (Function)
Built in Chapter 5, Find and Pause.
Stops Find route on rules (Maze Rules): its searchTick timer stops, and findStopped tells the Find route button and Find Route, so the next findRequested starts Find route again. Stopping a Find route that is not running changes nothing. The trial is kept as it is.
- Applies To
rules- Timer Name
"searchTick"
- Custom Event
findStopped
