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.

Newcomers AppGameKit Corner / Arrays local global undim

Author
Message
Snowbird
9
Years of Service
User Offline
Joined: 16th Apr 2015
Location:
Posted: 26th Apr 2015 12:53
Hi,
I am new to AppGameKit Basic and I like it so far, yet I have problems with the documentation, as it seems confusing or incomplete at times. Thus I stumbled upon some commands, that I coudn't find proper documentation for.

First do #include headers have some kind of auto guard present, because most of my basecode depends on other parts and thus one file gets included over and over again, possibly, by itself and other parts, I have not run into problems so far, but coming from c and c++ I am confused as #insert is more like the c version and produces the double inclusion error, so I think the answer is yes, that #include has auto guards?

Another strange thing is that all inclusion paths are relative to the main.agc file, which means that if you wanna use lib code which has multiple files and is in a folder of it's own you need to include all the files within the lib as if they were included from outside the folder, this is not a good thing.

I can't find anything on what local does or what it is good for.

http://www.appgamekit.com/documentation/principles/1_datatypes.htm

Quote: "All arrays are created as global arrays, which means you can access their data from anywhere in your program. It is important to note that a global array must be declared at the top of the main source code of the program as arrays are dynamically created only when the DIM command is executed. Placing DIM commands at the top of included source code will not dynamically create the array unless it lies within a subroutine called from the main program. Essentially, your program has to DIM the array before it can access the array for reading and writing."


VS

Quote: "To maintain backwards compatibility arrays can still be defined with DIM, but version 2 introduces a new method of defining arrays that will become particularly important when defining them in types. Note that both DIM arrays and new style arrays perform exactly the same after they are declared so any functions mentioned here will also work on DIM arrays. The new method is mainly for consistency. The new method is as follows"


So if I declare something like this is it a global array and/or do I need to undim it at the end of the function, do I need to put local before b and c?
Does changing the length of an array to -1 free all it's elements or am I producing memory leaks.


Thanks,
This forum needs a preview button for posts and I still don't know my username.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 27th Apr 2015 09:39
I'm pretty sure that AppGameKit clears up after itself with regard to local arrays. You don't need to put local before the declaration but I tend to undim anyway because I like to clean up after myself.

Using AppGameKit V2 Tier 1
Snowbird
9
Years of Service
User Offline
Joined: 16th Apr 2015
Location:
Posted: 27th Apr 2015 13:06
Thanks, I really wasn't sure, because the informations were kinda contradicting and I have never seen the local keyword in use. Good to know that arrays can be local.

Login to post a reply

Server time is: 2024-11-23 11:08:02
Your offset time is: 2024-11-23 11:08:02