Arrays again

Blitz3D Forums/Blitz3D Beginners Area/Arrays again

seferey(Posted 2006) [#1]
Hi I was giving it another try at arrays

Anyway here's My code

Graphics3D 640,480,32,2

SetBuffer BackBuffer()


Dim boxposition$(4,2)
box1position$(1) = "box1"
box2position$(1) = "box2"
box3position$(1) = "box3"
box4position$(1) = "box4"


Cam1=CreateCamera()

light1=CreateLight()

RotateEntity light1,0,0,90


While Not KeyHit(1)

UpdateWorld
RenderWorld 

Flip 

Wend 
End 


I meant to say

I'm trying to load model files up as I give them a position in X and Y


octothorpe(Posted 2006) [#2]
I can't make sense out of what you want to do, so instead I'll give you an example of how 2d string arrays actually work.




puki(Posted 2006) [#3]
I think "seferey" is just wanting to know how to store the positions - I think - purely because he multi-dimensioned the array. So, assuming that is right - you can do it as a 2 dimensional numeric array - or do it as a string array and have 3 dimensions (1 for the name like you did above):

Load your model, then set the positions
Dim boxposition(4,2)
boxposition(1,1)=whatever the x value is
boxposition(1,2)=whatever the y value is

boxposition(2,1)=whatever the x value is
boxposition(2,2)=whatever the y value is

etc

EDIT:
Taking into account arrays start at 0


octothorpe(Posted 2006) [#4]
I hope not!

Type arrays would serve that purpose much better:

type thing
field x#, y#
end type

dim things.thing(4-1)
things(0) = new thing
things(0)\x = whatever the x value is
things(0)\y = whatever the y value is
things(1) = new thing
things(1)\x = whatever the x value is
things(1)\y = whatever the y value is
...


Bonus points for a constructor function

function new_thing.thing(x# = 0, y# = 0) : t.thing = new thing : t\x = x : t\y = y : return t : end function

things(2) = new_thing(123.45,67.89)
things(3) = new_thing(234.56,78.901)


The downside of this approach is that you need to remember to Delete array elements when you're done with them.

If you can't be bothered, just initialize all the elements of your array to new blank objects:

dim sloppy_things.thing(4-1)
for i = 0 to 4-1 : sloppy_things(i) = new thing : next

sloppy_things(0)\x = whatever the x value is
sloppy_things(0)\y = whatever the y value is
sloppy_things(1)\x = whatever the x value is
sloppy_things(1)\y = whatever the y value is



puki: EDIT: Taking into account arrays start at 0

Are you sure you did that? You still seem to be using [1] as the first index.


seferey(Posted 2006) [#5]
I was rewriting it again this way

Dim Boxes(100, 2)

Box1(0,0) = 200 ;the X value
Box1(0,1) = 50 ;the Y value



I'm trying it in different ways to position my entities in x and y values am I wrong in this as well and where it says

Box1(0,0) = 200 ;the X value


this line above says expecting ")"

right where it says (0,0)

it wants this (0,0) to be this (0)

Box1(0) = 200 ;the X value



octothorpe(Posted 2006) [#6]
The name of your array is Boxes, not Box1.

Boxes(0, 0) = 200


seferey(Posted 2006) [#7]
Here's a quick question for ya

can you use a type command to position a 3d models if so how?

I also understand some of the the type setup plus it can be used to go to a function I written right.

just curios that's all


octothorpe(Posted 2006) [#8]
Please start new threads for new topics.