In the previous chapter we used numbers to check if the door we created was open or closed.
Why not a simple boolean I hear some folks asking? Simple: The only available data types in YOLOL are
numbers (integers and decimals) and strings (a list of characters).
So in reality using false and true means nothing other than trying to assign something to a field,
however not a boolean.
Step #1
To get to some coding, writevar="Hello!"into the first line and try running it!
As you will see, a local variable called var will be initialised with the value Hello!.
Now let's try and add another word to the string using string operations.
String operations will manipulate an existing string to add or remove parts to/ from it.
More about operators and their usage in the official documentation!
Step #2:
Writevar+="World!"into the second line and execute the snippet!
var="Hello!"
As you may have noticed, the resulting string has an excess questionmark in between the two words. Why?
The operator += appends or adds something to the specified variable. It does not replace or remove characters, thus the questionmark after Hello remains.
An easy fix would obviously be to change var to just Hello before doing anything with it, but that would be boring! Here we can introduce another operator: --
Step #3:
Writevar--in between the two lines and let the snippet run again!
var="Hello!"
var+="World!"
As you see, there's still a space missing in between the words. I'll leave that one for you to figure out though!
Step #4:
Try to get a space in between the two words!
var="Hello!"
var--
var+="World!"
| Previous Chapter | Next Chapter |
|---|