GLBasic forum

Main forum => GLBasic - en => Topic started by: griller on 2007-Jan-01

Title: DIM arrays - how do I declare multiple global arrays???
Post by: griller on 2007-Jan-01
I've run into a problem with my "Agony of the Damned" trial game.

I only seem to be able to declare one global array using DIM. I need more than one array for my game!

Code:
DIM map_array [16][16][3]
DIM keylocation_array [1][1]
DIM unit_array [1][1]

Error:
C:\DOCUME~1\AL\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\DOCUME~1\AL\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:20: error: `keylocation_array' undeclared (first use this function)
C:\DOCUME~1\AL\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:20: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\DOCUME~1\AL\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:21: error: `unit_array' undeclared (first use this function)
Title: DIM arrays - how do I declare multiple global arrays???
Post by: Synthetic on 2007-Jan-02
If you haven't already, try updating to the latest version. I just ran it on 4.051 with no errors.
Title: DIM arrays - how do I declare multiple global arrays???
Post by: Kitty Hello on 2007-Jan-02
after the name of the "map_array" try to remove the spaces before the "[" symbol. Please tell me if it fixed the problem.
Title: DIM arrays - how do I declare multiple global arrays???
Post by: griller on 2007-Jan-04
Thank you for your advice Synthetic and GernotFrisch.

New code:
DIM map_array[16][16][3]
DIM keylocation_array[2][2]
DIM unit_array[2][2]

This did not work either :(

I am still playing with GLBasic 4.009 Demo version to see if it is capable of creating the game I wish to write. Is there a set of limitations within the demo? I have ordered GLBasic SDK premium with the Xmas discount offer so hopefully it will work with that compiler when I get it....
Title: DIM arrays - how do I declare multiple global arrays???
Post by: Kitty Hello on 2007-Jan-04
From the menu: Web/Internet Update, you can get a new version. This, however, seems totally strange. Please upload the .gbas file you try to compile with zshare and post a link. You example compiles fine here, so it must be something else.
Title: DIM arrays - how do I declare multiple global arrays???
Post by: griller on 2007-Jan-04
Success!!!

The update made it work perfectly - thank you Gernot. :)

I am happy to upload my program but what is "zshare"? Are you talking about "Submit a New Game"? I ran a search of your forum and of GLBasic and got no usefull results for "zshare" :(
Title: DIM arrays - how do I declare multiple global arrays???
Post by: Kitty Hello on 2007-Jan-04
Great to see it working! ZShare? Take a look at the very top of the forum pages.
If you want your game in the showroom, that's the way to go.
Send me a mail for the access-password for uploading.
Title: DIM arrays - how do I declare multiple global arrays???
Post by: griller on 2007-Jan-04
OK - I've posted my code at:

http://www.zshare.net/download/agony-of-the-damned-gbap.html

I hope to make a very cool (and bizzare) 2D turn based strategy game using your compiler.

I didn't notice the zshare link at the top of the page!!!
Title: DIM arrays - how do I declare multiple global arrays???
Post by: Kitty Hello on 2007-Jan-04
The gpap is the "Project" file. The "gbas" is the source file. You uploaded the project ;)
Title: DIM arrays - how do I declare multiple global arrays???
Post by: griller on 2007-Jan-04
Hmmm - I need to sleep more and program less....

Try this:

http://www.zshare.net/download/agony-of-the-damned-gbas.html
Title: DIM arrays - how do I declare multiple global arrays???
Post by: Kitty Hello on 2007-Jan-04
Looks nice. Beware: GETFILE/PUTFILE is only valid for line numbers 0..255 (you use 450)
Better use INIPUT/INIOPEN for new projects now.
Title: DIM arrays - how do I declare multiple global arrays???
Post by: griller on 2007-Jan-05
OK Gernot, I have re-written my save/load subs to use INIPUT to save my arrays. Its a but slow but does the job with just one file.

Code:

SUB savemap:
 KILLFILE "Maps/map.ini"
 INIOPEN "Maps/map.ini"
 FOR x=0 TO 63
  counter = 0
  FOR y=0 TO 63
   FOR z=0 TO 2
    INIPUT x, counter, map_array    counter = counter + 1
   NEXT
  NEXT
 NEXT
 INIOPEN ""
ENDSUB

SUB loadmap:
 INIOPEN "Maps/map.ini"
 FOR x=0 TO 63
  counter = 0
  FOR y=0 TO 63
   FOR z=0 TO 2
    map_array    counter = counter + 1
   NEXT
  NEXT
 NEXT
 INIOPEN ""
ENDSUB
Title: DIM arrays - how do I declare multiple global arrays???
Post by: Kitty Hello on 2007-Jan-05
you seem to be a good programmer. You might have better results when you write all values for "y" in one string, seperating with a ',' and get them out later with SPLITSTR.
...just an idea.
Title: DIM arrays - how do I declare multiple global arrays???
Post by: griller on 2007-Jan-06
OK - I will have a play...

What a fantastic resource this forum is - this support is invaluable.
Title: DIM arrays - how do I declare multiple global arrays???
Post by: Hemlos on 2007-Jan-24
Hi, just passing through the forums..

 if youre reading and/or writing the data from an entire ARRAY[]  with more than 1 dimension, it will slow the cpu/ram exponentially....

ie
dim arrayname[100][100]=10000 data slots
dim arrayname[100][100][100]=1000000 data slots
dim arrayname[100][100][100][100]=100000000 data slots

and naturally:
ie dim arrayname[1000][1000][1000][1000]=1000000000000 data slots!

if you are experiencing a lack of performance, think about how much data youre actually using per frame when you build your array.

also you can optimize mapp_array
Title: DIM arrays - how do I declare multiple global arrays???
Post by: Kitty Hello on 2007-Jan-25
Yes. And for x,y,z it's OK. For speed and stuff I'd go with TYPES then, since it makes code more readable and the compiler is quite good now with types and errors.