I disagree TDK,
Using one array called "Data" is vague and it's easy to forget what data is stored in which field. When storing different data types it becomes even more impractical.
If you use separate arrays it is much clearer what each one is storing and cross-referencing is just as easy.
print names$(i)
print positionx(i)
print positionz(i)
The two position arrays could be condensed into one but I don't see the need for it.
DIM name$(6)
DIM position(6,1)
Even this is ambiguous, you might well assume that the second position value would describe the Y axis not Z.
@Kenobi
First of all, Welcome to the forum
Your program isn't very user-friendly at the moment. The user prompts "Type in the name" don't tell the user what these names are for, and the second prompt doesn't mention that it will search the array for the name typed. Make sure you give clear instructions.
Your search array function isn't producing one name because you don't have a condition in there to restrict what is printed - since you have no conditions at all in your code I will explain.
A condition is a statement that is either TRUE or FALSE, the code that is attached to the condition will only be executed if the condition is TRUE. Try running the following code.
if 1=0 then print "1=0 is TRUE"
if 1=1 then print "1=1 is TRUE"
From the output you'd think the first line never happened.
If we want some output for the first line, even if it's false, we can add an ELSE statement to the condition - code following ELSE is only executed if the condition is FALSE.
if 1=0 then print "1=0 is TRUE" else print "1=0 is FALSE"
if 1=1 then print "1=1 is TRUE" else print "1=1 is FALSE"
Those lines are getting pretty long. Luckily, you can write IF statements on multiple lines, this is useful when you want to do lots of things on condition.
if 1=0
print "1=0 is TRUE"
else
print "1=0 is FALSE"
endif
if 1=1
print "1=1 is TRUE"
endif
Much easier to read. ENDIF calls the end of the statement, everything between IF and ENDIF will be executed on condition, there is no need for THEN. Notice how I've indented the lines in between? It's important to do that so you can see where the condition begins and ends. I recommend indenting any command that uses more than one line like this.
I got rid of the second ELSE because we don't need it.
Do we really need the ELSE on the first condition though? Yes it is FALSE but it will always be false, so it seems a bit silly to be wasting time writing code for something that's never going to happen. Can you work out how to write this condition without using ELSE?
That's enough on conditions, back to your code!
The first thing you did with your function is pass the search string to it - good job, we will certainly need that. At the moment however, the string isn't being used at all.
What we need to do is write a condition that will only print a name if it matches the search string.
You can compare strings in the same way as numbers (ie "a"="a" is TRUE). Can you work out the condition you should attach to the print command?
BONUS POINTS: With the right condition this program will work, but the string given will have to match the name exactly, even down to the case of each letter. If the search worked whether the letters were upper case or lower case it would be much easier to find the names you wanted. There are two commands that convert all the characters in a string to the same case: UPPER$() converts the string to upper case and LOWER$() converts to lower case. If you convert the name string and search string to the same case it wont matter which letters are capitalised.
Here's an example:
my$ = "hEllO kEnObI"
test$ = "Hello Kenobi"
If upper$(my$) = upper$(test$)
print "Doesn't matter if you are a weirdo who capitalises vowels, I understand cos I am smart. :D"
Endif
"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright