Wow, this is embarrasing... So heres my theory on what DATA, READ, and RESTORE works, [especially annoying FOR TO but Ill get to it later] Is this 100% accurate or am I missing something??
If you learn assembly, especially MIPS assembly, which is so low level that you can convert it into 1s and 0s by hand, the user of data, read, and restore is very heavily used. The reason it exists in BASIC is because of how easy it is to convert it back into assembly so it can run.
DATA is just user defined data, a faster way to fill up an array with manual numbers/strings rather than generated
Then what did I did wrong? Is there limitations to using READ DATA? I kind of feel iffy on RESTORE because it works on either side as long as they're closest? Or only on top. But on the other one, 12Me23 told me about this but I still see no progress. Does usage of READ ALWAYS need to be in DIM/VAR or DEF? Do I always need WHILE [idk how it work] or FOR TO first 1 line before READ?
Where READ is alt of DIM\DEF? Like this?
READ Bob$
RESTORE @WalkieTalkie
DEF A$[2]
A$[0] = "Hello!"
A$[1] = "How are you?"
A$[2]= "I'm good! Thanks!"
@WalkieTalkie
DATA 1
DATA 2
DATA 3
Not really
RESTORE always always comes before READ, READ simply puts whatever value is next into whatever variable you want. If the variable wasnt created with VAR/DIM, it will create it automatically
In this example, we put 100 digits of pi into an array
Then because its in an array we can easily get any value of it
DIGITS[0] is the first number
DIGITS[79] is the 80th number
DIGITS[99] is the 100th number
DIGITS[100] will give you an error because there arent 101 numbers
^ And actually in that example
The FOR loop makes:
I=0
I=1
I=2
I=3
...
I=97
I=98
I=99
And for each value of I, it runs whatever is inside the loop, in this case it runs
READ DIGITS[0]
all the way to
READ DIGITS[99]
X is just a useless variable
But inside the FOR loop it is the counter to know when to stop looping
X=0, X=1, X=2, X=3, X=4
That NEXT X is the exact same as NEXT. Adding the X just makes it 'easier to read' but I think that's bs
You used X as the FOR loop incrementer, but by convention, i is always used first, then j, then k, and so on
The array R (or hotel room, or whatever) can only store one number each
However, if you replaced R with R$
That means it is an array of strings
Then in the DATA you could do
DATA "Bob's room", "Bill's room", "Harry's room", "empty", "another empty room"
READ/DATA is used to add data in with your code. If you were using a different language you might just read from file instead. However BASIC was made back in the days of puch cards and tape drives so file access was not always possible.
When you first start a program, READ will find the first DATA statement and return the first value it finds then move to the next bit of data.
If you want to control where is reads from you use RESTORE. If you don't pass a parameter it starts from the beginning. You can also pass a label to make it start at a certain spot in the code.
You will need to be careful that you pass the correct variable to read, you don't want to try to put a string in a number variable.
See how I used RESTORE to read the favorite numbers before the fruits even though the fruit was first in the code. RESTORE is the only reason we should use line numbers in smile basic.
You declare data with the DATA statement after the statement is is just a comma separated list of numbers or strings which you can mix and match.
READ just gets the next available data value
SmileBASIC runs faster without a variable after NEXT
And % after a variable means that that variable is specifically an array
You use it if you want to make a function that takes an array as it's parameter
You should try making a game!
...classy background that Petit II people did long time with cute backgrounds, but I been struggling on how to make one text not move but make selected text move.
Explain more on %? I feel a little better on DATA and READ atm though.
% means an integer variable. That is a whole number like 1, 0, or -1. While # means a floating point number that can have a value after the decimal point like -1.1, 3.14159, or 1.00001. Finally $ is for strings like say "Hello".
Integers have a much smaller range, and can't have fractional values but are generally faster which on a low power computer may be useful.
Regardless of a speed boost I like to include it. It documents your intent when using a variable so when you or someone else comes back to it after a break you have a better idea of what to do with it. For loop counters you almost always want %, for SIN and COS you want #. If you don't specify you may end up with a floating point number when you wanted an integer too. It pays to be precise.