Qbasicnews.com
August 18, 2018, 01:30:13 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Hey, a legitimate question!  (Read 9028 times)
Dio
I hold this place together
*****
Posts: 874



« on: March 03, 2007, 12:43:05 AM »

It's about time...

anyways,

I see stuff like

Code:
Dim a(100,100)


and i think to myself, "What it that comma doing in there?"

I don't know how to use that and it look useful. does anyone know of a tutorial or somthing? i plan on making a minesweeper clone and this sounds like somthing i should learn.

i have only known the subscript to have one number.
Logged

quote="whitetiger0990"]whitetiger is.. WHITE POWER!!! [/quote]
Here
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #1 on: March 03, 2007, 12:59:08 AM »

That's a two-dimensional array.  You can even have more than two dimensions if you want.  Everything works just like a normal array, except when you reference an element, you have to give two (or more, if you are using more dimensions) indexes:
Code:
dim arr(100, 100)

arr(x, y) = 12
Logged
Skyler
Ancient Guru
****
Posts: 564



« Reply #2 on: March 03, 2007, 10:05:33 AM »

Being math, you're not limited to three or even four dimensions- you can have ten or twenty-six, if you want.
Logged

In the beginning, there is darkness the emptiness of a matrix waiting for the light. Then a single photon flares into existence. Then another. Soon, thousands more. Optronic pathways connect, subroutines emerge from the chaos, and a holographic consciousness is born." -The Doctor
phycowelder
Forum Regular
**
Posts: 136



WWW
« Reply #3 on: March 03, 2007, 12:03:34 PM »

i use them all the time!
for X,Y locations! and graphic memory arrays!
i even use more detailed ones like type arrays.

eg.

Code:

dim shared exitbut(0 to 1,4*(48*16)+4) as byte

a snippit for my two exit buttons from my MAPGEN.bas
0 and 1 is my button waiting and button pressed!
4*(48*16)+4 is the memory slot i needed for each pictures
Eg. PUT (100,100), exitbut(0,0), PSET
-pastes exit button one on the screen


Code:

dim shared xandys(0 to 25,0 to 1) as short

this snippet from the same MAPGEN.bas
i have 0-25 buttons and other graphics going on the screen
and 0-1 is the X location and Y location!
eg. PUT (xandys(10,0),xandys(10,1)), exitbut(0,0), PSET
-pastes exit button one on the screen
-10 is the X and Y value i wanted the exit button


Code:

dim shared paltool(0 to 849,0 to 1,4*(16*16)+4) as byte

this was for my Brush for the tile painter,
0-849 = how many tiles it can hold in memory
0-1 = visable tile and mask tile
4*(16*16)+4= memmory to hold a 16x16 tile


I hope this helps a little!
if not i tryed or chalk me up to a retard, and i should keep my nose out of it!!
Logged

t is better to error on the side of caution
than the side of haste!!!
Dio
I hold this place together
*****
Posts: 874



« Reply #4 on: March 03, 2007, 10:27:20 PM »

ok, so i'm trying this experiment:

Code:
screenres 800,600,32,2,1
dim water(800,600)
dim list(480000)
for i = 0 to 2399
  do
    x = int(rnd*800):y = int(rnd*600)
  loop until water(x,y) = 0
  list(i) = water(x,y)
  water(x,y) = 1
  pset(x,y),255
next
sleep

do
  i = int(rnd*2399)
if water(x,y+1) = 0 then
  water(x,y+1) = 1
  water(x,y) = 0
  pset(x,y-1),0
  pset(x,y),255
  list(i) = water(x,y)
end if
loop


before, i had it just pick a random x and y and if that happened to be a blue pixel, it would move it down. but that was really slow.
so i made List(480000) and used the first 2400.
line eight seems to be te problem.
Logged

quote="whitetiger0990"]whitetiger is.. WHITE POWER!!! [/quote]
Here
phycowelder
Forum Regular
**
Posts: 136



WWW
« Reply #5 on: March 03, 2007, 11:34:15 PM »

Code:

do
  i = int(rnd*2399)
if water(x,y+1) = 0 then
  water(x,y+1) = 1
  water(x,y) = 0
  pset(x,y-1),0
  pset(x,y),255
  list(i) = water(x,y)
end if
loop


how do you check your WATER(X,Y) values!
X and Y are always the same never changing!
so nothing in the loop will change except line 21
which will always make your random list(i)=water(x,y) which i believe is always 0
Logged

t is better to error on the side of caution
than the side of haste!!!
Skyler
Ancient Guru
****
Posts: 564



« Reply #6 on: March 03, 2007, 11:41:25 PM »

Line 8 sets list(i) to 0. Every single time. Notice:
Code:

  do
    x = int(rnd*800):y = int(rnd*600)
  loop until water(x,y) = 0
  list(i) = water(x,y)

I doubt that's what you want.

Also, I don't think FB likes the size of the arrays you are dimming. I haven't had much luck with anything above 256x256.
Logged

In the beginning, there is darkness the emptiness of a matrix waiting for the light. Then a single photon flares into existence. Then another. Soon, thousands more. Optronic pathways connect, subroutines emerge from the chaos, and a holographic consciousness is born." -The Doctor
phycowelder
Forum Regular
**
Posts: 136



WWW
« Reply #7 on: March 04, 2007, 12:04:36 AM »

i dont know about that! this allocates a full 800x600 screen in to memory of 16x16 pixels!
and it is only one of about 40 arrays in my one program!
it runs fast and smooth!
Code:
dim shared paltool(0 to 849,0 to 1,4*(16*16)+4) as byte
Logged

t is better to error on the side of caution
than the side of haste!!!
Skyler
Ancient Guru
****
Posts: 564



« Reply #8 on: March 04, 2007, 09:17:48 AM »

Hmm,  maybe it's just me, but my programs tend to exit on startup if I try to use a large array.

By the way, phycowelder, is your period key broken?
Logged

In the beginning, there is darkness the emptiness of a matrix waiting for the light. Then a single photon flares into existence. Then another. Soon, thousands more. Optronic pathways connect, subroutines emerge from the chaos, and a holographic consciousness is born." -The Doctor
phycowelder
Forum Regular
**
Posts: 136



WWW
« Reply #9 on: March 04, 2007, 12:05:58 PM »

lol sorry no! i just use "!" alot always have doent know y.
i guess it how people realy know it its me
! ! ! ! ! ! ! ! ! !
Logged

t is better to error on the side of caution
than the side of haste!!!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!