Else Heart.Break()

Else Heart.Break()

55 ratings
Coding Guide - Not only first steps
By Balthasar
The aim of this guide is to show you some of the possibilities, the game provides. Also it covers some basic coding issues.

I don't want to start from scratch but i'll still try to explain every step in detail.
2
   
Award
Favorite
Favorited
Unfavorite
Necessary Tools
You'll need a modifier of course. If you don't own one yet look into my guide for lockpicking to get one.

Another helpful tool is the teleporting device but it's not necessary for our case.

The most important thing is to find some computer or object that has all functions you want to use. Some basic interface like the computer at the reception of your hotel should be ok for now.



Just uncommend the existing code with "#" in front or delete it completely.

Part I - Connect() and Slurp()
Ok, now that you hopefully found some computer, that provides you with some basic functions (including the Connect() and the Slurp() function) let's go straight into the code:

Every computer, that has Connect and Slurp can basically get you anywhere you want in the game.

For now, we want to connect to some other place and go there.

The function to connect to some other object is "Connect()" , obviously :).

But it needs the right argument. It needs the exact name (the exact string) of it. For example, we want to move back to our little room. Type in:

Connect("Hotel_Room1_Door1")

This will connect us with our door basically. The problem here is to get the names of all the objects. There is a device you'll find later on, that extracts the name of any object you use it on but for now you will just have to trust me on this :).

Ok, the program connected to your door. Next step is to get there.

So, we need the Slurp() function:

Type in:
Slurp()



If you now use the computer you will be slurped into the internet. Choose the target (in this case it should be Hotel_Room1_Door1, to which we connected before) and press "q" for exit when you get there.

Now you should be in your room again.

Note: Many non-computer-objects own a Connect() function but only a few types of them also have the Slurp() function.
Part II - Creating a Main Menu
Let's say you want to connect and travel (Slurp) to some other object somewhere else and you want to find out if the object you are traveling to has a certain function. For example you want to know if an object you are slurping to has also a Slurp function, to get you back into the internet.

Well, usually an object you can travel to directly also has this function but let's assume you don't know or simply want to check, if the object provides some other function you may miss on the one you are at the moment.

First we will write a start to write a small menue, so that the user has some option(s) to choose from. For now this will only include the search for a function of an object but we may want to expand this later on.

The Main Menu

First search for a computer with a bigger screen. A laptop or maybe the one at Wellspring Soda building should do.

Instead of just typing in some functions we now will start to write an own function, which will be the main entry point. So...maybe we call it main() or to make it more obvious in this case MainMenu():

void MainMenu() #some code is missing here end

void is the parameter, that tells the compiler, that this is a function. The brackets behind "MainMenue" are mandatory. Now we have this nice little function but at the moment it does...nothing :). Also, it won't yet be called by the computer, when you run it. So let's fix this and throw in some more code:

MainMenu() void MainMenu() ClearText() Print("Main Menu") Print("=========") Print("") Print("1. Check for function") Print("") Print("Please choose an option.") var mChoice = Input("") end

Now we first call our function MainMenu() at the start. When it's called the screen gets cleared via ClearText(). For now you should have an empty screen anyway but it will be important for later, when you jump back to the main entry point of your program.

The Print-command should be self-explaining. Below this we actually do two things:

var mChoice
declares a variable mChoice (the m just stands for main in this case) and

Input("")
initialises the variable. In this case the variable isn't directly initialised with a certain value but with another function Input(""), that awaits the users input on the screen, which is then saved within var mChoice.

You also could write:

var mChoise = Input("Please choose an option.")
It does the same but this case the users input would be followed directly after the line instead one line below.

Ok, so now the user typed in something. He doesn't have much choices either at the moment :). So either he types "1" or something else. Whatever he typed we store it into mChoice and now will have to do something with this:

MainMenu() void MainMenu() ClearText() Print("Main Menu") Print("=========") Print("") Print("1. Check for function") Print("") Print("Please choose an option.") #saves users input into mChoice var mChoice = Input("") if(mChoice == "1") Print("Excellent choice!") #do something else Print("I'm sorry but i didn't understand " + mChoice) Input("Please press the 'any key'.") MainMenu() end end

Ok, what do we have here?

if(mChoice == "1") Print("Excellent choice!") #do something

With the if command we check if the user typed in "1". If this turns out to be true the program goes on and just prints some text.

else Print("I'm sorry but i didn't understand " + mChoice) Input("Please press the 'any key'.") MainMenu() end

If the condition is untrue (false) the program will jump to this point and aks the user to press a key. After this we call our MainMenu() function again and the program will start again from the beginning.

Note, that in this case we have the Input() command again but this time it just waits for the users input.

Let's assume the user finally decides to choose option 1 (after a long time he carefully thought about his options :) ). He wants to check if some object has a certain function and thus can handle some specific task for him. Now we first need him to tell us the name of the object he wants to check. We could go on and directly ask the user for another input within the if/else - check but to have a better structure of our little program we will call another function from there:

if(mChoice == "1") Print("Excellent choice!") CheckObject()

Of course we will have to create this function too, to make it accessable:

void CheckObject() #some awsome code in here end

You can write this at any place within the program but for the sake of readability we will create this function below our MainMenu().


Part III - Calling (an)other function(s) and dealing with objects
This is what we have so far:

MainMenu() void MainMenu() ClearText() Print("Main Menu") Print("=========") Print("") Print("1. Check for function") Print("") Print("Please choose an option.") #saves users input into mChoice var mChoice = Input("") if(mChoice == "1") Print("Excellent choice!") CheckObject() else Print("I'm sorry but i didn't understand " + mChoice) Input("Please press the 'any key'.") MainMenu() end end void CheckObject() #some awsome code in here end

When CheckObject() is called we want the user to specify the name of it and which function he searchs for:

void CheckObject() #clear screen again ClearText() Print("Please type in the name of the object.") #save users input in var oName var oName = Input("") ClearText() Print("Which function you search for?") var oFunc = Input("") #connect to the object var cName = Connect(oName) #check if object has the function, the user searches for if(cName.HasFunction(oFunc)) Print("The object has the function " + oFunc) else Print("The object doesn't have a function called " + oFunc) end end

Much code this time but most things we know already, like Print() and ClearText() and how to get users input.

Let's have a look at those parts that are new:

var cName = Connect(oName)

We save a connection to an object to a variable?! Yes, kind of :). Actually this is legit and for now we don't need to know which kind of value is saved in "cName". What is important, though is to understand, that we now connected to an object (if the user typed in an existing object that is) and kind of saved this connection into a new variable.

And now you will (hopefully) see, why we did this:

if(cName.HasFunction(oFunc))

Three different things are happening here.

  • 1. A function "HasFunction()" will be called at the object itself. The HasFunction() was implemented with one of the last updates to every object. It returns true if it finds the function you searched for and false if it didn't. Instead of passing the users input itself you could of course use this function in a similar way like myObject.HasFunction("SomeFunction")

    The dot between the two expressions cName and HasFunction() actually tells the compiler, that you are using some Function of the object itself. This is important for understanding i think. You could also call some other function on it and if the object has the function implemented, it will execute.

    To make this more clear let me show you another example:

    var computer = Connect("FinanceComputer") var balance = computer.GetBalanceForPerson(GetNameOfCardOwner()) Print("Balance: " + balance)

    This is actually what happens, if you check your balance with your credit card :)...if you know the right functions you can adjust your credit amount with some similar code btw

    So, just like in our case, a connection is established to the object called "FinanceComputer". Next the computer is addressed to call a function called "GetBalanceForPerson()". If you are able to hack your own card yet you will notice, that this function isn't available at the card itself. So it only can be called on the finance computer object. And that's what this code does.

  • 2. Like said the HasFunction() is called on the object we adress. Also, the value/parameter for the function to search for is passed to this call --> HasFunction(oFunc) , which was the variable, that stored the users input for which function the program should look for.
  • 3. Finally, with

    if(...)

    the condition is checked, if the object, we connected to, has the function oFunc. Since HasFunction() returns true or false we can use the if/else check in this way.

Last but not least we also have some slightly different way to use the Print() function:

Print("The object has the function " + oFunc)

Basically it's the same Print() function as always but in this case we not just print out predefined (hardcoded) text but we also pass the variable "oFunc" to the text at the end of the line.

By now, the program asks the user for an object to connect to and after this it wants him to type in the function he's looking at. For example the user wants to know if the door ("Hotel_Corridor_Door1") in his hotel room has a Say() function. Just to greet the player or moan about him when he passes through maybe. Or he wants to know if the fuse box in his room can Connect() and Slurp() (btw, yes it can).

To end this part we want to add some code, so that the user has the ability to go back to the Main Menu again or to search for another object/function. So we add this after the whole if/else statement:

Print("") Print("Do you wish to search for another object?") var chObjChoice = Input("") if(chObjChoice == "y" || chObjChoice == "Y") CheckObject() else MainMenu() end

The only new thing here is the operand ||. It just adds an "Or" condition to the whole check. You also could read this like "if (chObjChoice == "y" OR "Y")
Part IV - Passing parameters to other functions
Let's have a look at the whole code again, that we made so far:

MainMenu() void MainMenu() ClearText() Print("Main Menu") Print("=========") Print("") Print("1. Check for function") Print("") Print("Please choose an option.") #saves users input into mChoice var mChoice = Input("") if(mChoice == "1") Print("Excellent choice!") CheckObject() else Print("I'm sorry but i didn't understand " + mChoice) Input("Please press the 'any key'.") MainMenu() end end void CheckObject() #clear screen again ClearText() Print("Please type in the name of the object.") #save users input in var oName var oName = Input("") ClearText() Print("Which function you search for?") var oFunc = Input("") #connect to the object var cName = Connect(oName) #check if object has the function, the user searches for if(cName.HasFunction(oFunc)) Print("The object has the function " + oFunc) else Print("The object doesn't have a function called " + oFunc) end #let user decide wether he wants to search for another #object/function or not Print("") Print("Do you wish to search for another object?") var chObjChoice = Input("") if(chObjChoice == "y" || chObjChoice == "Y") CheckObject() else MainMenu() end end

Btw, if you are getting tired just hack a coffee cup :7

Drink(1) Sleepiness(-1000)

Alright. Now that i have your attention again let's think about more options for our little program.

There is something, that would be pretty useful to do but we will have to skip this until a certain bug within the game is fixed. The developer(s) , who are pretty fast replying to any issue btw, are aware of this already and hopefully will deal with it soon...

...until this we have to think about other things we could do.


So, you came to Dorisburg to sell some Soda, right?! Well, actually no one wants to do this i guess ;) so wouldn't it be nice to sell some soda, without doing anything for it?

By the time i'm writing this i noticed that this code won't work atm. There seems to be a bug with the computer that registers your sales but i hope this will be fixed by the time you read this guide.

EDIT: Actually it should work if you started a new game. I'm not sure why this is the case and i also checked, if i maybe had some typos. But it was the same code.

What needs to be done? First we gonna add some new menu point:

void MainMenu() ClearText() Print("Main Menu") Print("=========") Print("") Print("1. Check for function") Print("2. Sell some Soda")

Second we need to adjust the choices:

if(mChoice == "1") Print("Excellent choice!") CheckObject() else if(mChoice == "2") SellSoda() else Print("I'm sorry but i didn't understand " + mChoice) Input("Please press the 'any key'.") MainMenu() end

So now, additionally to the condition check, if the user typed in "1" we now have an "else if" check for number "2". In that case the program calls the function SellSoda(), which (of course) we still have to write:

void SellSoda() ClearText() Print("Sell a Soda(tm)") Print("-------------------") Print("") Print("How many Soda's you want to sell?") number numberOfSodas = Input("") string name = GetUser() #todo some more code end

First 5 lines should be understandable by now. The following two lines are somewhat different, then what we did before so far:

number numberOfSodas = Input("") string name = GetUser()

A variable "numberOfSodas" is declared and it will save the users input. But this time we don't define the type of the variable as "var" but instead as "number". Why? you may ask. Well, first things first...at this point it won't make a difference if you declare it as "var" or as "number" but in general you should think about which type of variable you really need for certain aspects of your code.

Also. As we will see soon declaring this variable as "number" has an effect straight away, compared to a declaration as "var". If the user now inputs anything else then a number the program will crash. "Bad!" you might say. And partly you'd be right :).

There may be some workaround(s) but for now it's just important to know that this crash will happen too (if the user types in a none-numeric value and) if you declare the variable as "var" instead of "number". It will just happen at a later point as we will see.

Ok enough of that...whats the second one? Right. "string name = GetUser()". This will save the name of the user in a variable, that is declared as "string". In comparison to the number issue we had before, this declaration is pretty safe for now because there's no user input at all.

So, how do we change the sales now? Well. If you go to the Harbour and check the computers code you should get an idea at least :). We could do something similar, that we did before like:

var sodacomputer = Connect("HarborWest_SodaStorageComputer") sodacomputer.RegisterSeller("Sebastian", 100)

But this wouldn't work. Firstly, the SodaStorageComputer itself has no function RegisterSeller(). It execudes some code, that connects to some other computer instead. Secondly. Even if it would have a function like that to call, you also would have to spend the amount of money that equals the amount of sodas you selled :). But..we don't want to spend any money, right?

"Lol, just erase the part of code where that computer connects to the bank *trollface* " <-- Of course you could do this too :) ..it's just not helping in our guide for a better understanding at the moment



So let's have a look at the SodaStorageComputer again. If you register your selled Soda's there it connects 1. to the Wellspringer server to register your amount of selled Soda's and 2. it connects to the finance server to withdraw the amount of credits that equals this number. Since we are actually not at this computer but somewhere else writing our own program we just need to connect to the Wellspringer server, without the need to pay for it:

void SellSoda() ClearText() Print("Sell a Soda(tm)") Print("-------------------") Print("") Print("How many Soda's you want to sell?") number numberOfSodas = Input("") string name = GetUser() #connect to Wellspringer server var wellspring = Connect("Wellspringer") wellspring.RegisterSeller(name, numberOfSodas) Print("") Print("The amount of " + numberOfSodas + " Soda's has been registered.") Input("Please press a key.") MainMenu() end

Let's have a look at this:
wellspring.RegisterSeller(name, numberOfSodas)

The first part of this code should be familar by now. We connect to an object and save this into a variable. Secondly we call a function on this object called RegisterSeller(). What's new here is, that we also pass some parameters "name" and "numberOfSodas". We do need to do this because the function wants those and will not execute if they wouldn't be passed.

The function itself could look like this:

void RegisterSeller(string name, number amount) loop x from 0 to Count(arraySodaSellers) if(name == arraySodaSellers[x]) arraySoldAmount[x] = arraySoldAmount + amount end end

Maybe by now you guess why it would be rather better to have a crash on "our" side first (number vs. var) before it hits the Wellspringer server.







Part V - Remote Connections / Unlocking Doors I
Alright. Some bug was fixed recently so we can move on with our little program.

Unlocking Doors via Remote Connection(s)



In this part we want to have a look at some of the possibilities we have, when connecting to other objects. If you reat my previews parts you know, that we can just connect to some object and use his functions on his side. We also covered the way, how we can make sure, if an object has a certain function, that we want to use.

Especially if you want to deal with doors, this will come in handy.

So...let's do this :) :

First we will add a new menu option to our main-menu:

void MainMenu() ClearText() Print("Main Menu") Print("=========") Print("") Print("1. Check for function") Print("2. Sell some Soda") Print("3. Unlock a door")

Second we need to adjust the choices again:

if(mChoice == "1") Print("Excellent choice!") CheckObject() else if(mChoice == "2") SellSoda() else if(mChoice == "3") UnlockDoor() else Print("I'm sorry but i didn't understand " + mChoice) Input("Please press the 'any key'.") MainMenu() end

Of corse you also can use all the functions shown in this tutorial as standalone code. There's no need to have a menu at all for example (given, that you call it correctly and pass the right values if needed etc.) but i think for this tutorial it's a good way to do it like that.

Ok, so we added a 3rth option called "Unlock door" to the menu and adjusted the if/then condition so, that it will call the function UnlockDoor(), if it's the users choice. Of course we will have to write this function still:

void UnlockDoor() ClearText() Print("Unlock a door") Print("===========") Print("") Print("Please type in the name of the door:") #Door name #it should work as string too, since it is a string but to make sure we don't #get any nasty bugs when connecting later on, we will use var for now var dName = Input("") var cDoor = Connect(dName) ClearText() Print("Please type in the range of numbers, that") Print("you want to go through:") Print("") #Start number var nMin = Input("Min: ") #End number var nMax = Input("Max: ") Print("Trying to unlock " + dName + " now!") Print("Press 'Up' or 'Down' to stop the hacking.") Sleep(2) BreakDoor(cDoor, nMin, nMax) end

Quite a bit of code again but actually there's nothing, we don't know already. I will comment on some key elements either:

var dName = Input("") var cDoor = Connect(dName)

We catch the users input and store it in the var dName. Then we declare another var named cDoor (c for connection) and initialize it with the connection to the (game-)object, to which the doors name dName points to.

For example the user puts in "TownHall_DoorToLongsonOffice". Then the value of dName will be TownHall_DoorToLongsonOffice and the Connect() function will connect to the object, that is behind this identifier, namely the door to Longsons Office in the Town Hall.



This

BreakDoor(cDoor, nMin, nMax)

calls another function "BreakDoor()", that does the real job for us and tries to hack the door, according to the values the user typed in for the minimum and maximum numbers.

Note: Maybe it's important to clearify at this point, that we don't really "unlock" a door. We will rather try to hack it.

We will soon see, how BreakDoor() will look like but first let's have a quick look at the parameters, which are passed to it. It's the minimum and maximum number input "nMin" and "nMax" aswell as the variable cDoor . And that's quite interesting. We actually pass the connection to an object itself (in form of a stored value within a variable) to another function.

To be honest, i was curious too if this would work or not but it does :)

Ok, for now we have a range of numbers from nMin to nMax, the program will try to go through later on and we have to connection to a certain door. The last part is to write the actual code, that hacks the door (or tries to):

void BreakDoor(var cDoor, number nMin, number nMax) ClearText() number counter = 0 loop x from nMin to nMax Print("Trying code: " + x) if(cDoor.Unlock(x)) ClearText() Print("Door Unlocked!") Print("Code: " + x) break end end end

If you haven't work with loops yet, this is the time to do it :). But let's first take a look at how the parameters are passed to the function:

void BreakDoor(var cDoor, number nMin, number nMax)

First of all, you can name the paramaters, that the function needs as input in another way. Meaning it must not be the same, as the once you declared somewhere else in your program and then pass to it. Actually it's rather not recommended to name them in exact the same way but for now i think it'll make things easier to understand. But to be more specific on that you could name them also like:

void BreakDoor(var someDoor, number minimum, number maximum)

I won't go any deeper into this but for now let's just note, that the variables (the parameters the function needs as input) you declare here are actually new ones. If call this function from somewhere else within your program code, the usage BreakDoor(cDoor, nMin, nMax) will actually not really pass the variables cDoor, nMin and nMax but instead just their (stored) values.

What's also interesting is, that we previously declared nMin and nMax as "var" in our function UnlockDoor(). But the function BreakDoor() itself wants "number" instead. Still this works because (i'm guessing here) the type of value "var" will implicitly be converted to the type "number" in this case.

Let's move on to the loop:

loop x from nMin to nMax #do something end

Maybe you already saw this ingame or reat the disc, referring to loops. And, well, in principle it's really no big deal but you should be careful though because with loops you can pretty much ♥♥♥♥ up the program at run-time if you create an endless loop for example.

What it does is simply looping a segment of code "nMax" times, starting at "nMin".

The "segment of code" in our case is:

Print("Trying code: " + x) if(cDoor.Unlock(x)) ClearText() Print("Door Unlocked!") Print("Code: " + x) break end

It will call the function Unlock() at the door, we connected to using the actual value "x" as code-number, while "x" itself will be raised by one each time until the number "nMax" is reached.

In other words we just try any number from nMin to nMax to open the door.

Since Unlock() returns true or false we can use it directly within an if condition check:

if(cDoor.Unlock(x))

and if we are lucky and unlocked the door we stop the loop with:

break
Part V - Remote Connections / Unlocking Doors II
That's pretty much what you will need to brute force a door to unlock it. Let's quick get back at some point in our UnlockDoor() function we call, when the user chooses this from the main menu:

Print("Press 'Up' or 'Down' to stop the hacking.") Sleep(2)

You may have wondered what this is for :). Well, i'll get back to this in a second but let's first complete the UnlockDoor() function so that the user is able to hack another door or go back to the main menu after this:

After

BreakDoor(cDoor, nMin, nMax)

we put this code

Print("Search for another door (y/n)?") var uChoice = Input("") if(uChoice == "y") UnlockDoor() else MainMenu() end

So, if the user hacked a door, meaning if "BreakDoor()" was executed, the program will jump back to UnlockDoor() and executes the code above.

Hacking a door can be pretty boring because most doors in Else.Heartbreak() have a door code of at least 5 digits and it can take a while, till you looped to the right position.

The user should at least be able to abort the hacking process by pressing a certain key.

So let's expand our BreakDoor() function a bit for this purpose:

void BreakDoor(var cDoor, number nMin, number nMax) ClearText() number counter = 0 loop x from nMin to nMax if(IsKeyPressed("down") || IsKeyPressed("up"))
break
end
Print("Trying code: " + x) if(cDoor.Unlock(x)) ClearText() Print("Door Unlocked!") Print("Code: " + x) break end end end

With IsKeyPressed() we will watch the users input while the program runs the loop and if he presses the down or up arrow key the loop will stop (break).

As last part of this section i want to show a slightly different approach to hack a door. Instead of just running from let's say 0 to 99999 it would be cooler to have the numbers jump from the smallest to the highest number, then to the smallest number +1 again, followed by the highest number -1 and so on. This way you might get quicker results at some doors.

add

if(Mod(x,2)!=0) x = nMax - counter counter = counter +1 else x = counter end

before the line:
Print("Trying code: " + x)

We declared the counter outside of the loop and initialized it with the value 0. Now

Mod(x,2)

does nothing else then to divide the actual value of x by 2 and return the rest of this division. If the rest is "0" then it's an equal number, if not it's an unequal number. Wether x is equal or unequal it will be assigned by the value of the highest number (nMax) - the actual counter value or to the value of the counter itself. If the inital values for nMin and nMax would be 0 and 99999, this way we would jump from 0 to 99999, then back to 1, then to 99998, back to 2 and so on.



5 Comments
Arucard 7 Jun, 2017 @ 5:33pm 
Hello from the future! I still don't own this on Steam, so can't rate it up, but have favorited'd and want you to know how amazing this guide is. Using this has helped me understand a lot and prompted me to start earnestly learning programming. Great game, great guide, great googly moogly I am in your debt, sir.
Balthasar  [author] 25 Feb, 2016 @ 1:01pm 
I think you don't "need" to do anything like this. It's more like a sandbox outlined with some basic story. But the main goal here (at least as far as I know) is to get ppl to learn how to code and stuff. Tutorials like this just aim to give you some direction what is possible and where to start if you don't know what you want to do next.
Kakkamakkara 25 Feb, 2016 @ 11:04am 
So does one need to actually do shit like this in the game? I'm out.
Balthasar  [author] 29 Jan, 2016 @ 3:52pm 
Thx :). Nice game, man!
Erik 22 Jan, 2016 @ 1:47pm 
Wow, this is super impressive!