6ZZOMSZRHZ67J5N64GYR4GO7JG3O45EJBRRNRDJS3T533VPVRCAAC ############## Functions ##############void run_tests(string name, array tests)number count = 0loop test in testsif !equal(test[0], test[1])Print(name + " " + count + ": fail")Print("left: " + test[0])Print("right: " + test[1])endcount += 1endPrint(name + " tests done.")end
# test.sprakLibrary for testing functions/programs.## Usage* TODO.## Functions### `run_tests`Runs unit tests that test for equality of outputs#### Type`string -> [[A, A]] -> void`#### Arguments* `name`: Name of the curent test.* `tests`: Array of output pairs to compare.#### Examples```sprak# TODO```#### Imports* equality.sprak
################ serde.sprak ################string deserialise_string(string input)string output = ""bool escaped = falseloop character in inputif character != "\"if character != '"'output += characterendelse if escapedoutput += characterescaped = falseelse if character == '\'escaped = trueendendreturn outputendbool is_digit(string input)number code = CharToInt(input)if code >= -49if code <= -40return trueendendreturn falseend# Types:# * 0: none# * 1: bool# * 2: number# * 3: string# * 4: arrayvar deserialise_array(string input)array accumulator = []bool in_string = falsebool escaped = falsebool in_value = falsestring buffer = ""number key_type = 0bool key_bool = falsenumber key_number = 0string key_string = ""number value_type = 0bool value_bool = falsenumber value_number = 0string value_string = ""array contexts = []loop character in inputbool is_numeric = falseif character == ":"if !in_stringin_value = trueif key_type == 2key_number = bufferbuffer = ""endelse if in_valuevalue_string += ":"elsekey_string += ":"endelse if character == ","if !in_stringif key_type == 2if value_type == 3accumulator[key_number] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_number] = value_numberelse if value_type == 1accumulator[key_number] = value_boolendelse if key_type == 3if value_type == 3accumulator[key_string] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_string] = value_numberelse if value_type == 1accumulator[key_string] = value_boolendelse if key_type == 1if value_type == 3accumulator[key_bool] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_bool] = value_numberelse if value_type == 1accumulator[key_bool] = value_boolendendin_value = falsebuffer = ""key_string = ""value_string = ""else if in_valuevalue_string += ","elsekey_string += ","endelse if is_digit(character)is_numeric = trueelse if character == "."is_numeric = trueelse if character == "-"is_numeric = trueelse if character == '"'if !in_stringin_string = trueif in_valuevalue_type = 3elsekey_type = 3endelse if !escapedin_string = falseelse if in_valuevalue_string += '"'elsekey_string += '"'endelse if character == "t"if !in_stringif in_valuevalue_bool = truevalue_type = 1elsekey_bool = truekey_type = 1endelse if in_valuevalue_string += "t"elsekey_string += "t"endelse if character == "f"if !in_stringif in_valuevalue_bool = falsevalue_type = 1elsekey_bool = falsekey_type = 1endelse if in_valuevalue_string += "f"elsekey_string += "f"endelse if character == "{"if !in_stringif key_type == 2Append(contexts, [accumulator, key_type, key_number])else if key_type == 0Append(contexts, [accumulator, key_type])else if key_type == 3Append(contexts, [accumulator, key_type, key_string])elseAppend(contexts, [accumulator, key_type, key_bool])endaccumulator = []elsevalue_string += "{"endelse if character == "}"if !in_stringif key_type == 2if value_type == 3accumulator[key_number] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_number] = value_numberelse if value_type == 1accumulator[key_number] = value_boolendelse if key_type == 3if value_type == 3accumulator[key_string] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_string] = value_numberelse if value_type == 1accumulator[key_string] = value_boolendelse if key_type == 1if value_type == 3accumulator[key_bool] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_bool] = value_numberelse if value_type == 1accumulator[key_bool] = value_boolendendarray last_context = contexts[Count(contexts) - 1]array last_accumulator = last_context[0]number last_key_type = last_context[1]if last_key_type != 0last_accumulator[last_context[2]] = accumulatorelsereturn accumulatorendaccumulator = last_accumulatorvalue_type = 4Remove(contexts, Count(contexts) - 1)elsevalue_string += "}"endelse if character == "\"if !escapedescaped = trueelseescaped = falseif in_valuevalue_string += "\"elsekey_string += "\"endendelse if in_valuevalue_string += characterelsekey_string += characterendif is_numericif !in_stringbuffer += characterif in_valuevalue_type = 2elsekey_type = 2endelse if in_valuevalue_string += characterelsekey_string += characterendendendendvar deserialise(string input)if input[0] == "{"return deserialise_array(input)else if is_digit(input[0])number output = inputreturn outputelse if input[0] == "-"number output = inputreturn outputelse if input[0] == '"'return deserialise_string(input)else if input == "t"return trueelse if input == "f"return falseendend################### equality.sprak ###################bool equal_array(array first, array second)if Count(first) == Count(second)if "" + first == "" + secondloop key in GetIndexes(first)if !HasIndex(second, key)return falseelse if !equal(first[key], second[key])return falseendendreturn trueendendreturn falseendbool equal(var first, var second)string type_first = Type(first)if type_first == Type(second)if type_first != "array"return first == secondendreturn equal_array(first, second)endreturn falseend################ array.sprak ################bool has(var test_element, array input)loop element in inputif equal(element, test_element)return trueendendreturn falseend############## Functions ##############array supply(array overrides, string function)string MemoryAPI_thing = "FinanceComputer"string TingrunnerAPI_thing = "PoliceOfficeInterior_MinistryOfficeWorkstationComputer_1"string name = Name()if HasIndex(overrides, "MemoryAPI")MemoryAPI_thing = overrides["MemoryAPI"]endif HasIndex(overrides, "TingrunnerAPI")TingrunnerAPI_thing = overrides["TingrunnerAPI"]endvar MemoryAPIif MemoryAPI_thing != nameMemoryAPI = Connect(MemoryAPI_thing)elsereturn [false, "MemoryAPI unavailable."]endvar TingrunnerAPIif TingrunnerAPI_thing != nameTingrunnerAPI = Connect(TingrunnerAPI_thing)elsereturn [false, "TingrunnerAPI unavailable."]endarray skip_types = ["floppy", "navnode", "bed", "point", "seat", "locker", "memory", "portal", "character", "map", "suitcase", "goods"]array skip_things = ["ComputerTerminalBoard1_ComputerTerminalBoard1", "Hotel_Diner_Fountain", "TrainingCube", "Internet_Internet_MediumComputer_10", "Internet_MediumComputer", "ArcadeHall_ArcadeMachine_ArcadeMachine_3"]var load_bufferif !HasIndex(overrides, "skip_types")load_buffer = MemoryAPI.LoadMemory("skip_types")if load_buffer != 0skip_types = deserialise(load_buffer)endelseskip_types = overrides["skip_types"]endif !HasIndex(overrides, "skip_things")load_buffer = MemoryAPI.LoadMemory("skip_things")if load_buffer != 0skip_things = deserialise(load_buffer)endelseskip_things = overrides["skip_things"]endif HasIndex(overrides, "more_skip_types")loop type in overrides["more_skip_types"]if !has(type, skip_types)Append(skip_types, type)endendendif HasIndex(overrides, "more_skip_things")loop thing in overrides["more_skip_things"]if !has(thing, skip_things)Append(skip_things, thing)endendendload_buffer = MemoryAPI.LoadMemory(function)if load_buffer != 0if load_buffer != nameif !has(load_buffer, skip_things)if !has(TingrunnerAPI.GetTypeOfThing(load_buffer), skip_types)var connection = Connect(load_buffer)if connection.HasFunction(function)return [true, connection]endendendendendload_buffer = 0loop room in TingrunnerAPI.GetAllRooms()loop thing in TingrunnerAPI.GetThingsInRoom(room)if thing != nameif !has(thing, skip_things)if !has(TingrunnerAPI.GetTypeOfThing(thing), skip_types)var connection = Connect(thing)if connection.HasFunction(function)MemoryAPI.SaveMemory(function, thing)return [true, connection]endendendendendendreturn [false, "`" + function + "` not found."]end
# supply.sprakLibrary for supplying connections.## Usage* Once in a while, keep re-runnning the "skip.sprak" script until completion to update the list of types and things to skip.* Don't use on "FinanceComputer" or "PoliceOfficeInterior_MinistryOfficeWorkstationComputer_1".## Functions### `supply`Returns `[true, connection]` where `connection` is a connection to a thing that supplies the input function if anything in the game world is able to supply the function, otherwise `[false, error_message]` where `error_message` is a `string` about what caused the failure. If it hasn't yet been cached, the thing that supplies the function is then saved in the memory of "FinanceComputer" (or the thing overriding it) using the name of the function as key to speed up later access to the same function.#### Type`["MemoryAPI"?: string, "TingrunnerAPI"?: string, "skip_types"?: [string], "skip_things"?: [string], "more_skip_types"?: [string], "more_skip_things"?: [string]] -> string -> [true, connection] | [false, string]`#### Arguments* `overrides`: `array` that may contain data to replace or supplement variables used by the function.* `function`: Function to find a connection for.#### Examples```sprakvar connection = supply([], "IsNight")Say("" + connection[1].IsNight())```#### Imports* serde.sprak* `deserialise`* equality.sprak* array.sprak* `has`
DisconnectAll()################ serde.sprak ################string serialise_string(string input)string output = ""loop character in inputif character == '"'output += "\"else if character == "\"output += "\"endoutput += characterendreturn '"' + output + '"'endstring serialise_array(array input)string output = ""bool not_start = falseloop key in GetIndexes(input)string key_type = Type(key)if key_type != "array"if not_startoutput += ","elsenot_start = trueendoutput += serialise(key) + ":" + serialise(input[key])endendreturn "{" + output + "}"endstring serialise(var input)string input_type = Type(input)if input_type == "unknown"string output = ""loop character in "" + inputif character != "i"output += characterendendreturn outputelse if input_type == "string"return serialise_string(input)else if input_type == "number"return "" + inputelse if input_type == "bool"if inputreturn "t"endreturn "f"else if input_type == "array"return serialise_array(input)endendstring deserialise_string(string input)string output = ""bool escaped = falseloop character in inputif character != "\"if character != '"'output += characterendelse if escapedoutput += characterescaped = falseelse if character == '\'escaped = trueendendreturn outputendbool is_digit(string input)number code = CharToInt(input)if code >= -49if code <= -40return trueendendreturn falseend# Types:# * 0: none# * 1: bool# * 2: number# * 3: string# * 4: arrayvar deserialise_array(string input)array accumulator = []bool in_string = falsebool escaped = falsebool in_value = falsestring buffer = ""number key_type = 0bool key_bool = falsenumber key_number = 0string key_string = ""number value_type = 0bool value_bool = falsenumber value_number = 0string value_string = ""array contexts = []loop character in inputbool is_numeric = falseif character == ":"if !in_stringin_value = trueif key_type == 2key_number = bufferbuffer = ""endelse if in_valuevalue_string += ":"elsekey_string += ":"endelse if character == ","if !in_stringif key_type == 2if value_type == 3accumulator[key_number] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_number] = value_numberelse if value_type == 1accumulator[key_number] = value_boolendelse if key_type == 3if value_type == 3accumulator[key_string] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_string] = value_numberelse if value_type == 1accumulator[key_string] = value_boolendelse if key_type == 1if value_type == 3accumulator[key_bool] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_bool] = value_numberelse if value_type == 1accumulator[key_bool] = value_boolendendin_value = falsebuffer = ""key_string = ""value_string = ""else if in_valuevalue_string += ","elsekey_string += ","endelse if is_digit(character)is_numeric = trueelse if character == "."is_numeric = trueelse if character == "-"is_numeric = trueelse if character == '"'if !in_stringin_string = trueif in_valuevalue_type = 3elsekey_type = 3endelse if !escapedin_string = falseelse if in_valuevalue_string += '"'elsekey_string += '"'endelse if character == "t"if !in_stringif in_valuevalue_bool = truevalue_type = 1elsekey_bool = truekey_type = 1endelse if in_valuevalue_string += "t"elsekey_string += "t"endelse if character == "f"if !in_stringif in_valuevalue_bool = falsevalue_type = 1elsekey_bool = falsekey_type = 1endelse if in_valuevalue_string += "f"elsekey_string += "f"endelse if character == "{"if !in_stringif key_type == 2Append(contexts, [accumulator, key_type, key_number])else if key_type == 0Append(contexts, [accumulator, key_type])else if key_type == 3Append(contexts, [accumulator, key_type, key_string])elseAppend(contexts, [accumulator, key_type, key_bool])endaccumulator = []elsevalue_string += "{"endelse if character == "}"if !in_stringif key_type == 2if value_type == 3accumulator[key_number] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_number] = value_numberelse if value_type == 1accumulator[key_number] = value_boolendelse if key_type == 3if value_type == 3accumulator[key_string] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_string] = value_numberelse if value_type == 1accumulator[key_string] = value_boolendelse if key_type == 1if value_type == 3accumulator[key_bool] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_bool] = value_numberelse if value_type == 1accumulator[key_bool] = value_boolendendarray last_context = contexts[Count(contexts) - 1]array last_accumulator = last_context[0]number last_key_type = last_context[1]if last_key_type != 0last_accumulator[last_context[2]] = accumulatorelsereturn accumulatorendaccumulator = last_accumulatorvalue_type = 4Remove(contexts, Count(contexts) - 1)elsevalue_string += "}"endelse if character == "\"if !escapedescaped = trueelseescaped = falseif in_valuevalue_string += "\"elsekey_string += "\"endendelse if in_valuevalue_string += characterelsekey_string += characterendif is_numericif !in_stringbuffer += characterif in_valuevalue_type = 2elsekey_type = 2endelse if in_valuevalue_string += characterelsekey_string += characterendendendendvar deserialise(string input)if input[0] == "{"return deserialise_array(input)else if is_digit(input[0])number output = inputreturn outputelse if input[0] == "-"number output = inputreturn outputelse if input[0] == '"'return deserialise_string(input)else if input == "t"return trueelse if input == "f"return falseendend################### equality.sprak ###################bool equal_array(array first, array second)if Count(first) == Count(second)if "" + first == "" + secondloop key in GetIndexes(first)if !HasIndex(second, key)return falseelse if !equal(first[key], second[key])return falseendendreturn trueendendreturn falseendbool equal(var first, var second)string type_first = Type(first)if type_first == Type(second)if type_first != "array"return first == secondendreturn equal_array(first, second)endreturn falseend################ array.sprak ################bool has(array input, var test_element)loop element in inputif equal(element, test_element)return trueendendreturn falseend############## Functions ##############bool no_SprakAPI(string thing)return Connect(thing).HasFunction("") == 0end######### Main #########ClearText()string name = Name()string MemoryAPI = Connect("FinanceComputer")string TingrunnerAPI = Connect("PoliceOfficeInterior_MinistryOfficeWorkstationComputer_1")array skip_types = []skip_types[0] = "floppy"array skip_things = []var load_buffer = MemoryAPI.LoadMemory("skip_types")if load_buffer != 0skip_types = deserialise(load_buffer)endload_buffer = MemoryAPI.LoadMemory("skip_things")if load_buffer != 0skip_things = deserialise(load_buffer)endload_buffer = 0bool seen_last_thing = falsestring last_thing = ""number number_buffer = Count(skip_things)if number_buffer > 0last_thing = skip_things[number_buffer - 1]elseseen_last_thing = trueendloop room in TingrunnerAPI.GetAllRooms()loop thing in TingrunnerAPI.GetThingsInRoom(room)if seen_last_thingstring thing_type = TingrunnerAPI.GetTypeOfThing(thing)if thing != nameif !has(skip_types, thing_type)if !has(skip_things, thing)Append(skip_things, thing)MemoryAPI.SaveMemory("skip_things", serialise(skip_things))if no_SprakAPI(thing)Append(skip_types, thing_type)MemoryAPI.SaveMemory("skip_types", serialise(skip_types))endRemove(skip_things, Count(skip_things) - 1)endendendelse if thing == last_thingseen_last_thing = trueendendendMemoryAPI.SaveMemory("skip_things", serialise(skip_things))Say("Done.")DisconnectAll()
# skip.sprakFinds and saves the names of things with broken code and types with no SprakAPI (no `HasFunction` function). Saves the serialised results to the memory of "FinanceComputer" using the keys "skip_types" for the types "skip_things" for the names.## Usage* Don't run the code on "FinanceComputer" or "PoliceOfficeInterior_MinistryOfficeWorkstationComputer_1".* Save the code onto a thing that has the `Say` and `Connect` functions. A drink would work, but a computer would be more ideal, as the latter's code execution speed can be increased using screwdrivers.* Run the code until it causes an error or until completion. I recommend pausing the game whilst the code is running and periodically checking if it's done as pausing allows code to run faster. It is critical that the code is not interrupted whilst it's running (i.e., don't re-hack the thing/re-run the code) as this will cause incorrect outputs.* Repeat the previous step until a notification appears with the "Done." message. I recommend saving after each time the code errors/finishes in case of accidents.## Functions### `no_SprakAPI`Determines if the thing has SprakAPI.#### Type`string -> bool`#### Arguments* `thing`: Thing to test.#### Examples```sprak# TODO```## Imports* supply.sprak* `hardcoded_supply`* serde.sprak* equality.sprak* array.sprak* `has`
################### equality.sprak ###################bool equal_array(array first, array second)if Count(first) == Count(second) && "" + first == "" + secondloop key in GetIndexes(first)if !HasIndex(second, key)return falseelse if !equal(first[key], second[key])return falseendendreturn trueendreturn falseendbool equal(var first, var second)string type_first = Type(first)if type_first == Type(second)if type_first != "array"return first == secondendreturn equal_array(first, second)endreturn falseend############### test.sprak ###############void run_tests(string name, array tests)number count = 0loop test in testsif !equal(test[0], test[1])Print(name + " " + count + ": fail")Print("left: " + test[0])Print("right: " + test[1])endcount += 1endPrint(name + " tests done.")end############## Functions ##############void test_serialise_string()string name = "serialise_string"array tests = []Append(tests, [serialise_string('a'), '"a"'])Append(tests, [serialise_string(''), '""'])Append(tests, [serialise_string('\'), '"\\"'])Append(tests, [serialise_string('"'), '"\""'])Append(tests, [serialise_string('\\'), '"\\\\"'])run_tests(name, tests)endvoid test_serialise_array()string name = "serialise_array"array tests = []Append(tests, [serialise_array([false]), '{0:f}'])Append(tests, [serialise_array([-273.15]), '{0:-273.15}'])Append(tests, [serialise_array([""]), '{0:""}'])Append(tests, [serialise_array([[]]), '{0:{}}'])Append(tests, [serialise_array([]), '{}'])run_tests(name, tests)endvoid test_serialise()string name = "serialise"array tests = []Append(tests, [serialise(false), 'f'])Append(tests, [serialise(-273.15), '-273.15'])Append(tests, [serialise(""), '""'])Append(tests, [serialise([]), '{}'])array a = [false]array keys = GetIndexes(a)Append(tests, [serialise(keys[0]), '0'])run_tests(name, tests)endvoid test_deserialise_string()string name = "deserialise_string"array tests = []Append(tests, [deserialise_string('"a"'), 'a'])Append(tests, [deserialise_string('""'), ''])Append(tests, [deserialise_string('"\\"'), '\'])Append(tests, [deserialise_string('"\""'), '"'])Append(tests, [deserialise_string('"\\\\"'), '\\'])run_tests(name, tests)endvoid test_is_digit()string name = "is_digit"array tests = []Append(tests, [is_digit("0"), true])Append(tests, [is_digit("1"), true])Append(tests, [is_digit("2"), true])Append(tests, [is_digit("3"), true])Append(tests, [is_digit("4"), true])Append(tests, [is_digit("5"), true])Append(tests, [is_digit("6"), true])Append(tests, [is_digit("7"), true])Append(tests, [is_digit("8"), true])Append(tests, [is_digit("9"), true])Append(tests, [is_digit("a"), false])run_tests(name, tests)endvoid test_deserialise_array()string name = "deserialise_array"array tests = []array a = []a = deserialise_array('{0:f}')Append(tests, [a, [false]])a = deserialise_array('{0:-273.15}')Append(tests, [a, [-273.15]])a = deserialise_array('{0:"a"}')Append(tests, [a, ["a"]])a = deserialise_array('{0:""}')Append(tests, [a, [""]])a = deserialise_array('{0:{}}')Append(tests, [a, [[]]])a = deserialise_array('{}')Append(tests, [a, []])run_tests(name, tests)endvoid test_deserialise()string name = "deserialise"array tests = []Append(tests, [deserialise('f'), false])Append(tests, [deserialise('-273.15'), -273.15])Append(tests, [deserialise('""'), ""])Append(tests, [deserialise('{}'), []])array a = [false]array keys = GetIndexes(a)number b = keys[0]Append(tests, [deserialise('0'), b])run_tests(name, tests)endDisconnectAll()ClearText()test_serialise_string()test_serialise_array()test_serialise()test_deserialise_string()test_is_digit()test_deserialise_array()test_deserialise()
################ serde.sprak ################string serialise_string(string input)string output = ""loop character in inputif character == '"'output += "\"else if character == "\"output += "\"endoutput += characterendreturn '"' + output + '"'endstring serialise_array(array input)string output = ""bool not_start = falseloop key in GetIndexes(input)string key_type = Type(key)if key_type != "array"if not_startoutput += ","elsenot_start = trueendoutput += serialise(key) + ":" + serialise(input[key])endendreturn "{" + output + "}"endstring serialise(var input)string input_type = Type(input)if input_type == "unknown"string output = ""loop character in "" + inputif character != "i"output += characterendendreturn outputelse if input_type == "string"return serialise_string(input)else if input_type == "number"return "" + inputelse if input_type == "bool"if inputreturn "t"endreturn "f"else if input_type == "array"return serialise_array(input)endendstring deserialise_string(string input)string output = ""bool escaped = falseloop character in inputif character != "\"if character != '"'output += characterendelse if escapedoutput += characterescaped = falseelse if character == '\'escaped = trueendendreturn outputendbool is_digit(string input)number code = CharToInt(input)if code >= -49if code <= -40return trueendendreturn falseend# Types:# * 0: none# * 1: bool# * 2: number# * 3: string# * 4: arrayvar deserialise_array(string input)array accumulator = []bool in_string = falsebool escaped = falsebool in_value = falsestring buffer = ""number key_type = 0bool key_bool = falsenumber key_number = 0string key_string = ""number value_type = 0bool value_bool = falsenumber value_number = 0string value_string = ""array contexts = []loop character in inputbool is_numeric = falseif character == ":"if !in_stringin_value = trueif key_type == 2key_number = bufferbuffer = ""endelse if in_valuevalue_string += ":"elsekey_string += ":"endelse if character == ","if !in_stringif key_type == 2if value_type == 3accumulator[key_number] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_number] = value_numberelse if value_type == 1accumulator[key_number] = value_boolendelse if key_type == 3if value_type == 3accumulator[key_string] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_string] = value_numberelse if value_type == 1accumulator[key_string] = value_boolendelse if key_type == 1if value_type == 3accumulator[key_bool] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_bool] = value_numberelse if value_type == 1accumulator[key_bool] = value_boolendendin_value = falsebuffer = ""key_string = ""value_string = ""else if in_valuevalue_string += ","elsekey_string += ","endelse if is_digit(character)is_numeric = trueelse if character == "."is_numeric = trueelse if character == "-"is_numeric = trueelse if character == '"'if !in_stringin_string = trueif in_valuevalue_type = 3elsekey_type = 3endelse if !escapedin_string = falseelse if in_valuevalue_string += '"'elsekey_string += '"'endelse if character == "t"if !in_stringif in_valuevalue_bool = truevalue_type = 1elsekey_bool = truekey_type = 1endelse if in_valuevalue_string += "t"elsekey_string += "t"endelse if character == "f"if !in_stringif in_valuevalue_bool = falsevalue_type = 1elsekey_bool = falsekey_type = 1endelse if in_valuevalue_string += "f"elsekey_string += "f"endelse if character == "{"if !in_stringif key_type == 2Append(contexts, [accumulator, key_type, key_number])else if key_type == 0Append(contexts, [accumulator, key_type])else if key_type == 3Append(contexts, [accumulator, key_type, key_string])elseAppend(contexts, [accumulator, key_type, key_bool])endaccumulator = []elsevalue_string += "{"endelse if character == "}"if !in_stringif key_type == 2if value_type == 3accumulator[key_number] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_number] = value_numberelse if value_type == 1accumulator[key_number] = value_boolendelse if key_type == 3if value_type == 3accumulator[key_string] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_string] = value_numberelse if value_type == 1accumulator[key_string] = value_boolendelse if key_type == 1if value_type == 3accumulator[key_bool] = value_stringelse if value_type == 2value_number = bufferaccumulator[key_bool] = value_numberelse if value_type == 1accumulator[key_bool] = value_boolendendarray last_context = contexts[Count(contexts) - 1]array last_accumulator = last_context[0]number last_key_type = last_context[1]if last_key_type != 0last_accumulator[last_context[2]] = accumulatorelsereturn accumulatorendaccumulator = last_accumulatorvalue_type = 4Remove(contexts, Count(contexts) - 1)elsevalue_string += "}"endelse if character == "\"if !escapedescaped = trueelseescaped = falseif in_valuevalue_string += "\"elsekey_string += "\"endendelse if in_valuevalue_string += characterelsekey_string += characterendif is_numericif !in_stringbuffer += characterif in_valuevalue_type = 2elsekey_type = 2endelse if in_valuevalue_string += characterelsekey_string += characterendendendendvar deserialise(string input)if input[0] == "{"return deserialise_array(input)else if is_digit(input[0])number output = inputreturn outputelse if input[0] == "-"number output = inputreturn outputelse if input[0] == '"'return deserialise_string(input)else if input == "t"return trueelse if input == "f"return falseendend
# serde.sprakLibrary for (de)serialising data.## Functions### `serialise_string`Returns the serialised form of input where `\` and `"` characters have been prepended with `\`.#### Type`string -> string`#### Arguments* `input`: String to serialise.#### Examples```sprakPrint(equal(serialise_string('foo"\\'), 'foo\"\\\\'))```### `serialise_array`Returns the serialised version of an `array`. Excludes elements whose keys are not of type `bool`, `number`, `string`, or `unknown`. Keys of type `unknown` are assumed to be `array` indices and will be converted to `number`.#### Type`array -> string`#### Arguments* `input`: Array to serialise.#### Examples```sprakPrint(equal(serialise_array([true, false]), "{0:t,1:f}"))```### `serialise`Returns the serialised version of the input. Assumes data of type `unknown` are `array` indices and are converted to `number`. Data of type `number` are rounded to include only up to 6 decimal places of precision.#### Type`var -> string`#### Arguments* `input`: Input to serialise.#### Examples```sprakPrint(equal(serialise(true), "t"))Print(equal(serialise(false), "f"))Print(equal(serialise(-273.15), "-273.15"))Print(equal(serialise([true, "false"]) == '{0:t,1:"false"}'))```### `deserialise_string`Returns the deserialised form of the input.#### Type`string -> string`#### Arguments* `input`: Serialised string to deserialise.#### Examples```sprakPrint(equal(deserialise_string('"foo\"\\\\"'), 'foo"\\'))```### `is_digit`Determines if the input character is a numeric digit.#### Type`string -> bool`#### Arguments* `input`: Character to test.#### Examples```sprakPrint(is_digit(0))Print(!is_digit(a))```### `deserialise_array`Returns the deserialised form of the input.Assumptions:* "\\" and whitespace characters only occur in strings.* Keys are only of type `bool`, `number` or `string`.* Input is valid.#### Type`string -> array`#### Arguments* `input`: Serialised array to deserialise.#### Examples```sprakPrint(equal(deserialise_array("{0:t,1:f}"), [true, false]))```### `deserialise`Returns the deserialised form of the input.Assumptions:* "\\" and whitespace characters only occur in strings.* `array` keys are only of type `bool`, `number` or `string`.* Input is valid.#### Type`string -> var`#### Arguments* `input`: Input to deserialise.#### Examples```sprakPrint(equal(deserialise("t"), true))Print(equal(deserialise("f"), false))Print(equal(deserialise("-273.15"), -273.15))Print(equal(deserialise('{0:t,1:"false"}'), [true, "false"]))```## TODO* Replace recursions with iterations in:* `serialise_array` and `serialise`* Add an option to serialise numbers using more precision.
bool equal_array(array first, array second)if Count(first) == Count(second)if "" + first == "" + secondloop key in GetIndexes(first)if !HasIndex(second, key)return falseelse if !equal(first[key], second[key])return falseendendreturn trueendendreturn falseendbool equal(var first, var second)string type_first = Type(first)if type_first == Type(second)if type_first != "array"return first == secondendreturn equal_array(first, second)endreturn falseend
# serde.sprakLibrary for testing data equality.## Functions### `equal_array`Determines if both inputs are equal to each other#### Type`array -> array -> bool`#### Arguments* `first`: Input to compare with `second`.* `second`: Input to compare with `first`.#### Examples```sprak# TODO```### `equal`Determines if both inputs are equal to each other#### Type`var -> var -> bool`#### Arguments* `first`: Input to compare with `second`.* `second`: Input to compare with `first`.#### Examples```sprakPrint(equal(true, true))array a = []a[1] = 1a[0] = 0Print(equal([0, 1], a)[1])Print(!equal(true, false)[1])array b = []Append(b, [0])array c = []Append(c, b[0])Print(!equal(b, b)[0])```
{"folders": [{"name": "else_heart_break_scripts","path": "."},{"name": "else_heart_break","path": "../../../../else_heart_break"},{"name": "sprak-language-extension","path": "../../../../projects/sprak-language-extension"},{"path": "../else_heart_break_scripts.1639998913"}],"settings": {}}
################ array.sprak ################bool has(var elem, array arr)loop element in arrif equal(element, elem)return trueendendreturn falseend
# serde.sprakLibrary for `array` data.## Functions### `has`Determines if an array contains an element.#### Type`A -> array A -> bool`#### Arguments* `elem`: The value to search for.* `arr`: Array to search in.#### Examples```sprak# TODO```#### Imports* equality.sprak* `equal_array`* `equal`
# else-Heart.BreakCode for items in the game [else Heart.Break()](http://elseheartbreak.com/ "else Heart.Break() Homepage").---## Notes* `bool` operators in Sprak don't seem to short-circuit. Unconcise usage of conditionals in this project may have been used to emulate short-circuiting `bool` operators.* Some functions have long execution durations and may stop after a while. To prevent this, pause the game when running them because they continue to run (and at a faster speed) even when the game is paused.---## LicenseThis software is distributed and licensed under the terms of the [Blue Oak Model License 1.0.0](https://web.archive.org/web/20190309191626/https://blueoakcouncil.org/license/1.0.0).### ContributionUnless you explicitly state otherwise, any contribution submitted for inclusion in this software by you shall be licensed as above, without any additional terms or conditions.
# Blue Oak Model LicenseVersion 1.0.0## PurposeThis license gives everyone as much permission to work withthis software as possible, while protecting contributorsfrom liability.## AcceptanceIn order to receive this license, you must agree to itsrules. The rules of this license are both obligationsunder that agreement and conditions to your license.You must not do anything with this software that triggersa rule that you cannot or will not follow.## CopyrightEach contributor licenses you to do everything with thissoftware that would otherwise infringe that contributor'scopyright in it.## NoticesYou must ensure that everyone who gets a copy ofany part of this software from you, with or withoutchanges, also gets the text of this license or a link to<https://blueoakcouncil.org/license/1.0.0>.## ExcuseIf anyone notifies you in writing that you have notcomplied with [Notices](#notices), you can keep yourlicense by taking all practical steps to comply within 30days after the notice. If you do not do so, your licenseends immediately.## PatentEach contributor licenses you to do everything with thissoftware that would otherwise infringe any patent claimsthey can license or become able to license.## ReliabilityNo contributor can revoke this license.## No Liability***As far as the law allows, this software comes as is,without any warranty or condition, and no contributorwill be liable to anyone for any damages related to thissoftware or this license, under any kind of legal claim.***
.git.DS_Store