Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Lonnie
21
Years of Service
User Offline
Joined: 28th May 2003
Location:
Posted: 11th Sep 2003 05:50
Ok people, I now want to attempt to make an array. How? Can you please give me an example please? And explain alittle about arrays? Thanks! You will see me on here more!

What I want to do is save data for a charecter in a RPG (Ok I know its a crazy attempt to try to make a very simple RPG with arrays, for such a newb, but Ill try lol)
Thanks!

Do Print "Hello World"
Wait 2003 loop
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 11th Sep 2003 06:53
think of an array as an egg carton with more than just 2 dimensions if required.

count from zero to the intended number to get the amount of spaces

dim myarray(10) is really 11 integer spaces

for i = 0 to 10
myarray(i) = i
next i

this populates the array with the same numbered value as its numerical sequence.

to save an array regardless of dimensions you can use the save and load array. Use a zero in the save and load commands where there would have been the dimensions.


save array "myarraydata.foo",myarray(0)
same with load
load array "myarraydata.foo",myarray(0)


this is a real basic start to these commands.

http://www.lunarpixel.com
It's already tomorrow in Australia
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 11th Sep 2003 14:28
about arrays (old hands please note I am ignoring the zero element for simplicity)

dim numbers(9)

makes a list of 9 numbers, so you could do

numbers(1)=10
numbers(2)=20
numbers(3)=30
......
numbers(9)=90

you can use them just like normal numbers

numbers(9)+numbers(1)=100

but you need to provide that number in the brackets so that you know what number in the set "numbers" you are talking about, so the variable numbers can hold 9 values

numbers
(1)(2)(3)(4)(5)(6)(7)(8)(9)

the real use of arrays is that you can get the computer to change the number in the brackets so that it can get to them on it`s own, for example the following code will load 10xi into each of 9 numbers

dim numbers(9)
for i=1 to 9
numbers(i)=i*10
next i

or this code will read a chunk of data into the numbers

dim numbers(9)
for i=1 to 9
read value
numbers(i)=value
next i
data 1265,234,9087,3434,314,415,456,765,384

you can use them to hold the status of an army of 2000 attacking machines

for i=1 to 2000
if robot_power(i)=0 then gosub explode_the_sucker
next i

lets you check the status of 2000 robots in a few lines, and to hurt robot 123 that you have in your sites?

robot_power(123)=robot_power(123)-20

just like you would a normal variable, just remeber you need to supply the correct values, you could modify the above code to keep track of 2000 spheres and delete them when their power reaches zero or whatever else your code requires, then you can also use them to indicate what happens on (for example) a matrix, since they can use two numbers for the index like this

dim grid(4,4)

gives a set of numbers lke this

grid
(1)(2)(3)(4)
(5)(6)(7)(8)
(9)(10......etc
(13......16)

so grid(2,2) refers to the number at the position in the array 2 across 2 down (6) or grid(1,4)=13, you could use a bigger grid to store the positions of mines hidden under a matrix and explode one when the player is that the correct tile position, you check that position in the matrix and if the player is on a mine then BOOM!
you can make them 3D too

dim cubeworld(10,10,10)

4D

dim hyperworld(10,10,10,10)

7D

dim headexploder(10,10,10,10,10,10,10)

or as many dimensions as you like, you can also make arrays from strings, types and floats...eg

dim word$(200)
dim decimal#(50)
dim types(20)

heres an example that remembers 10 individual lines and then lets you recall a specific line

dim messages$(10)
for i=1 to 10
input a$
messages$(i)=a$
cls
next i

do
repeat
print "what number message do you wish to recall?"
input index
until (index>0 and index<10)
print messages$(index)
print "press space to continue"
wait 200
repeat
until spacekey()
cls
loop

you can use arrays to record movements or store the scripts for actions, the position of objects in 3D (or 23D) space and loads of other useful stuff, they also remove the load when you want a lot of repetitive numbers handling that are all the same type, heres a pack of cards

dim cards(52)
for i=1 to 52
cards(i)=i
next i

but they are all in order, lets shuffle them up 300 times by swapping any two randomly chosen cards around

for i=1 to 300
first_card=rnd(51)+1
second_card=rnd(51)+1
hold_first_card=cards(first_card):` this saves the 1st card value
card(first_card)=card(second_card):` this puts the 2nd card in 1st cards slot
card(second_card)=hold_first_card:` and this puts the 1st cards value in the 2nd cards slot
next i

that swaps two different randomly chosen cards around 300 times, that shuffles the pack thoroughly, to see the result and verify that the shuffle occured with no duplication of cards just do

for i=1 to 52
print cards(i)
next i

hope that explains arrays better, they are fast since they are held in memory and they simplify your code, you realy need arrays to do anything cool, unless you plan to write code like

robot1=23
robot2=45
robot3=32
.
.
.
.
robot1000=3

instead of

dim robot(1000)
for i=1 to 1000
read robot_type
robot(i)=robot_type
next i
data 23,45,32........
......
data .....,3

cheers.

Mentor.
zzabb
21
Years of Service
User Offline
Joined: 25th Apr 2003
Location: Seattle, USA
Posted: 16th Sep 2003 10:53
great post mentor

My advice is free -
unfortunately you get what you pay for (-:
Lonnie
21
Years of Service
User Offline
Joined: 28th May 2003
Location:
Posted: 15th Oct 2003 00:11
Thanks A lot Mentor! (Sorry about the huge delay in responding) I have read that several times! Thanks It Helps Alot!

Later

Do Print "Hello World"
Wait 2003 loop

Login to post a reply

Server time is: 2024-11-25 13:51:12
Your offset time is: 2024-11-25 13:51:12