Posted: 19th Aug 2011 19:08
Hi,
when I DIM an array with a custom type in an #include(d) file then try and access it from the main source I get the following error:

Array 'jobs' subscripts must match corresponding DIM statement on line 32


The #include is a gosub to
+ Code Snippet
    type job
        walkrange
        maxhealth
    endtype

    dim jobs[10] as job
    jobs[1].walkrange = 3


And the main.agc line that spits the error is
+ Code Snippet
message(str(jobs[1].walkrange))


I don't know if this is a bug or my own failings.

Many thanks
Posted: 19th Aug 2011 20:13
Where in your main code is the #include line? It has to be above the point in the program where you make use of what it creates. Preferably at the top before anything else.
Posted: 19th Aug 2011 21:14
Yeah its right at the top just after resolution setting etc
+ Code Snippet
SetDisplayAspect( 4.0/3.0 )
SetVirtualResolution ( 640, 480 )

#include "func_blocks.agc"
#include "jobs.agc"

Then I load media then I gosub to the #include
Posted: 19th Aug 2011 21:23
So your included file would be like,

+ Code Snippet
VarSetup:
   type this_and_that
      a as integer
      b as integer
   endtype

  dim Those[10] as this_and_that
return



and in your main you have,

+ Code Snippet
#include "vars.agc"

Gosub VarSetup

Those[1].a = 1
Those[1].b = 2
print("There are those "+str(Those[1].a)+" and there are these "+str(Those[1].b)+".")



I would think that would work.
Posted: 19th Aug 2011 21:47
yeah thats basically it. At first I thought it was because I was accessing it from within a function (as arrays are global) but even outside the function a in your example still same error.
Posted: 20th Aug 2011 2:36
The immediate solution is to put the DIM in the main file.
Posted: 20th Aug 2011 2:40
Yeah thats what I've done. I'm also getting weird "array subscript errors" popping up being reported on lines the code isnt and when the the array is perfectly fine - i.e. used with no difference earlier or later in the code.

Are arrays currently buggy?
Posted: 20th Aug 2011 4:33
Inside includes perhaps. Otherwise, no, at least not that I've seen.