Qbasicnews.com

Full Version: exe problems!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
well im having problems with a space invaders clone im making. The .bas runs like a charm but once I compile it into a .exe i get a "subscript out or range". I know many people have posted these types of problems, and I am suspecting it has to do something with my arrays :???: But anyways here is the code Sad

o yeah there is some extra lines of code because im still working on the game :roll:

Code:
DECLARE SUB InitPaletteData (FileName$, PaletteArray&())
DECLARE SUB HARloadPut (FileName$, Array() AS INTEGER)
DECLARE SUB ChangePalette (PaletteArray&())
DEFINT A-Z
DIM MyArray(200) AS INTEGER
DIM MyArraym(200) AS INTEGER


SCREEN 13
'$DYNAMIC
  
'Load standard palette.
REDIM StandardPal&(1 TO 1)
CALL InitPaletteData("C:\GRADIENT.PAL", StandardPal&())
CALL ChangePalette(StandardPal&())



HARloadPut "c:\jelly.PUT", MyArray()

HARloadPut "c:\jellym.PUT", MyArraym()




player.x% = 142
player.y% = 180
PUT (player.x%, player.y%), MyArray, PSET
DO
WAIT &H3DA, 8

a$ = INKEY$


IF x = 100 THEN direction$ = "down"
IF y = 20 THEN direction$ = "right"
IF x = 0 AND y = 0 THEN direction$ = "left"
IF x = 0 AND y = 20 THEN direction$ = "up"

IF direction$ = "left" THEN x = x + 1
IF direction$ = "down" THEN y = y + 1
IF direction$ = "right" THEN x = x - 1
IF direction$ = "up" THEN y = y - 1



PUT (x, y), MyArray, PSET


PUT (x + 30, y), MyArray, PSET
PUT (x + 60, y), MyArray, PSET
PUT (x + 90, y), MyArray, PSET
PUT (x + 120, y), MyArray, PSET

PUT (x, y + 30), MyArray, PSET
PUT (x + 30, y + 30), MyArray, PSET
PUT (x + 60, y + 30), MyArray, PSET
PUT (x + 90, y + 30), MyArray, PSET
PUT (x + 120, y + 30), MyArray, PSET

PUT (x, y + 60), MyArray, PSET
PUT (x + 30, y + 60), MyArray, PSET
PUT (x + 60, y + 60), MyArray, PSET
PUT (x + 90, y + 60), MyArray, PSET
PUT (x + 120, y + 60), MyArray, PSET

pixelcolortop% = POINT(y, y)

IF player.x% = 0 THEN player.x% = 0 ELSE IF a$ = CHR$(0) + CHR$(75) THEN player.x% = player.x% - 1: PUT (player.x%, player.y%), MyArray, PSET

IF player.x% = 298 THEN player.x% = 298 ELSE IF a$ = CHR$(0) + CHR$(77) THEN player.x% = player.x% + 1: PUT (player.x%, player.y%), MyArray, PSET

FOR a% = 1 TO level%
LOCATE 23, 1: PRINT x, y
LOCATE 22, 1: PRINT playerx, playery
LOCATE 23, 6: PRINT pixelcolortop%
NEXT a%

LOOP

SUB ChangePalette (PaletteArray&())

    'Break down all 256 colours into their RGB values.
    DIM RGBval(0 TO 255, 0 TO 2)
    FOR n = 0 TO 255
    c& = PaletteArray&(n)
    b = c& \ 65536: c& = c& - b * 65536
    g = c& \ 256: c& = c& - g * 256
    r = c&
    RGBval(n, 0) = r
    RGBval(n, 1) = g
    RGBval(n, 2) = b
    NEXT n

    'Write colours directly to the video card.
    WAIT &H3DA, &H8, &H8: WAIT &H3DA, &H8
    FOR n = 0 TO 255
    OUT &H3C8, n            'Select attribute.
    OUT &H3C9, RGBval(n, 0) 'Write red.
    OUT &H3C9, RGBval(n, 1) 'Write green.
    OUT &H3C9, RGBval(n, 2) 'Write blue.
    NEXT n

END SUB

SUB HARloadPut (FileName$, Array() AS INTEGER)
l& = 0
FF = FREEFILE
OPEN FileName$ FOR BINARY AS #FF
l& = LOF(FF)
CLOSE #FF
Ints = (l& - 7) \ 2
'$DYNAMIC
REDIM Array(Ints) AS INTEGER
DEF SEG = VARSEG(Array(0))
BLOAD FileName$, 0
DEF SEG
END SUB

'* InitPaletteData() subroutine:
'* Initializes a long integer array with palette colour data - this must be
'* done before changing palettes with the PALETTE USING statement. The
'* calling value of FileName$ dictates whether the data should be read
'* directly from a palette file or from DATA statements (see below).
'*
'* Parameters:
'*       FileName$ - The name of the palette file to load. This must include
'*                   the path to the file if it does not reside in the
'*                   current directory. If FileName$ is an empty string (""),
'*                   palette data is read from DATA statements.
'* PaletteArray&() - Dynamic, long integer array to hold palette data.
'*
'* Note: Before calling InitPaletteData() to initialize a palette from DATA
'*       statements, use an appropriate RESTORE statement to ensure the
'*       correct DATA statements are read.
'*
SUB InitPaletteData (FileName$, PaletteArray&())

    'Size array to hold all 256 colours.
    REDIM PaletteArray&(0 TO 255)

    IF FileName$ <> "" THEN
    '*** Read palette data from file ***
    FileNo = FREEFILE
    OPEN FileName$ FOR BINARY AS #FileNo
    FOR n = 0 TO 255
        GET #FileNo, , colour&
        PaletteArray&(n) = colour&
    NEXT n
    CLOSE #FileNo
    ELSE
    '*** Read palette data from DATA statements ***
    FOR n = 0 TO 255
        READ colour&
        PaletteArray&(n) = colour&
    NEXT n
    END IF

END SUB
Change

REDIM StandardPal&(1 TO 1)
to
DIM StandardPal&(255)

and remove the line

REDIM PaletteArray&(0 TO 255)

in the InitPaletteData sub
One suggestion for you: don't use hard paths for your data, use relative paths. Where you have this:
Code:
HARloadPut "c:\jelly.PUT", MyArray()
Get rid of the C:\ because that makes it a hard path. The file should be in the same directory as your BAS file anyways, right? Or, you can make a directory and put the images in there. So if you have:
Quote:C:\mygame
You can do this kind of directory structure:
Quote:C:\mygame\images
and put your images into the "images" subdirectory. Then, your loader line will look like this:
Code:
HARloadPut "images\jelly.PUT", MyArray()
Much cleaner!
@Plasma - thanks for the help but now i have a duplicate definition error, I tryed to fix it in this line
Code:
REDIM Array(Ints) AS INTEGER

and changed it to

Code:
REDIM Arrays(Ints) AS INTEGER

but now when I try making a exe it gives another error

Code:
DOS memory-arena error
Memory allocation error
Cannot load COMMAND, system halted

@NecrosIhsan - thanks Big Grin i was going to do that after becuase right now im just trying to get it to work lol! As soon as it works im going to do a lot of retouching Smile


[/quote][/code]
This is causing you problems:
Code:
SUB InitPaletteData (FileName$, PaletteArray&())

    'Size array to hold all 256 colours.
    REDIM PaletteArray&(0 TO 255)
PaletteArray& does not need to be redefined in the Sub because you have already passed an array to the Sub as its second argument. In addition, you already know how large the palette array should be, so you can just DIM it to its proper size in the first place. Also, you don't need to REDIM the array at all...just do:
Code:
'Load standard palette.
DIM StandardPal&(0 TO 255)
and you should be fine.
thanks for the quick reply Smile but now im back to square one lol XD any other suggestions.
Quote:well im having problems with a space invaders clone im making. The .bas runs like a charm but once I compile it into a .exe i get a "subscript out or range". I know many people have posted these types of problems, and I am suspecting it has to do something with my arrays :???: But anyways here is the code Sad

o yeah there is some extra lines of code because im still working on the game :roll:

Code:
DECLARE SUB InitPaletteData (FileName$, PaletteArray&())
DECLARE SUB HARloadPut (FileName$, Array() AS INTEGER)
DECLARE SUB ChangePalette (PaletteArray&())
DEFINT A-Z
DIM MyArray(200) AS INTEGER
DIM MyArraym(200) AS INTEGER


SCREEN 13
'$DYNAMIC
  
'Load standard palette.
REDIM StandardPal&(1 TO 1)
CALL InitPaletteData("C:\GRADIENT.PAL", StandardPal&())
CALL ChangePalette(StandardPal&())



HARloadPut "c:\jelly.PUT", MyArray()

HARloadPut "c:\jellym.PUT", MyArraym()




player.x% = 142
player.y% = 180
PUT (player.x%, player.y%), MyArray, PSET
DO
WAIT &H3DA, 8

a$ = INKEY$


problomIF x = 100 THEN direction$ = "down"
IF y = 20 THEN direction$ = "right"
IF x = 0 AND y = 0 THEN direction$ = "left"
IF x = 0 AND y = 20 THEN direction$ = "up"problem

IF direction$ = "left" THEN x = x + 1
IF direction$ = "down" THEN y = y + 1
IF direction$ = "right" THEN x = x - 1
IF direction$ = "up" THEN y = y - 1



PUT (x, y), MyArray, PSET


PUT (x + 30, y), MyArray, PSET
PUT (x + 60, y), MyArray, PSET
PUT (x + 90, y), MyArray, PSET
PUT (x + 120, y), MyArray, PSET

PUT (x, y + 30), MyArray, PSET
PUT (x + 30, y + 30), MyArray, PSET
PUT (x + 60, y + 30), MyArray, PSET
PUT (x + 90, y + 30), MyArray, PSET
PUT (x + 120, y + 30), MyArray, PSET

PUT (x, y + 60), MyArray, PSET
PUT (x + 30, y + 60), MyArray, PSET
PUT (x + 60, y + 60), MyArray, PSET
PUT (x + 90, y + 60), MyArray, PSET
PUT (x + 120, y + 60), MyArray, PSET

pixelcolortop% = POINT(y, y)

IF player.x% = 0 THEN player.x% = 0 ELSE IF a$ = CHR$(0) + CHR$(75) THEN player.x% = player.x% - 1: PUT (player.x%, player.y%), MyArray, PSET

IF player.x% = 298 THEN player.x% = 298 ELSE IF a$ = CHR$(0) + CHR$(77) THEN player.x% = player.x% + 1: PUT (player.x%, player.y%), MyArray, PSET

FOR a% = 1 TO level%
LOCATE 23, 1: PRINT x, y
LOCATE 22, 1: PRINT playerx, playery
LOCATE 23, 6: PRINT pixelcolortop%
NEXT a%

LOOP

SUB ChangePalette (PaletteArray&())

    'Break down all 256 colours into their RGB values.
    DIM RGBval(0 TO 255, 0 TO 2)
    FOR n = 0 TO 255
    c& = PaletteArray&(n)
    b = c& \ 65536: c& = c& - b * 65536
    g = c& \ 256: c& = c& - g * 256
    r = c&
    RGBval(n, 0) = r
    RGBval(n, 1) = g
    RGBval(n, 2) = b
    NEXT n

    'Write colours directly to the video card.
    WAIT &H3DA, &H8, &H8: WAIT &H3DA, &H8
    FOR n = 0 TO 255
    OUT &H3C8, n            'Select attribute.
    OUT &H3C9, RGBval(n, 0) 'Write red.
    OUT &H3C9, RGBval(n, 1) 'Write green.
    OUT &H3C9, RGBval(n, 2) 'Write blue.
    NEXT n

END SUB

SUB HARloadPut (FileName$, Array() AS INTEGER)
l& = 0
FF = FREEFILE
OPEN FileName$ FOR BINARY AS #FF
l& = LOF(FF)
CLOSE #FF
Ints = (l& - 7) \ 2
'$DYNAMIC
REDIM Array(Ints) AS INTEGER
DEF SEG = VARSEG(Array(0))
BLOAD FileName$, 0
DEF SEG
END SUB

'* InitPaletteData() subroutine:
'* Initializes a long integer array with palette colour data - this must be
'* done before changing palettes with the PALETTE USING statement. The
'* calling value of FileName$ dictates whether the data should be read
'* directly from a palette file or from DATA statements (see below).
'*
'* Parameters:
'*       FileName$ - The name of the palette file to load. This must include
'*                   the path to the file if it does not reside in the
'*                   current directory. If FileName$ is an empty string (""),
'*                   palette data is read from DATA statements.
'* PaletteArray&() - Dynamic, long integer array to hold palette data.
'*
'* Note: Before calling InitPaletteData() to initialize a palette from DATA
'*       statements, use an appropriate RESTORE statement to ensure the
'*       correct DATA statements are read.
'*
SUB InitPaletteData (FileName$, PaletteArray&())

    'Size array to hold all 256 colours.
    REDIM PaletteArray&(0 TO 255)

    IF FileName$ <> "" THEN
    '*** Read palette data from file ***
    FileNo = FREEFILE
    OPEN FileName$ FOR BINARY AS #FileNo
    FOR n = 0 TO 255
        GET #FileNo, , colour&
        PaletteArray&(n) = colour&
    NEXT n
    CLOSE #FileNo
    ELSE
    '*** Read palette data from DATA statements ***
    FOR n = 0 TO 255
        READ colour&
        PaletteArray&(n) = colour&
    NEXT n
    END IF

END SUB
there is a problom