Quote: "What is the difference in using
array insert at bottom
and
array insert at top
does it make a big difference with how things work?"
Yes, it's a big difference. ARRAY INSERT AT TOP will move all elements down one and insert a blank element at the top of the array (zero).
Quote: "How would i check to see if a certain object in IN the array also, like if i had picked up a key is there a way to chack that it is IN the array in order to use it with a door for example?"
A simple FOR/NEXT loop would do the trick. Not quite like you had it though... it doesn't have to be that complicated. When you use a FOR/NEXT loop you use a variable that increases on every loop. FOR t=1 to 100 means that t=1 the first loop, t=2 the second loop and so on till it's 100 and the FOR/NEXT loop automatically exits.
` Make random number picking more random
randomize timer()
` Define the User Defined Type (UDT)
type InvStuff
ItemName as String
ItemImage as Integer
endtype
` Dimensionalize the array with 2 (to show blank entries 0 to 2)
dim Items(5) as InvStuff
` Make one item
HexKey$="Hex-Key"
CreateObject(HexKey$,1000)
` Show the array size
print "Array Size = "+str$(array count(Items(0)))
print ""
` Show the contents of the array
for t=0 to array count(Items(0))
print "Items("+str$(t)+").ItemName = "+Items(t).ItemName
print "Items("+str$(t)+").ItemImage = "+str$(Items(t).ItemImage)
print ""
next t
for t=0 to array count(Items(0))
` Check the array for the key
if Items(t).ItemName="Hex-Key"
print "The key is in inventory slot #"+str$(t)
` Leave the FOR/NEXT loop since the key has been found
exit
endif
next t
wait key
` Always put an end before the first function so you don't get an error
end
function CreateObject(ItemName$,ItemImage)
` Make a = a random number between 0 and 5
a=rnd(5)
` Add the item to the array (using the random number)
Items(a).ItemName = ItemName$
Items(a).ItemImage = ItemImage
endfunction
Quote: "Also would an array be used to like display the images along the bottom of the screen or would that be done in a different way?"
Yes you can since you added the image number to the array. You just use the array to PASTE the images on the screen. This creates 9 images (numbers 1 to 9) and PASTEs them to the screen by each item in the array. The x and y coordinates determine where that graphic is going to be on the screen. x is horizontal and y is vertical.
` Make random number picking more random
randomize timer()
` Define the User Defined Type (UDT)
type InvStuff
ItemName as String
ItemImage as Integer
endtype
` Dimensionalize the array with 2 (to show blank entries 0 to 2)
dim Items(7) as InvStuff
` Make small images
for t=1 to 9
` Pick a random background color
ink rgb(rnd(255),rnd(255),rnd(255)),0
` Make a box
box 0,0,20,20
` Change color to white
ink rgb(255,255,255),0
` Show the number
center text 10,0,str$(t)
` Grab the image
get image t,0,0,20,20,1
next t
` Make 5 items
for t=1 to 5
HexKey$="Hex-Key"
` Create the item with a random image number
CreateObject(HexKey$,rnd(8+1))
next t
` Show the array size
print "Array Size = "+str$(array count(Items(0)))
print ""
` Make x=300 and clear the screen
x=300:cls
` Show the contents of the array
for t=0 to array count(Items(0))
print "Items("+str$(t)+").ItemName = "+Items(t).ItemName
print "Items("+str$(t)+").ItemImage = "+str$(Items(t).ItemImage)
print ""
` Show the item image on the screen if it's more than zero
if Items(t).ItemImage>0 then paste image Items(t).ItemImage,x,y,1
` Add 45 to y
inc y,45
next t
wait key
` Always put an end before the first function so you don't get an error
end
function CreateObject(ItemName$,ItemImage)
` Make a = a random number between 0 and 5
a=rnd(5)
` Add the item to the array (using the random number)
Items(a).ItemName = ItemName$
Items(a).ItemImage = ItemImage
endfunction
For inventory it's really better to avoid adding and deleting elements in the array. If you dimensionalize the array at 19 and if your character can only hold 20 items at a time there's no need to delete any element because weather or not they are holding 20 items does not negate the fact that the max is 20 and you have an array to fit the max already. Notice on the code snip above. When there wasn't an item to show (zero) it didn't place an image on the screen.