TutorialsBinary Search

Appendix A — Logic Reference

Every Logic Component and Function in Crack the Safe, 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 Button Clicks

Built in Chapter 1, Safe Room.

Logic ComponentButton ClicksAttach to: Safe Rules

Does what each button on the screen asks. A button sends its Custom Event to Safe Rules when clicked, and each one here calls the Function its key calls.

Attach toAny Object
DATA STRUCTURES
Safe Stateself.safeState
On Back Clicked
WhenbackClickedCustom Event
1Erase DigitFunction
safeRules
self
On Scan Clicked
WhenscanClickedCustom Event
1Scan GuessFunction
safeRules
self
On New Safe Clicked
WhennewSafeClickedCustom Event
1Start New SafeFunction
safeRules
self
On Human Tab Clicked
WhenhumanTabClickedCustom Event
1Choose Human RoleFunction
safeRules
self
On Computer Tab Clicked
WhencomputerTabClickedCustom Event
1Choose Computer RoleFunction
safeRules
self
On Lock Code Clicked
WhenlockCodeClickedCustom Event
1Lock CodeFunction
safeRules
self
On Step Clicked
WhenstepClickedCustom Event
1Step OnceFunction
safeRules
self
On Change Code Clicked
WhenchangeCodeClickedCustom Event
1Start Code SetupFunction
safeRules
self
On Run Clicked
WhenrunClickedCustom Event
1Run or PauseFunction
safeRules
self
On Pause Clicked
WhenpauseClickedCustom Event
1Run or PauseFunction
safeRules
self
On Watch Computer Clicked
WhenwatchComputerClickedCustom Event
1Watch ComputerFunction
safeRules
self
On Myth Lesson Clicked
WhenmythLessonClickedCustom Event
1Open or Close Myth LessonFunction
safeRules
self
On Close Lesson Clicked
WhencloseLessonClickedCustom Event
1Close Myth LessonFunction
safeRules
self

A.2 Clear Entry (Function)

Built in Chapter 1, Safe Room.

FunctionClear Entry

Empties the entry (Clear) while the keypad is open, so the next digit typed is its first digit.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Check Keypad OpenFunction
Action Name
keypad
safeRules
safeRules
2Ifkeypad.value == true
Then
3Change Variable
Variable
$entry
Value
0
4Change Component Value
Component Value
safeRules.safeState.startsNewEntry
Value
false
5Otherwise
6Change Variable
Variable
$message
Value
data('Safe Copy','Code Sealed','text')

A.3 Erase Digit (Function)

Built in Chapter 1, Safe Room.

FunctionErase Digit

Removes the last digit of the entry (Back) while the keypad is open. The next digit typed is added to what is left.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Check Keypad OpenFunction
Action Name
keypad
safeRules
safeRules
2Ifkeypad.value == true
Then
3Change Variable
Variable
$entry
Value
floor($entry / 10)
4Change Component Value
Component Value
safeRules.safeState.startsNewEntry
Value
false
5Otherwise
6Change Variable
Variable
$message
Value
data('Safe Copy','Code Sealed','text')

A.4 Keypad Keys

Built in Chapter 1, Safe Room.

Logic ComponentKeypad KeysAttach to: Safe Rules

Lets the keyboard work the keypad: the digit keys type a digit, Backspace erases the last digit, and Delete clears the entry. The keypad's buttons call the same Functions. What Enter does depends on the role, so Human Role and Computer Role answer it.

Attach toAny Object
DATA STRUCTURES
Safe Stateself.safeState
When Digit0 Is Pressed
WhenCommand PressedCommand: Digit 0
1Type DigitFunction
safeRules
self
digit
0
When Digit1 Is Pressed
WhenCommand PressedCommand: Digit 1
1Type DigitFunction
safeRules
self
digit
1
When Digit2 Is Pressed
WhenCommand PressedCommand: Digit 2
1Type DigitFunction
safeRules
self
digit
2
When Digit3 Is Pressed
WhenCommand PressedCommand: Digit 3
1Type DigitFunction
safeRules
self
digit
3
When Digit4 Is Pressed
WhenCommand PressedCommand: Digit 4
1Type DigitFunction
safeRules
self
digit
4
When Digit5 Is Pressed
WhenCommand PressedCommand: Digit 5
1Type DigitFunction
safeRules
self
digit
5
When Digit6 Is Pressed
WhenCommand PressedCommand: Digit 6
1Type DigitFunction
safeRules
self
digit
6
When Digit7 Is Pressed
WhenCommand PressedCommand: Digit 7
1Type DigitFunction
safeRules
self
digit
7
When Digit8 Is Pressed
WhenCommand PressedCommand: Digit 8
1Type DigitFunction
safeRules
self
digit
8
When Digit9 Is Pressed
WhenCommand PressedCommand: Digit 9
1Type DigitFunction
safeRules
self
digit
9
When Back Is Pressed
WhenCommand PressedCommand: Back
1Erase DigitFunction
safeRules
self
When Clear Is Pressed
WhenCommand PressedCommand: Clear
1Clear EntryFunction
safeRules
self

A.5 New Safe

Built in Chapter 1, Safe Room.

Logic ComponentNew SafeAttach to: Safe Rules

Starts the first safe when the game begins, in the Human role.

Attach toAny Object
DATA STRUCTURES
Safe Stateself.safeState
When the Game Starts
WhenGame Start
1Start New SafeFunction
safeRules
self

A.6 Safe Button

Built in Chapter 1, Safe Room.

Logic ComponentSafe ButtonAttach to: Back Key, Scan Button, New Safe Button, Role Tab, Lock Code Button, Change Code Button, Step Button, Run Button, Pause Button, Watch Computer Button, Close Lesson Button, Myth Lesson Button

A button that sends its Custom Event (clickEvent) to the Safe Rules Object when the player clicks it. Each button sets its own. It works only while the game's controls are on (the Game Controls Input Context), unless worksInLesson says it also works while the Myth Lesson is open.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
safeRulesObjectConstantNone
worksInLessonBooleanConstantNo
PER INSTANCE VARIABLES
NameTypeStarting Value
clickEventText(empty)
On Hud Activated
WhenUI Activated
1Check Input Context Active
Action Name
controlsOn
Input Context
Game Controls
2IfcontrolsOn.value == true || @self.worksInLesson == true
Then
3Trigger Custom Event on Object
Applies to
@self.safeRules
Custom Event
self.clickEvent

A.7 Show Entry

Built in Chapter 1, Safe Room.

Logic ComponentShow EntryAttach to: Entry Display

Keeps the keypad display up to date: the number of the entry, or dashes while the entry is empty (0).

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
entryTextObjectConstantNone
emptyTextObjectConstantNone
When Created
WhenCreate
1Show Entry Or DashesFunction
entryText
@self.entryText
emptyText
@self.emptyText
On Variable Changed · Entry
WhenVariable ChangedGlobal Variable: entry
1Show Entry Or DashesFunction
entryText
@self.entryText
emptyText
@self.emptyText

A.8 Show Entry Or Dashes (Function)

Built in Chapter 1, Safe Room.

FunctionShow Entry Or Dashes

Shows the entry text while the entry has a number, and the dashes while it is empty (0).

PARAMETERS
NameTypeStarts at
entryTextObjectEntry Value
emptyTextObjectNo Entry
ACTIONS
1If$entry > 0
Then
2Set Visible
Applies to
entryText
Visible
true
3Set Visible
Applies to
emptyText
Visible
false
4Otherwise
5Set Visible
Applies to
entryText
Visible
false
6Set Visible
Applies to
emptyText
Visible
true

A.9 Type Digit (Function)

Built in Chapter 1, Safe Room.

FunctionType Digit

Adds one typed digit to the entry while the keypad is open. The first digit after a finished entry starts a new entry; later digits are added on the right while the entry is below the highest code.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
digitNumber0
ACTIONS
1Check Keypad OpenFunction
Action Name
keypad
safeRules
safeRules
2Ifkeypad.value == true
Then
3IfsafeRules.safeState.startsNewEntry == true
Then
4Change Variable
Variable
$entry
Value
0
5Change Component Value
Component Value
safeRules.safeState.startsNewEntry
Value
false
6If$entry < data('Safe Settings','Standard Safe','highestCode')
Then
7Change Variable
Variable
$entry
Operator
*=
Value
10
8Change Variable
Variable
$entry
Operator
+=
Value
digit
9Otherwise
10Change Variable
Variable
$message
Value
data('Safe Copy','Code Sealed','text')

A.10 Type Its Digit

Built in Chapter 1, Safe Room.

Logic ComponentType Its DigitAttach to: Digit Key

A keypad button that types its digit when the player clicks it, the same as pressing its digit key on the keyboard. Like the key, it does nothing while the game's controls are off (the Myth Lesson is open).

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
safeRulesObjectConstantNone
PER INSTANCE VARIABLES
NameTypeStarting Value
digitNumber0
On Hud Activated
WhenUI Activated
1Check Input Context Active
Action Name
controlsOn
Input Context
Game Controls
2IfcontrolsOn.value == true
Then
3Type DigitFunction
safeRules
@self.safeRules
digit
self.digit

A.11 Check Guess (Function)

Built in Chapter 2, Human Scan.

FunctionCheck Guess

Compares a guess with the code and answers with the clue: 1 when the code is higher than the guess, -1 when it is lower, 0 when the guess is the code.

PARAMETERS
NameTypeStarts at
guessNumber0
codeNumber0
RETURN TYPENumber
ACTIONS
1Declare Variable
Name
clue
Value
0
2Ifguess == code
Then
3Change Variable
Variable
clue
Value
0
4Otherwise
5Ifguess < code
Then
6Change Variable
Variable
clue
Value
1
7Otherwise
8Change Variable
Variable
clue
Value
-1
9Return
Value
clue

A.12 Follow the Clue (Function)

Built in Chapter 2, Human Scan.

FunctionFollow the Clue

Uses the clue of the scan just made: Unlocked when the guess is the code; otherwise the range shrinks past the guess, and the trial is Exhausted when the scan budget is spent.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1IfsafeRules.safeState.clue == 0
Then
2Change Variable
Variable
$low
Value
$lastGuess
3Change Variable
Variable
$high
Value
$lastGuess
4Set Game State
Applies to
safeRules
Game State
Unlocked
5Change Variable
Variable
$message
Value
data('Safe Copy','Unlocked','text')
6Otherwise
7IfsafeRules.safeState.clue == 1
Then
8Change Variable
Variable
$low
Value
$lastGuess + 1
9Change Variable
Variable
$message
Value
text(data('Safe Copy','Higher Than','text'), ' ', $lastGuess)
10Otherwise
11Change Variable
Variable
$high
Value
$lastGuess - 1
12Change Variable
Variable
$message
Value
text(data('Safe Copy','Lower Than','text'), ' ', $lastGuess)
13If$scans >= data('Safe Settings','Standard Safe','scanBudget')
Then
14Set Game State
Applies to
safeRules
Game State
Exhausted
15Change Variable
Variable
$message
Value
data('Safe Copy','Out of Scans','text')

A.13 Scan Guess (Function)

Built in Chapter 2, Human Scan.

FunctionScan Guess

Tries the entry as a guess. A guess counts only while the safe is Locked and only inside the range of codes still possible; it then counts one scan, asks Check Guess for the clue, and follows it.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Check Game State
Action Name
safeIsLocked
Applies to
safeRules
Game State
Locked
2IfsafeIsLocked.value == true
Then
3If$entry >= $low && $entry <= $high
Then
4Change Variable
Variable
$lastGuess
Value
$entry
5Change Variable
Variable
$scans
Operator
+=
Value
1
6Change Component Value
Component Value
safeRules.safeState.startsNewEntry
Value
true
7Check GuessFunction
Action Name
checkedGuess
guess
$lastGuess
code
safeRules.safeState.code
8Change Component Value
Component Value
safeRules.safeState.clue
Value
checkedGuess.value
9Follow the ClueFunction
safeRules
safeRules
10Record ScanFunction
safeRules
safeRules
11Otherwise
12Change Variable
Variable
$message
Value
data('Safe Copy','Outside the Range','text')
13Otherwise
14Change Variable
Variable
$message
Value
data('Safe Copy','Start a New Safe','text')

A.14 Show Possibilities

Built in Chapter 2, Human Scan.

Logic ComponentShow PossibilitiesAttach to: Possibilities

Keeps the words after the count of codes still possible right, from the start and whenever the range changes.

Attach toAny Object
DATA STRUCTURES
Possibilities Lineself.possibilitiesLine
When Created
WhenCreate
1Write Possibilities LineFunction
line
self
On Variable Changed
WhenVariable Changed
1Write Possibilities LineFunction
line
self

A.15 Show Safe Door

Built in Chapter 2, Human Scan.

Logic ComponentShow Safe DoorAttach to: Safe

Shows the safe open while the trial is Unlocked, and closed in every other phase.

Attach toAny Object
On Game State Changed
WhenGame State Changed
1Check Game State
Action Name
safeIsOpen
Game State
Unlocked
2IfsafeIsOpen.value == true
Then
3Set Sprite
Sprite
Unlocked Safe
4Otherwise
5Set Sprite
Sprite
Locked Safe

A.16 Start New Safe (Function)

Built in Chapter 2, Human Scan.

FunctionStart New Safe

Starts a fresh trial on a new safe in the Human role: draws a new secret code with the engine's random block and resets the trial.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Generate Random Integer
Action Name
codeRoll
Minimum
data('Safe Settings','Standard Safe','lowestCode')
Maximum
data('Safe Settings','Standard Safe','highestCode')
2Change Component Value
Component Value
safeRules.safeState.code
Value
codeRoll.value
3Reset TrialFunction
safeRules
safeRules
4Set Game State
Applies to
safeRules
Game State
Locked
5Change Variable
Variable
$message
Value
data('Safe Copy','Scan a Guess','text')

A.17 Write Possibilities Line (Function)

Built in Chapter 2, Human Scan.

FunctionWrite Possibilities Line

Writes the words after the count of codes still possible: possibility remains when only one code is left, possibilities remain otherwise.

PARAMETERS
NameTypeStarts at
lineObjectStructural
Required Components
Slot NamepossibilitiesLine
Component TypeData Structure
Required SchemaPossibilities Line
ACTIONS
1If$low == $high
Then
2Change Component Value
Component Value
line.possibilitiesLine.words
Value
data('Safe Copy','One Possibility Remains','text')
3Otherwise
4Change Component Value
Component Value
line.possibilitiesLine.words
Value
data('Safe Copy','Possibilities Remain','text')

A.18 Clue Word (Function)

Built in Chapter 3, Scan Record.

FunctionClue Word

Answers with the words a Scan Card shows for a clue: UNLOCKED for 0, HIGHER for 1, LOWER for -1.

PARAMETERS
NameTypeStarts at
clueNumber0
RETURN TYPEText
ACTIONS
1Declare Variable
Type
Text
Name
word
2Ifclue == 0
Then
3Change Variable
Variable
word
Value
data('Safe Copy','Card Unlocked','text')
4Otherwise
5Ifclue == 1
Then
6Change Variable
Variable
word
Value
data('Safe Copy','Card Higher','text')
7Otherwise
8Change Variable
Variable
word
Value
data('Safe Copy','Card Lower','text')
9Return
Value
word

A.19 Lay Out Scan Record

Built in Chapter 3, Scan Record.

Logic ComponentLay Out Scan RecordAttach to: Safe Rules

Makes the record strip when the Safe Room begins: one Code Mark for each code a safe can have, and one Scan Card, with its guess and its clue, for each scan of the budget. The strip and the row of cards keep their width and share it out in equal slots, so the record fits the window whatever the range of codes and the scan budget.

Attach toAny Object
DATA STRUCTURES
Lay Out Scan Record Dataself.layOutScanRecordData
SHARED VARIABLES
NameTypeKindStarting Value
codeMarkObjectConstantNone
stripLeftNumberConstant54.15
stripWidthNumberConstant970
markTopNumberConstant-629
scanCardObjectConstantNone
cardGuessObjectConstantNone
cardClueObjectConstantNone
rowLeftNumberConstant51.5
rowWidthNumberConstant973
cardRoomNumberConstant139
cardTopNumberConstant-695
guessTopNumberConstant-685
clueTopNumberConstant-707
When the Scene Starts
WhenScene Start
1Region
Label
"Code Marks"
Color
#48BAB5
2Change Component Value
Component Value
self.layOutScanRecordData.codeCount
Value
data('Safe Settings','Standard Safe','highestCode') - data('Safe Settings','Standard Safe','lowestCode') + 1
3Change Component Value
Component Value
self.layOutScanRecordData.markSlot
Value
@self.stripWidth / self.layOutScanRecordData.codeCount
4Repeatself.layOutScanRecordData.codeCounttimes
Each time
5Create Instance
Object to Create
@self.codeMark
X
0
Y
0
Created As
mark
6Set Position
Applies to
mark
Position Relative To
Screen
X
@self.stripLeft + (local.index + 0.5) * self.layOutScanRecordData.markSlot
Y
@self.markTop
7Change Variable
Variable
mark.code
Value
data('Safe Settings','Standard Safe','lowestCode') + local.index
8Region
Label
"Scan Cards"
Color
#F3C569
9Change Component Value
Component Value
self.layOutScanRecordData.cardSlot
Value
@self.rowWidth / data('Safe Settings','Standard Safe','scanBudget')
10Change Component Value
Component Value
self.layOutScanRecordData.cardScale
Value
min(1, self.layOutScanRecordData.cardSlot / @self.cardRoom)
11Repeatdata('Safe Settings','Standard Safe','scanBudget')times
Each time
12Create Instance
Object to Create
@self.scanCard
X
0
Y
0
Created As
card
13Set Position
Applies to
card
Position Relative To
Screen
X
@self.rowLeft + (local.index + 0.5) * self.layOutScanRecordData.cardSlot
Y
@self.cardTop
14Set Scale
Applies to
card
Horizontal Scale
self.layOutScanRecordData.cardScale
Vertical Scale
self.layOutScanRecordData.cardScale
15Change Variable
Variable
card.scan
Value
local.index + 1
16Create Instance
Object to Create
@self.cardGuess
X
0
Y
0
Created As
guess
17Set Position
Applies to
guess
Position Relative To
Screen
X
@self.rowLeft + (local.index + 0.5) * self.layOutScanRecordData.cardSlot
Y
@self.guessTop
18Set Scale
Applies to
guess
Horizontal Scale
self.layOutScanRecordData.cardScale
Vertical Scale
self.layOutScanRecordData.cardScale
19Change Variable
Variable
guess.scan
Value
local.index + 1
20Create Instance
Object to Create
@self.cardClue
X
0
Y
0
Created As
clue
21Set Position
Applies to
clue
Position Relative To
Screen
X
@self.rowLeft + (local.index + 0.5) * self.layOutScanRecordData.cardSlot
Y
@self.clueTop
22Set Scale
Applies to
clue
Horizontal Scale
self.layOutScanRecordData.cardScale
Vertical Scale
self.layOutScanRecordData.cardScale
23Change Variable
Variable
clue.scan
Value
local.index + 1

A.20 Record Scan (Function)

Built in Chapter 3, Scan Record.

FunctionRecord Scan

Adds the scan just made to the Scan Log as row "Scan N" (N is the scan's number): its guess, its clue, and the range after the clue narrowed it.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Control Data Row
Action Name
addedRow
Table
Scan Log
Row
text('Scan ', $scans)
Values > guess
$lastGuess
Values > clue
safeRules.safeState.clue
Values > low
$low
Values > high
$high

A.21 Show Code Mark

Built in Chapter 3, Scan Record.

Logic ComponentShow Code MarkAttach to: Code Mark

Colors one Code Mark by what the player knows about its code: gold for the last guess, teal while the code is still possible, dark once it is ruled out.

Attach toAny Object
DATA STRUCTURES
Mark Faceself.markFace
SHARED VARIABLES
NameTypeKindStarting Value
lastGuessColorColorConstant#f3c569
inRangeColorColorConstant#48bab5
ruledOutColorColorConstant#263b47
On Variable Changed · Scans
WhenVariable ChangedGlobal Variable: scans
1Ifself.markFace.code == $lastGuess
Then
2Change Sprite Tint Property
Value
@self.lastGuessColor
3Otherwise
4Ifself.markFace.code >= $low && self.markFace.code <= $high
Then
5Change Sprite Tint Property
Value
@self.inRangeColor
6Otherwise
7Change Sprite Tint Property
Value
@self.ruledOutColor

A.22 Show Scan Card

Built in Chapter 3, Scan Record.

Logic ComponentShow Scan CardAttach to: Card Guess, Card Clue, Scan Card

Shows one piece of a Scan Card (the card, its guess or its clue) once the card's scan has happened, with that scan's guess and clue from the Scan Log, and hides it again when a new safe starts.

Attach toAny Object
DATA STRUCTURES
Card Faceself.cardFace
When Created
WhenCreate
1Set Visible
Visible
No
On Variable Changed · Scans
WhenVariable ChangedGlobal Variable: scans
1Ifself.cardFace.scan <= $scans
Then
2Change Component Value
Component Value
self.cardFace.guess
Value
data('Scan Log', text('Scan ', self.cardFace.scan), 'guess')
3Clue WordFunction
Action Name
cardWords
clue
data('Scan Log', text('Scan ', self.cardFace.scan), 'clue')
4Change Component Value
Component Value
self.cardFace.clue
Value
cardWords.value
5Set Visible
Visible
Yes
6Otherwise
7Set Visible
Visible
No

A.23 Check Keypad Open (Function)

Built in Chapter 4, Computer Search.

FunctionCheck Keypad Open

Answers whether the player may type on the keypad now: while setting a code for the computer (Setup), or while the human cracks a Locked safe.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
RETURN TYPEBoolean
ACTIONS
1Declare Variable
Type
Boolean
Name
isOpen
Value
false
2Change Variable
Variable
isOpen
Value
false
3Check Game State
Action Name
settingCode
Applies to
safeRules
Game State
Setup
4IfsettingCode.value == true
Then
5Change Variable
Variable
isOpen
Value
true
6Check Game State
Action Name
safeIsLocked
Applies to
safeRules
Game State
Locked
7Check Logic Enabled
Action Name
humanCracks
Applies to
safeRules
Logic Component
Human Role
8IfsafeIsLocked.value == true && humanCracks.value == true
Then
9Change Variable
Variable
isOpen
Value
true
10Return
Value
isOpen

A.24 Choose Computer Role (Function)

Built in Chapter 4, Computer Search.

FunctionChoose Computer Role

Hands the safe to the computer if the human has it: turns the Human Role Logic off and the Computer Role Logic on, starts Setup for a new code, and sends roleChosen. If the computer already has it, nothing changes.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Check Logic Enabled
Action Name
humanCracks
Applies to
safeRules
Logic Component
Human Role
2IfhumanCracks.value == true
Then
3Set Logic State
Applies to
safeRules
Logic Component
Human Role
State
Disable
4Set Logic State
Applies to
safeRules
Logic Component
Computer Role
5Start Code SetupFunction
safeRules
safeRules
6Trigger Custom Event
Custom Event
roleChosen

A.25 Choose Human Role (Function)

Built in Chapter 4, Computer Search.

FunctionChoose Human Role

Hands the safe to the human if the computer has it: turns the Computer Role Logic off and the Human Role Logic on, starts a new safe, and sends roleChosen. If the human already has it, nothing changes.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Check Logic Enabled
Action Name
computerCracks
Applies to
safeRules
Logic Component
Computer Role
2IfcomputerCracks.value == true
Then
3Set Logic State
Applies to
safeRules
Logic Component
Computer Role
State
Disable
4Set Logic State
Applies to
safeRules
Logic Component
Human Role
5Start New SafeFunction
safeRules
safeRules
6Trigger Custom Event
Custom Event
roleChosen

A.26 Choose Midpoint (Function)

Built in Chapter 4, Computer Search.

FunctionChoose Midpoint

Answers the computer's next guess for a range of codes: the middle of low and high, rounded down. It is given only the two ends of the range, never the code.

PARAMETERS
NameTypeStarts at
lowNumber0
highNumber0
RETURN TYPENumber
ACTIONS
1Declare Variable
Name
midpoint
Value
0
2Change Variable
Variable
midpoint
Value
floor((low + high) / 2)
3Return
Value
midpoint

A.27 Choose Role

Built in Chapter 4, Computer Search.

Logic ComponentChoose RoleAttach to: Safe Rules

Lets the keyboard choose the role: H for the Human role, C for the Computer role. The role tabs call the same Functions.

Attach toAny Object
DATA STRUCTURES
Safe Stateself.safeState
When Human Is Pressed
WhenCommand PressedCommand: Human
1Choose Human RoleFunction
safeRules
self
When Computer Is Pressed
WhenCommand PressedCommand: Computer
1Choose Computer RoleFunction
safeRules
self

A.28 Computer Role

Built in Chapter 4, Computer Search.

Logic ComponentComputer RoleAttach to: Safe Rules

What the controls do while the computer cracks the safe: Enter locks the code, Space takes one Step, A runs or pauses the search, and R goes back to Setup for a new code. Choose Computer Role and Watch Computer turn this Logic on.

Attach toAny Object
DATA STRUCTURES
Safe Stateself.safeState
When Scan Is Pressed
WhenCommand PressedCommand: Scan
1Lock CodeFunction
safeRules
self
When Step Is Pressed
WhenCommand PressedCommand: Step
1Step OnceFunction
safeRules
self
When Run Is Pressed
WhenCommand PressedCommand: Run
1Run or PauseFunction
safeRules
self
When New Safe Is Pressed
WhenCommand PressedCommand: New Safe
1Start Code SetupFunction
safeRules
self

A.29 Current Situation (Function)

Built in Chapter 4, Computer Search.

FunctionCurrent Situation

Answers which situation the game is in, as the name of a Screen Layout column: human or humanDone in the Human role; in the Computer role codeSetup, searching, running, solved or outOfScans for the phase of the trial and whether Run is on.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
RETURN TYPEText
ACTIONS
1Declare Variable
Type
Text
Name
situation
2Change Variable
Variable
situation
Value
'human'
3Check Logic Enabled
Action Name
computerCracks
Applies to
safeRules
Logic Component
Computer Role
4IfcomputerCracks.value == true
Then
5Check Game State
Action Name
inSetup
Applies to
safeRules
Game State
Setup
6IfinSetup.value == true
Then
7Change Variable
Variable
situation
Value
'codeSetup'
8Check Game State
Action Name
inLocked
Applies to
safeRules
Game State
Locked
9IfinLocked.value == true
Then
10Change Variable
Variable
situation
Value
'searching'
11Check Game State
Action Name
inUnlocked
Applies to
safeRules
Game State
Unlocked
12IfinUnlocked.value == true
Then
13Change Variable
Variable
situation
Value
'solved'
14Check Game State
Action Name
inExhausted
Applies to
safeRules
Game State
Exhausted
15IfinExhausted.value == true
Then
16Change Variable
Variable
situation
Value
'outOfScans'
17Check Logic Enabled
Action Name
runIsOn
Applies to
safeRules
Logic Component
Run Search
18IfrunIsOn.value == true
Then
19Change Variable
Variable
situation
Value
'running'
20Otherwise
21Check Game State
Action Name
safeIsOpen
Applies to
safeRules
Game State
Unlocked
22Check Game State
Action Name
scansUsedUp
Applies to
safeRules
Game State
Exhausted
23IfsafeIsOpen.value == true || scansUsedUp.value == true
Then
24Change Variable
Variable
situation
Value
'humanDone'
25Return
Value
situation

A.30 Human Role

Built in Chapter 4, Computer Search.

Logic ComponentHuman RoleAttach to: Safe Rules

What the controls do while the human cracks the safe: Enter scans the entry and R starts a new safe; Space and A only say that the computer needs a locked code. Choose Human Role turns this Logic on.

Attach toAny Object
DATA STRUCTURES
Safe Stateself.safeState
When Scan Is Pressed
WhenCommand PressedCommand: Scan
1Scan GuessFunction
safeRules
self
When New Safe Is Pressed
WhenCommand PressedCommand: New Safe
1Start New SafeFunction
safeRules
self
When Step Is Pressed
WhenCommand PressedCommand: Step
1Change Variable
Variable
$message
Value
data('Safe Copy','No Code Locked','text')
When Run Is Pressed
WhenCommand PressedCommand: Run
1Change Variable
Variable
$message
Value
data('Safe Copy','No Code Locked','text')

A.31 Lock Code (Function)

Built in Chapter 4, Computer Search.

FunctionLock Code

Locks the entry as the secret code during Setup, if it is a code the safe can have (from the lowest to the highest code). The safe is then Locked and the computer may start its search.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Check Game State
Action Name
settingCode
Applies to
safeRules
Game State
Setup
2IfsettingCode.value == true
Then
3If$entry >= data('Safe Settings','Standard Safe','lowestCode') && $entry <= data('Safe Settings','Standard Safe','highestCode')
Then
4Change Component Value
Component Value
safeRules.safeState.code
Value
$entry
5Change Variable
Variable
$entry
Value
0
6Set Game State
Applies to
safeRules
Game State
Locked
7Change Variable
Variable
$message
Value
data('Safe Copy','Code Sealed','text')
8Otherwise
9Change Variable
Variable
$message
Value
text(data('Safe Copy','Code Outside the Range','text'), ' ', data('Safe Settings','Standard Safe','lowestCode'), ' to ', data('Safe Settings','Standard Safe','highestCode'), '.')
10Otherwise
11Change Variable
Variable
$message
Value
data('Safe Copy','Code Sealed','text')

A.32 Reset Trial (Function)

Built in Chapter 4, Computer Search.

FunctionReset Trial

Starts a fresh trial on the same safe: every code is possible again, nothing has been scanned, the Scan Log is empty, and the keypad display shows the starting entry.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Change Variable
Variable
$low
Value
data('Safe Settings','Standard Safe','lowestCode')
2Change Variable
Variable
$high
Value
data('Safe Settings','Standard Safe','highestCode')
3Change Variable
Variable
$scans
Value
0
4Change Variable
Variable
$lastGuess
Value
0
5Change Component Value
Component Value
safeRules.safeState.clue
Value
0
6Reset Data Table
Table
Scan Log
7Change Variable
Variable
$entry
Value
data('Safe Settings','Standard Safe','startEntry')
8Change Component Value
Component Value
safeRules.safeState.startsNewEntry
Value
true

A.33 Show For Situation (Function)

Built in Chapter 4, Computer Search.

FunctionShow For Situation

Shows or hides one piece for the situation the game is in, as its row of the Screen Layout table says.

PARAMETERS
NameTypeStarts at
pieceObject
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
layoutRowText
ACTIONS
1Current SituationFunction
Action Name
situationNow
safeRules
safeRules
2Ifdata('Screen Layout', layoutRow, situationNow.value) == true
Then
3Set Visible
Applies to
piece
Visible
true
4Otherwise
5Set Visible
Applies to
piece
Visible
false

A.34 Show In Situation

Built in Chapter 4, Computer Search.

Logic ComponentShow In SituationAttach to: Entry Caption, Digit Key, Back Key, Scan Button, New Safe Button, Human Goal, Computer Goal, Search Readout, Code Caption, Last Guess Caption, Found Code Caption, Search Title, Midpoint Formula, Lock Code Button, Change Code Button, Step Button, Run Button, Pause Button, Watch Computer Button

Shows this piece only in the situations its row of the Screen Layout table picks (the keypad, the SCAN and LOCK CODE buttons, the RUN and PAUSE buttons, the Watch computer button, the computer's readout, and the rest), and hides it otherwise.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
safeRulesObjectConstantNone
layoutRowTextConstant(empty)
On Game State Changed
WhenGame State Changed
1Show For SituationFunction
piece
self
safeRules
@self.safeRules
layoutRow
@self.layoutRow
On Role Chosen
WhenroleChosenCustom Event
1Show For SituationFunction
piece
self
safeRules
@self.safeRules
layoutRow
@self.layoutRow
On Run Changed
WhenrunChangedCustom Event
1Show For SituationFunction
piece
self
safeRules
@self.safeRules
layoutRow
@self.layoutRow

A.35 Show Search Readout

Built in Chapter 4, Computer Search.

Logic ComponentShow Search ReadoutAttach to: Search Readout

Keeps the computer's readout line up to date: rewritten whenever the range or the phase can have changed.

Attach toAny Object
DATA STRUCTURES
Readout Lineself.readoutLine
On Game State Changed
WhenGame State Changed
1Write Search ReadoutFunction
readout
self
On Variable Changed · Scans
WhenVariable ChangedGlobal Variable: scans
1Write Search ReadoutFunction
readout
self

A.36 Show Selected Role

Built in Chapter 4, Computer Search.

Logic ComponentShow Selected RoleAttach to: Role Tab

Shows a role tab in gold while its role is the one chosen, and plain otherwise.

Attach toAny Object
SHARED VARIABLES
NameTypeKindStarting Value
safeRulesObjectConstantNone
PER INSTANCE VARIABLES
NameTypeStarting Value
isComputerTabBooleanNo
On Role Chosen
WhenroleChosenCustom Event
1Check Logic Enabled
Action Name
computerCracks
Applies to
@self.safeRules
Logic Component
Computer Role
2IfcomputerCracks.value == self.isComputerTab
Then
3Set Sprite
Sprite
Safe Gold
4Otherwise
5Set Sprite
Sprite
Safe Button

A.37 Start Code Setup (Function)

Built in Chapter 4, Computer Search.

FunctionStart Code Setup

Starts a fresh trial in the Computer role: the player types the code the computer will crack, then locks it.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Reset TrialFunction
safeRules
safeRules
2Change Component Value
Component Value
safeRules.safeState.humanScans
Value
0
3Set Game State
Applies to
safeRules
Game State
Setup
4Change Variable
Variable
$message
Value
data('Safe Copy','Choose a Code','text')

A.38 Take a Step (Function)

Built in Chapter 4, Computer Search.

FunctionTake a Step

Makes one computer turn while the safe is Locked: Choose Midpoint picks the next guess from the range, the guess is shown in the entry, and Scan Guess scans it, the same scanner the human uses.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Check Game State
Action Name
safeIsLocked
Applies to
safeRules
Game State
Locked
2IfsafeIsLocked.value == true
Then
3Choose MidpointFunction
Action Name
nextGuess
low
$low
high
$high
4Change Variable
Variable
$entry
Value
nextGuess.value
5Scan GuessFunction
safeRules
safeRules
6Otherwise
7Change Variable
Variable
$message
Value
data('Safe Copy','No Code Locked','text')

A.39 Write Search Readout (Function)

Built in Chapter 4, Computer Search.

FunctionWrite Search Readout

Writes the computer's readout line: NEXT GUESS with the midpoint Choose Midpoint picks from the range, or, once the safe is Unlocked, SOLVED IN with the number of scans.

PARAMETERS
NameTypeStarts at
readoutObjectStructural
Required Components
Slot NamereadoutLine
Component TypeData Structure
Required SchemaReadout Line
ACTIONS
1Check Game State
Action Name
searchSolved
Applies to
readout
Game State
Unlocked
2IfsearchSolved.value == true
Then
3Change Component Value
Component Value
readout.readoutLine.heading
Value
data('Safe Copy','Solved In','text')
4Change Component Value
Component Value
readout.readoutLine.number
Value
$scans
5If$scans == 1
Then
6Change Component Value
Component Value
readout.readoutLine.unit
Value
data('Safe Copy','One Scan','text')
7Otherwise
8Change Component Value
Component Value
readout.readoutLine.unit
Value
data('Safe Copy','Several Scans','text')
9Otherwise
10Choose MidpointFunction
Action Name
nextGuess
low
$low
high
$high
11Change Component Value
Component Value
readout.readoutLine.heading
Value
data('Safe Copy','Next Guess','text')
12Change Component Value
Component Value
readout.readoutLine.number
Value
nextGuess.value
13Change Component Value
Component Value
readout.readoutLine.unit
Value
''

A.40 Close Myth Lesson (Function)

Built in Chapter 5, Run and Compare.

FunctionClose Myth Lesson

Closes the Myth Lesson: the lesson's keys turn off, the game's controls turn back on, and lessonChanged tells the lesson's pieces and Run Search.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Set Input Context Active
Applies to
safeRules
Input Context
Myth Lesson
Active
false
2Set Input Context Active
Applies to
safeRules
Input Context
Game Controls
3Trigger Custom Event
Custom Event
lessonChanged

A.41 Lesson Keys

Built in Chapter 5, Run and Compare.

Logic ComponentLesson KeysAttach to: Safe Rules

Lets the keyboard open and close the Myth Lesson: F opens it or closes it, and Escape closes it. The Myth lesson and Close buttons call the same Functions.

Attach toAny Object
DATA STRUCTURES
Safe Stateself.safeState
When Lesson Is Pressed
WhenCommand PressedCommand: Lesson
1Open or Close Myth LessonFunction
safeRules
self
When Close Lesson Is Pressed
WhenCommand PressedCommand: Close Lesson
1Close Myth LessonFunction
safeRules
self

A.42 Open Myth Lesson (Function)

Built in Chapter 5, Run and Compare.

FunctionOpen Myth Lesson

Opens the Myth Lesson: the game's controls turn off (the Game Controls Input Context), the lesson's keys turn on (the Myth Lesson Input Context), and lessonChanged tells the lesson's pieces and Run Search.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Set Input Context Active
Applies to
safeRules
Input Context
Game Controls
Active
false
2Set Input Context Active
Applies to
safeRules
Input Context
Myth Lesson
3Trigger Custom Event
Custom Event
lessonChanged

A.43 Open or Close Myth Lesson (Function)

Built in Chapter 5, Run and Compare.

FunctionOpen or Close Myth Lesson

Closes the Myth Lesson if it is open, and opens it otherwise. F and the Myth lesson button call it.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Check Input Context Active
Action Name
lessonIsOpen
Applies to
safeRules
Input Context
Myth Lesson
2IflessonIsOpen.value == true
Then
3Close Myth LessonFunction
safeRules
safeRules
4Otherwise
5Open Myth LessonFunction
safeRules
safeRules

A.44 Run or Pause (Function)

Built in Chapter 5, Run and Compare.

FunctionRun or Pause

Pauses the computer's search if Run is on; otherwise turns Run on, if a locked code is waiting to be cracked.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Check Logic Enabled
Action Name
runIsOn
Applies to
safeRules
Logic Component
Run Search
2IfrunIsOn.value == true
Then
3Set Logic State
Applies to
safeRules
Logic Component
Run Search
State
Disable
4Change Variable
Variable
$message
Value
data('Safe Copy','Paused','text')
5Otherwise
6Check Game State
Action Name
safeIsLocked
Applies to
safeRules
Game State
Locked
7IfsafeIsLocked.value == true
Then
8Set Logic State
Applies to
safeRules
Logic Component
Run Search
9Otherwise
10Change Variable
Variable
$message
Value
data('Safe Copy','No Code Locked','text')

A.46 Show Human Result

Built in Chapter 5, Run and Compare.

Logic ComponentShow Human ResultAttach to: Human Result

Shows the human's result beside the computer's search after Watch computer, and hides it again when a role is chosen or a new code is set up.

Attach toAny Object
DATA STRUCTURES
Result Lineself.resultLine
SHARED VARIABLES
NameTypeKindStarting Value
safeRulesObjectConstantNone
On Role Chosen
WhenroleChosenCustom Event
1Write Human ResultFunction
line
self
safeRules
@self.safeRules
On Game State Changed
WhenGame State Changed
1Write Human ResultFunction
line
self
safeRules
@self.safeRules

A.47 Show With Lesson

Built in Chapter 5, Run and Compare.

Logic ComponentShow With LessonAttach to: Myth Lesson Panel, Lesson Line, Close Lesson Button

Shows this piece of the Myth Lesson while the lesson is open, and hides it while it is closed.

Attach toAny Object
On Lesson Changed
WhenlessonChangedCustom Event
1Check Input Context Active
Action Name
lessonIsOpen
Input Context
Myth Lesson
2IflessonIsOpen.value == true
Then
3Set Visible
Visible
Yes
4Otherwise
5Set Visible
Visible
No

A.48 Step Once (Function)

Built in Chapter 5, Run and Compare.

FunctionStep Once

Takes one Step by hand: Run is turned off first if it is on, so the computer makes exactly this one turn.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Set Logic State
Applies to
safeRules
Logic Component
Run Search
State
Disable
2Take a StepFunction
safeRules
safeRules

A.49 Watch Computer (Function)

Built in Chapter 5, Run and Compare.

FunctionWatch Computer

Hands the human's safe to the computer after the human's attempt has ended: keeps the human's result, turns the Computer role on, and starts a fresh trial on the same code, already locked, so the computer searches it at once.

PARAMETERS
NameTypeStarts at
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Change Component Value
Component Value
safeRules.safeState.humanScans
Value
$scans
2Check Game State
Action Name
humanUnlocked
Applies to
safeRules
Game State
Unlocked
3Change Component Value
Component Value
safeRules.safeState.humanUnlocked
Value
humanUnlocked.value
4Set Logic State
Applies to
safeRules
Logic Component
Human Role
State
Disable
5Set Logic State
Applies to
safeRules
Logic Component
Computer Role
6Reset TrialFunction
safeRules
safeRules
7Change Variable
Variable
$entry
Value
0
8Set Game State
Applies to
safeRules
Game State
Locked
9Change Variable
Variable
$message
Value
data('Safe Copy','Same Code','text')
10Trigger Custom Event
Custom Event
roleChosen

A.50 Write Human Result (Function)

Built in Chapter 5, Run and Compare.

FunctionWrite Human Result

Shows the human's kept result on the result line while the computer searches the human's code (after Watch computer), and hides the line otherwise. line: the text that shows the result. safeRules: the Object whose Safe State keeps the human's result (humanScans, humanUnlocked).

PARAMETERS
NameTypeStarts at
lineObjectStructural
Required Components
Slot NameresultLine
Component TypeData Structure
Required SchemaResult Line
safeRulesObjectStructural
Required Components
Slot NamesafeState
Component TypeData Structure
Required SchemaSafe State
ACTIONS
1Check Logic Enabled
Action Name
computerCracks
Applies to
safeRules
Logic Component
Computer Role
2IfcomputerCracks.value == true && safeRules.safeState.humanScans > 0
Then
3Change Component Value
Component Value
line.resultLine.scansUsed
Value
safeRules.safeState.humanScans
4IfsafeRules.safeState.humanScans == 1
Then
5Change Component Value
Component Value
line.resultLine.scanWord
Value
data('Safe Copy','One Scan','text')
6Otherwise
7Change Component Value
Component Value
line.resultLine.scanWord
Value
data('Safe Copy','Several Scans','text')
8IfsafeRules.safeState.humanUnlocked == true
Then
9Change Component Value
Component Value
line.resultLine.outcome
Value
data('Safe Copy','Card Unlocked','text')
10Otherwise
11Change Component Value
Component Value
line.resultLine.outcome
Value
data('Safe Copy','Out of Scans','text')
12Set Visible
Applies to
line
Visible
true
13Otherwise
14Set Visible
Applies to
line
Visible
false