# Programming in LOLGraphics 3.4/Variables & Input
## LOLGraphics Memory

In LOLGraphics, the interpreter gives you access to 4 segments which can be used to store data. Each segment has 65536 cells. In the one byte segment, each cell is a signed 1 byte integer. In the two byte segment, each cell is signed 2 byte integer. In the four byte segment each cell is a signed 4 byte integer, and in the 8 byte segment each cell is a signed 8 byte integer.
The cells in each segment are numbered 0-65535. At the beginning of the program each cell is set to a random number. You can print the value of each cell using PLZ PRINT ONE/TWO/FOUR/EIGHT BYTE 100. That command will print the value in the cell with index 100 (the 101st cell!) and not the number 100 (!). If you want to print 100 regardless of the value of a variable, simply type PLZ PRINT TEXT 100. can also change the value of each cell. Running PLZ SET ONE BYTE 100 27 will set the value on index 100 in the one-byte segment to 27.

## Declaring a variable

Writing cell addresses will make your code hard to read if you use many values. That’s why you have the ability to label those cells. If you type the line I HAS A FOUR BYTE DAT IZ CALLED X, you label the first unlabeled cell in the four byte segment “X”. You can also run PLZ SET FOUR BYTE X 27, and PLZ PRINT FOUR BYTE X.
The following code will print the same number twice but each time a different one.

## Variable names

Readers familiar with programming languages will definitely recall that practically all languages have rules regarding to which characters can be used in the name of a variable (usually just letters, numbers, and underscores with the first character being a letter always). The esoteric programming language TMMLPTEALPAITAFNFAL (The Multi-Million Language Project To End All Language Projects And Isn't That A Fine Name For A Language) has really weird rules that rotate every day so one day it can require the symbol [ to appear at least 15 days or something like that.
LOLGraphics doesn’t have any restrictions regarding the variable name. You can name a variable by a number but this probably isn’t a very smart decision since it will always go the cell with that index and not that variable.
Also you can give different variables the same name. If they are in different segments then there isn’t any reason the code won’t work as you have to specify the size of the variable anyways. However, if they are in the same segment the code will still work but when the variable name is specified, it will always operate using the first instance of it.

## Where to declare variables

Many programming languages like java and rust have scopes and variables declared in a scope can’t be used outside of it. LOLGraphics doesn’t have such stuff so if you declare a variable it’s forever. The only important thing is that the command which declares the variable was run before the commands that use it are run. In order to avoid having multiple variables with the same name, it’s recommended to declare the variables either at the very beginning of the code or if you think it makes the code messy, in a subprogram that is called only at the beginning of the code.
Also, it’s important to remember that despite the fact that this books says “and address or a variable” that a variable in LOLGraphics is just a label that points towards an address.

## Random numbers

To generate a random number, all you need to do is type the command PLZ GIMME A RANDOM ONE/TWO/FOUR/EIGHT BYTE <address/variable>. There is also the command PLZ CLEAR ALL TEH SEGMENTS. Despite what the name suggests, it doesn’t set all the cells in all the segments to 0, and neither does it set them to their initial values. Instead it sets all the values in all the segments to random numbers.

## Input

There are 2 ways to ask the user for input. The first one, which is preferable for cli apps is using the command PLZ ASK TEH USR 2 GIMME A ONE/TWO/FOUR/EIGHT BYTE <address/variable> this command will stop the program, activate the input button, wait for the user to type a number, then after he presses the button, it will save the value typed by the user in the specified address or variable.
The second way which is preferable in some situations is using the command PLZ READ ONE/TWO/FOUR/EIGHT BYTE <address/variable>. It doesn’t wait for the user to press on the input button, and doesn’t even activate it, instead it just takes whatever is there, and puts in the specified variable or address. If the input field is empty, the command will do nothing. This is the method used in the “8462 demo” which is like a WASD demo only using the numpad. You will also learn how to write such a program later in the book.

## Halting the program

The above section is useful if you want to wait for the user to type a number and then press on the input button. But what if you want to just halt the program and wait for the user to press on the input button? Luckily there is a command just for that! It’s PLZ WAIT 4 DA USR 2 REACT. It will be annoying for production applications if you plan on writing any in LOLGraphics, however it will be useful for debugging purposes.