I suppose that you know how to use text editor, and suppose you know how to write there piece of program and then make it run.
Lesson 1: Flow basics.
Every program is executed, line by line. And from top to bottom.
Hence:
Code: Select all
1. debugprint("My name is")
2. debugpring("Hollywood")
3. debugprint("im a programming language")
My name is
Hollywood
im a programming language
as it is executed line 1 first, then second and last the third line.
I will be at start using this Debugpring() command, since that way we dont need to open screens or anything.
1.1 - Variables and Debugprint() command.
variables are plaves where you can store information.
you are free to name your variables into anything you like, as long as they dont happen to be named same as some Hollywood command is.
we could for example have variable "my_name"
we would make this my_name variable, but putting some info inside it:
Code: Select all
my_name = "hollywood"
You could think these variables as envelopes, where you put notes inside. When you need that info, you open the envelope where it reads on top "my_name" and you can read note inside it that reads "hollywood". This is good when you reach certain state of dementia that you can store all kinds of important ingo like your name inside these envelopes.
By default, Debugprint command prints out everything that you write inside " and ", they will be displayed exactly as you wrote them.
However, we have anotehr option, we dont necessary have to put everything inside " and ", but we can also put stuff outside of it, which Hollywood will treat bit differently.
Lets take example:
Code: Select all
1. my_name = "hollywood"
2. debugprint("My name is")
3. debugpringt(my_name)
4. debugprint("im a programming language")
My name is
Hollywood
im a programming language
But how it happened this time is biot different.
Notice in line 3, I am not using " and " at all inside those ( and ). But instead, I am simply writing there "my_name". However, as you can see, isntead of reading
My name is
my_name
im a programming language
It actually reads Hollywood in that "my_name" place.
This is because when i wrote that my_name, Hollywood instead oepened up the envelope that read "my_name" on top of it, and wrote whatever was reading inside that note inside that envelope. Which in this case was "Hollywood".
Now, to show you about how the program flow works, I am showing one example again:
Code: Select all
1. debugprint("My name is")
2. debugpringt(my_name)
3. debugprint("im a programming language")
4. my_name = "hollywood"
My name is
0
im a programming language
Reason for this is, that since program flow is from top to bottom, you havent put any note inside that envelope until line 4, since line 2 is alreaduy telling to open the envelope, it will result in Hollywood displaying 0 instead of what you meant, since if there is no value assigned to one of the envelopes, then Hollywood just treats it as 0.
There is also another way to use Debugprint command, you can combine variables and stuff between " and ".
For example:
Code: Select all
1. my_name = "programmer"
2. debugprint("My name is")
3. debugpringt("hollywood and "..my_name)
4. debugprint("im a programming language")
My name is
hollywood and programmer
im a programming language
And this can be extended to even more complex systems like:
Code: Select all
1. my_firstname = "Andreas"
2. my_lastname = "Falkenhahn"
3. my_approval = "Wife"
2. debugprint("My name is")
3. debugpringt("hollywood")
4. debugprint("and i was made by"...my_firstname.." "..my_lastname".." with approval from "..my_approval)
Last line would now print out:
and i was made by Andreas Falkenhahn with approval from wife
Just notice that the idea is that everytime you want to combine variable and stuff between " and ", you need to use two dots ".." to separate them from each other.
1.3 more about variables.
Variables can have other stuff too inside them, than just text. Another typical usage for variables is having numbers inside them.
For example we could have:
my_weight = 200
Since we now have a number inside that variable, we can use it for mathematical operations.
For example:
Code: Select all
my_weight=200
your_weight=300
our_totalweight=my_weight + your_weight
debugprint(our_totalweight.." kg")
500 kg
you can aslo use mathematical calculations when assigning variables, even mixing variables and mathematical operations
example:
Code: Select all
mysalary=1000
mymoneyatendofmonth = mysalary - 100 - 50 - 30 - 400 - 400 - 200
salaryincreasepercentage=10
mynewsalary=mysalary * (1 + ( salaryincreasepercentage/100 ) )
debugprint("my salary is:"..mysalary.." Eur what is left of it each month is:"..mymoneyatendofmonth.." Eur Thats why i needed a rase, and got "..salaryincreasepercentage.." percent increase to my new salary, and hence my new salary is: "..mynewsalary.." Eur.")
my salary is: 1000 Eur what is left of it each month is: -180 Eur Thats why i needed a rase, and got 10 percent increase to my new salary, and hence my new salary is: 1100 Eur.
One of the most common usafe for variables is following:
my_variable=5
my_variable=my_variable+1
which means that now the my_variable contains number 6 inside it.
Another common usage is to make:
my_variable=1-my_variable
This means, that my_variable will always be either 1 or 0.
Very useful when you need to go between two different states continuosly in your program.
Next time I will go a bit about how to jump around in progam. since naturally, if only thing you can do is go from top to bottom, but never be able to jump back to top or middle or somewhere, there isnt much use from program.