09-25-2003, 09:43 AM
Okay I made a little test program that can create an array inside a SUB, get the segment address (assuming the offset is 0) and the mess with that array ANYWHERE else in the entire program.
I personally thought this was the most kickass thing in the world (because it's so new to me and) because I don't even need an array's fricken name in order to use it!!!! This is particularly handy when you need an array that you can resize the dimensions of (REDIM for use with maps that vary in size) and when that array is inside a TYPE (because you can't do that with static arrays unfortunately).
Unfortunately, it is a mystery to me why my attempt to impliment this into my heavily-UGL utilizing program failed.
SEGMENTS.BAS
As I look over this code after I had posted this message, I realize that I may have actually sort of "cheated" with this. I noticed that I didn't make the array a global one, so I'm starting to think that when it changes the array from inside that sub, it's actually leaving behind that old code, and simply allocating extra space. If this is the case, the code may be terribly inefficient, and I'll have to look it over again. Sorry in advance for any possible inconvience!
P.S. boy golley do i sound weird when i tries t' sound profeshunal
I personally thought this was the most kickass thing in the world (because it's so new to me and) because I don't even need an array's fricken name in order to use it!!!! This is particularly handy when you need an array that you can resize the dimensions of (REDIM for use with maps that vary in size) and when that array is inside a TYPE (because you can't do that with static arrays unfortunately).
Unfortunately, it is a mystery to me why my attempt to impliment this into my heavily-UGL utilizing program failed.
SEGMENTS.BAS
Code:
DECLARE FUNCTION GetInfo% (map AS ANY, x%, y%)
DECLARE SUB ShowMatrix (map AS ANY)
DECLARE SUB SetInfo (map AS ANY, x%, y%, value%)
DECLARE SUB ChangeArray (map AS ANY)
TYPE t
mapseg AS INTEGER
maxx AS INTEGER
maxy AS INTEGER
END TYPE
DIM map AS t
REDIM array(0 TO 10, 0 TO 10) AS INTEGER
map.mapseg = VARSEG(array(0, 0))
map.maxx = 10
map.maxy = 10
SetInfo map, 13, 0, 4
ShowMatrix map
SLEEP
ChangeArray map
SetInfo map, 3, 2, 7
ShowMatrix map
SUB ChangeArray (map AS t)
REDIM array(0 TO 3, 0 TO 3) AS INTEGER
map.mapseg = VARSEG(array(0, 0))
map.maxx = 3
map.maxy = 3
END SUB
FUNCTION GetInfo% (map AS t, x%, y%)
DEF SEG = map.mapseg
GetInfo% = PEEK((y% * (map.maxx + 1)) + x%)
DEF SEG
END FUNCTION
SUB SetInfo (map AS t, x%, y%, value%)
DEF SEG = map.mapseg
POKE (y% * (map.maxx + 1)) + x%, value%
DEF SEG
END SUB
SUB ShowMatrix (map AS t)
DIM x%, y%
CLS
FOR y% = 0 TO map.maxy
FOR x% = 0 TO map.maxx
PRINT GetInfo%(map, x%, y%);
NEXT x%
PRINT CHR$(13) + CHR$(13)
NEXT y%
END SUB
As I look over this code after I had posted this message, I realize that I may have actually sort of "cheated" with this. I noticed that I didn't make the array a global one, so I'm starting to think that when it changes the array from inside that sub, it's actually leaving behind that old code, and simply allocating extra space. If this is the case, the code may be terribly inefficient, and I'll have to look it over again. Sorry in advance for any possible inconvience!
P.S. boy golley do i sound weird when i tries t' sound profeshunal
earn.