forums

TNT Basic Forums > Programming Q&A
How do you declare a 3-D array.
< Last Thread     Next Thread >
Author
Thread        Post A Reply

10-29-2006 05:54

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

I'll do a snippet of my code here.

However, when I run the game, and when an action uses this code, \
I get:

*** Runtime exception caught ***
Line# : 362
Code : string factorytypename[factorysettings]
Error : Invalid array dimension.


Global int factorysettings=1
Global string factorytypename[factorysettings]
Global string factoryshiparray[factorysettings,unittypenumber]
Global string factorytecharray[factorysettings,technologytypes]

int oldsize=factorysettings
int i
int g
string Bfactorytypename[factorysettings]
string Bfactoryshiparray[factorysettings,unittypenumber]
string Bfactorytecharray[factorysettings,technologytypes]

for i=0 to factorysettings-1
Bfactorytypename=factorytypename

for g=0 to unittypenumber-1
Bfactoryshiparray[i,g]=factoryshiparray[i,g]
next

for g=0 to technologytypes-1
Bfactorytecharray[i,g]=factorytecharray[i,g]
next

next i
factorysettings=factorysettings+1

string factorytypename[factorysettings]
string factoryshiparray[factorysettings,unittypenumber-1]
string factorytecharray[factorysettings,technologytypes-1]

for i=0 to oldsize-1
factorytypename(i)=Bfactorytypename(i)
for g=0 to unittypenumber-1
factoryshiparray[i,g]=Bfactoryshiparray[i,g]
next g
for g=0 to technologytypes-1
factorytecharray[i,g]=Bfactorytecharray[i,g]
next g
next i
''''factories

if left str(TextOfLine,string length("factorytypename=")) = "factorytypename="
factorytypename[factorysettings-1] = (right str (TextOfLine,(String Length(TextOfLine)-string length("factorytypename="))))
BreakProc=1
end if

if left str(TextOfLine,string length("factoryshiparray=")) = "factoryshiparray="
value=""
i=0
continue=0
numberofcommas=0
for g=0 to string length(right str (TextOfLine,(String Length(TextOfLine)-string length("factoryshiparray="))))
if get char((right str (TextOfLine,(String Length(TextOfLine)-string length("factoryshiparray=")))),g)=","
numberofcommas=numberofcommas+1
continue=0
else
continue=1
end if
if get char((right str (TextOfLine,(String Length(TextOfLine)-string length("factoryshiparray=")))),g)=";"
numberofcommas=numberofcommas+1 '(numberofvalues)
factoryshiparray[factorysettings-1,i]=value
i=i+1
break
end if
if continue=1
value=value+get char((right str (TextOfLine,(String Length(TextOfLine)-string length("factoryshiparray=")))),g)
end if
next g
end if

if left str(TextOfLine,string length("factorytecharray=")) = "factorytecharray="
value=""
i=0
continue=0
numberofcommas=0
for g=0 to string length(right str (TextOfLine,(String Length(TextOfLine)-string length("factorytecharray="))))
if get char((right str (TextOfLine,(String Length(TextOfLine)-string length("factorytecharray=")))),g)=","
numberofcommas=numberofcommas+1
continue=0
else
continue=1
end if
if get char((right str (TextOfLine,(String Length(TextOfLine)-string length("factorytecharray=")))),g)=";"
numberofcommas=numberofcommas+1 '(numberofvalues)
factorytecharray[factorysettings-1,i]=value
i=i+1
break
end if
if continue=1
value=value+get char((right str (TextOfLine,(String Length(TextOfLine)-string length("factorytecharray=")))),g)
end if
next g
BreakProc=1
end if


for as=0 to factorysettings-2

print factorytypename[as]
for i=0 to unittypenumber-1
print factoryshiparray[as,i]
next
for i=0 to technologytypes-1
string factorytecharray[as,i]
next
print "___"
next as

10-29-2006 13:51

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

i can't really help you because this snippet cannot run on its run - too many missing variables

but i'd like to point these out:

Bfactorytypename=factorytypename

the 2 are arrays, and you didn't put [] next to them

factorytypename(i)=Bfactorytypename(i)

hmmm why do you use () instead of [] ???

10-29-2006 13:52

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

> hmmm why do you use () instead of [] ???

Oh, probably so that the board doesn't think it's italics!

10-29-2006 19:38

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

It probably has a (i) there... but I didn't see it.

But, ignore the snippet, do you declare a 3-d array by:

int threedarray[5,6]

like that?

10-29-2006 21:03

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Yes.

10-30-2006 09:52

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

I have given this a bit more thinking... This might actually be a bug. I commented the next line (from where TNT points to).

Then TNT skipped this error and went to the next one.

I.E the TNT debugger is 1 line behind of itself.

when the error is on line #363, it says the error is on #362, even If I commented out #362.

This phenomenon started only after I put in 3D arrays.

What I am afraid of is not being able to re define global 3d arrays in procedures.

I think the only way to give you working code is to give you my whole project.

10-30-2006 09:54

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

I did some more tweaking and discovered that they seem to be only can be redefined if I redefine them as single dimension arrays... :(

10-30-2006 10:06

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

Here is my project.
I recommend you to use my app to open it... I didn't put so much comments in there you'd easily get lost.

(remember to create an Alias of TNT basic and put into folder of tbedit)

when you open it, go to the "IncreaseFactories" procedure, that is where the error occurs.

To get the error, run the project (yes, it runs), then click new game, then open scenario, then an open dialog comes up.

Go into to "data" folder in the original folder. Go into scenarios-> defaultscenario, click the first text file. (called defaultscenariio also) and click open

>>
http://appleide.sitesled.com/PlanetaryWar.zip
>>

10-30-2006 10:10

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

Nevermind...

You can't declare arrays with 0 values, unlike in other BASIC languages...

10-30-2006 23:03

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

if you can't use 3D arrays, 2D arrays using the [x*width + y] form will do the job as good

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.