Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Using Global Variables or Datatype

Author
Message
ArcherSam
15
Years of Service
User Offline
Joined: 13th Mar 2011
Location: Florida, US
Posted: 25th Mar 2011 21:13
Hey,

My problem is i'm trying to utilize an array declared in another source file but I keep getting the error array doesn't exist or wrong subscript.
Also I need to know if a variable or datatype is modified in another source file, if call again will it remain modified?

Sam



Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 25th Mar 2011 21:34
Well, you are declaring a type that uses another type that has not yet been declared.

If you put the Intelligence_Design declaration at the top, then the Character_Design declaration doesn't throw the error.

ArcherSam
15
Years of Service
User Offline
Joined: 13th Mar 2011
Location: Florida, US
Posted: 25th Mar 2011 22:28
Thanks Rich! That makes perfect sense. LOL. Can't believe I forgot the basics.

So now why do I get an error when I try to "PRINT character(1).Radius" in the Class A source file?
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 25th Mar 2011 22:55
Quote: "So now why do I get an error when I try to "PRINT character(1).Radius" in the Class A source file? "

you can't declare a type inside a include file. If you want do do that you'll have to put the type declaration inside a gosub otherwise that part of the code never gets executed

ArcherSam
15
Years of Service
User Offline
Joined: 13th Mar 2011
Location: Florida, US
Posted: 25th Mar 2011 23:15
Thanks Brendy Boy! Prior to your message I had just discovered in the DarkBASIC professional Help File > Main Menu > Principles > Datatypes and variables > ARRAYS that
Quote: " It is important to note that the global array must be delcared at the top of the main source code of the program as arrays are dynamically created only when the DIM command is executed. "


Also that solves all my problems. Now I can create design types and create global arrays without errors. Here's the source code that gave fix the problems:





Also I have one question, in a couple of brief statements can you describe how the main source code functions in a program?
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 25th Mar 2011 23:29 Edited at: 25th Mar 2011 23:51
Well, sort of. You can define a type in an include file, and you don't even have to execute it. But you do have to execute the declare statement for the type variable you are going to use.

These two work together...





To me, the amazing thing is that you don't have to execute the code that defines the type, you just have to have it "above" the actual declare. And as has been mentioned, an include file is basically just pasted onto the end of your main code.

Anyway, in answer to your original question, a variable can be modified by code in an include file, with the caveat that the variable must still be global if the modification is done in a function, and that the code must be executed, either by function or gosub calls.

Note that all arrays are global, and don't need the "global" in front of the "dim" statement. And you can take all the "global"s out of the UDT definitions, too.

Login to post a reply

Server time is: 2026-07-16 23:18:33
Your offset time is: 2026-07-16 23:18:33