Poll: Yes or no?
You do not have permission to vote in this poll.
yes
100.00%
2 100.00%
no
0%
0 0%
Total 2 vote(s) 100%
* You voted for this item. [Show Results]

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2d array
#1
i want to have the data for a map in a 2d array. the only problem is i dont want to do each thing one at a time.
to explain better, this is what i want to do in qb. but this in actionscript. the only thing i know besides qb.

map = [[1,1,1],[1,1,1],[1,1,1]]

so i was wondering if there was a way of doing this in qb quickly and easily.
Reply
#2
You can't specify the contents of an array upon creation in QB. Is this what you meant? I had a bit of trouble understanding what you meant by "I don't want to do each thing one at a time". Do you mean that you don't want to set each value in the array with some other code (e.g. loading the values from a map file) -- you'd prefer to initialise it with the declaration of the array? If so, it's not possible.

-shiftLynx
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Reply
#3
i didnt understand your answer/question, so ill just re-ask it in a better and completely different way. 8)

if i want a map thats 3x3. and the array is called map. and i wanted each number in the array to do make a different tile on the screen. is there another way to do it besides this-

dim map(3,3) as w/e
map(1,1)=2
map(1,2)=1
map(1,3)=1
map(2,1)=2
... and so on
and then a loop to actually go through and draw maps according to the array.

sorry for the misconception. if there even was one.
Reply
#4
No, there isn't an easier way.

But you can write a routine to load the values from a file, or READ them from DATA statements, which would save you some hassle.

-shiftLynx
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Reply
#5
yes. use data statments like this:


Code:
DIM 2darray(3,3)

FOR y = 0 to 3
  FOR x = 0 to 3
    READ 2darray(x,y)
  NEXT
NEXT

DATA 1,1,1,1
DATA 1,2,3,1
DATA 1,3,2,1
DATA 1,1,1,1
Reply
#6
ok. thanks dark prevail. but one more question. if i wanted to use 2 of those datas how would i make sure that qb didnt confuse the two? or how does it know the difference in the first place?
Reply
#7
Two options that spring to mind are:

1. Use DATA statements, but keep your arrays in order:

Code:
'dimension both arrays
DIM AllOnes%(1 TO 4, 1 TO 4)
DIM AllTwos%(1 TO 4, 1 TO 4)

'fill array 1 with data
FOR y% = 1 TO 4
FOR x% = 1 TO 4
    READ AllOnes%(x%, y%)
NEXT x%, y%

'fill array 2 with data
FOR y% = 1 TO 4
FOR x% = 1 TO 4
    READ AllTwos%(x%, y%)
NEXT x%, y%

'end the program
SYSTEM

'data for array 1
DATA 1, 1, 1, 1
DATA 1, 1, 1, 1
DATA 1, 1, 1, 1
DATA 1, 1, 1, 1

'data for array 2
DATA 2, 2, 2, 2
DATA 2, 2, 2, 2
DATA 2, 2, 2, 2
DATA 2, 2, 2, 2

2. Read the data for your arrays from files. Then you could have a separate file for each array, to avoid confusion.

*peace*

Meg.
Reply
#8
Using files is preferrable anyways, especially if you're using QB. That removes some precious dataspace from your executable, firstly, and secondly, it makes it easier to make modifications without recompilation. Big Grin
I'd knock on wood, but my desk is particle board.
Reply
#9
Quote:ok. thanks dark prevail. but one more question. if i wanted to use 2 of those datas how would i make sure that qb didnt confuse the two? or how does it know the difference in the first place?
DATA statements can be placed anywhere in the main part of the program (which is why people normally tuck them away at the end). QB always starts READing from the first value in the first DATA statement it comes across.

Code:
DIM 2darray(3,3)

FOR y = 0 to 3
  FOR x = 0 to 3
    READ 2darray(x,y)
  NEXT
NEXT

DATA 1,2,3,4
DATA 5,6,7,8
DATA 9,10,11,12
DATA 13,14,15,16
QB would READ this as 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16.

You could have just one DATA statement with all the info like this:
Code:
DATA 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16

if you remmed-out 2 of the DATA statements like this:
Code:
DATA 1,2,3,4
'DATA 5,6,7,8
'DATA 9,10,11,12
DATA 13,14,15,16
QB would READ this as 1,2,3,4,13,14,15,16.

HTH.
url=http://www.spreadfirefox.com/?q=affiliates&id=60131&t=79][Image: safer.gif][/url]
END OF LINE.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)