Qbasicnews.com

Full Version: AI
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
my first attempt at AI, im getting a subscript outta range error on put (AIx*10-10,AIy*10-10),AI . whats wrong
Code:
SCREEN 13
DIM guy(10, 10)
DIM AI(10, 10)

guyy = 4
guyx = 4
AIy = 2
AIx = 2

FOR y = 1 TO 10
FOR x = 1 TO 10
READ z
PSET (x, y), z
NEXT x
NEXT y
GET (0, 0)-(10, 10), guy

FOR y = 1 TO 10
FOR x = 1 TO 10
READ z
PSET (x, y), z
NEXT x
NEXT y
GET (0, 0)-(10, 10), AI

CLS
PUT (AIx * 10 - 10, AIy * 10 - 10), AI
PUT (guyx * 10 - 10, guyy * 10 - 10), guy

DO
a$ = INKEY$

IF AIy > guyy THEN AIy = AIy + 1
IF AIy < guyy THEN AIy = AIy - 1
IF AIx < guyx THEN AIx = AIx - 1
IF AIx > guyx THEN AIx = AIx + 1
IF AIx = guyx OR AIy = guyy THEN PRINT " you lost"

IF oldAIx <> AIx OR oldAIy <> AIy THEN
oldAIx = AIx
oldAIy = AIy
CLS
PUT (AIx * 10 - 10, AIy * 10 - 10), AI
END IF

IF a$ = "w" THEN guyy = guyy - 1
IF a$ = "s" THEN guyy = guyy + 1
IF a$ = "d" THEN guyx = guyx + 1
IF a$ = "a" THEN guyx = guyx - 1
IF oldguyx <> guyx OR oldguyy <> guyy THEN
oldguyy = guyy
oldguyx = guyx
CLS
PUT (guyx * 10 - 10, guyy * 10 - 10), guy
END IF
LOOP UNTIL a$ = "q"

DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4

DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
Intersting design....

Make sure your Put is in range of the screen. ie. the x can be no less than 0 and no more than 319 - length of put inmage. The y can't be less than 0, and no more than 199 - height of pic.

That should be it.
sorry its saying ilegal function call, and x and y are in the range of the screen now but it still wont work, anything else
Ummm...ya do:

DIM guy(11, 11) AS INTEGER
DIM AI(11, 11) AS INTEGER

Try that now Big Grin
should i change the :
for y = 1 to 10 to:
for y = 0 to 10 or:
for y = 1 to 11

**EDIT
k thats not it i dunno why iut wont work my array size is 11,11 but im only getting 10,10 cause i want a ten by ten size sprite
No those are fine, just try what I said.

You see when you GET (0, 0) - (10, 10) you are accually getting image data = to that of (11,11).

Observe:
01,02,03,04,05,06,07,08,09,10,11 <--1-11
00,01,02,03,04,05,06,07,08,09,10 <--0-10

They are the same. You're trying to do:
01,02,03,04,05,06,07,08,09,10
00,01,02,03,04,05,06,07,08,09,10

Not the same are they?

Just try it! Big Grin
Wait no, wait!

I forgot the arrays start at 0!!, opps :oops: , just try it though.
sorry just a wee bit confused not about the 0 to 10 is the same as 1 to 11 bit but...i dunno anyway here is my code as of now

Code:
DIM guy(11, 11) AS INTEGER
DIM AI(11, 11) AS INTEGER

SCREEN 13

guyy = 4
guyx = 4
AIy = 2
AIx = 2

FOR y = 1 TO 10
FOR x = 1 TO 10
READ z
PSET (x, y), z
NEXT x
NEXT y
GET (0, 0)-(10, 10), guy

FOR y = 1 TO 10
FOR x = 1 TO 10
READ z
PSET (x, y), z
NEXT x
NEXT y
GET (0, 0)-(10, 10), AI

CLS
PUT (AIx * 11 - 11, AIy * 11 - 11), AI
PUT (guyx * 11 - 11, guyy * 11 - 11), guy

DO
a$ = INKEY$

IF AIy > guyy THEN AIy = AIy + 1
IF AIy < guyy THEN AIy = AIy - 1
IF AIx < guyx THEN AIx = AIx - 1
IF AIx > guyx THEN AIx = AIx + 1
IF AIx = guyx OR AIy = guyy THEN PRINT " you lost"

IF oldAIx <> AIx OR oldAIy <> AIy THEN
oldAIx = AIx
oldAIy = AIy
CLS
PUT (AIx * 11 - 11, AIy * 11 - 11), AI
END IF

IF a$ = "w" THEN guyy = guyy - 1
IF a$ = "s" THEN guyy = guyy + 1
IF a$ = "d" THEN guyx = guyx + 1
IF a$ = "a" THEN guyx = guyx - 1
IF oldguyx <> guyx OR oldguyy <> guyy THEN
oldguyy = guyy
oldguyx = guyx
CLS
PUT (guyx * 10 - 10, guyy * 10 - 10), guy
END IF
LOOP UNTIL a$ = "q"

DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4
DATA 4,4,4,4,4,4,4,4,4,4

DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
:o

Have you two broke the code, it is PUTing the sprites, WAY! out of range...

If you REM out the PUT, which, BTW, is giving a "Illegal Function" call, then under it put:

LOCATE 1, 1: PRINT AIx * 10 - 10; AIy * 10 - 10

You'll find the output is:

-3000 -3000

WAY! off screen.... I can't make out whats causing this, but something is deffently wrong with your cords...... :wink:
Ya I saw that, but when I had the original one, I made the first coordinates "good" coordinates, and it still blew up...so I left that at there...go figure :roll:
Pages: 1 2 3