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.

Author
Message
Unseen Ghost
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 14th Feb 2021 18:13
To remove or delete a type that has been loaded into memory I guess I have to use an array to track which media is loaded to be able to remove it or delete it? Am I right or wrong?

I know Blitz basic has commands to do it quite easily to my knowledge like:
Delete Each LoadedMediaData

The snipet below is what type I'm using



Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 730 2GB/1TB Western Dig. SSD/Windows 10 Home/Dark Basic Pro 9Ex

No one cares how much you know until they know how much you care.
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 14th Feb 2021 23:05
User Defined Types are essentially Variable Templates., thus they only exist as long as said Variable does.
In the case of individual variables... i.e.

myVariable As myType

This is going to exist as long as the variable is in Scope.

i.e.
Global myVariable As myType // this will last as long as the application is running

Function myFunction( )
Local myVariable As myType // this will last as long as the function is running
EndFunction

Now something we can do to manage the Lifetime of a Variable is to put them into Arrays
i.e.

Global DIM myVariable(0) As MyType

Then we can use the:
Array Insert At Element myVariable(0), Element
Array Delete Element myVariable(0), Element

To expand / contract the Array obviously creating or deleting each new Variable Element; and thus the associated memory that the Type uses.
You can obviously pair this with Functions to handle extra aspects; such-as say Loading / Deleting Images, Mesh, Sounds, etc. for essentially handling your Media Management.

Does this all make sense?
Now if you wanted to get really Advanced; you could always write your own Array Functions using Pointers and Memory., as DBP does allow you to create and manage memory directly; but I'd usually suggest not doing that, as well it is quite advanced and I'd argue that while these were excellent additions to the DBP Language, it really needed some other 'enhancements' to better utilise it.
Unseen Ghost
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 16th Feb 2021 01:36
I won't be using pointers. I'm not familar with them.

I understand arrays, but I don't understand them. I can create one, but my issue is I get confused on how to update the array as needed and do what I need to do with them to keep track of things. I hate arrays because I get confused
Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 730 2GB/1TB Western Dig. SSD/Windows 10 Home/Dark Basic Pro 9Ex

No one cares how much you know until they know how much you care.
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 16th Feb 2021 02:30
Arrays are very simple things to understand... well not how I tend to use them, but eh., I have a habit of trying to want to do things I can in C++ in AGK.
Point is the best way to look at an Array is like a Grid., or Table.

Once you get that concept down, they become much easier to visualise.
In any case AppGameKit and DBP both are intended as "User Friendly" Languages., and so they more-or-less handle all the clean up for you... the only thing you really need to worry about are Resource Assets (Images, Sounds, etc.) that you manually Create and Delete.
This you will need to keep track of and ideally remove when no longer needed.
Unseen Ghost
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 16th Feb 2021 19:44
It's kinda weird though, I can create an array, but not understand how to operate them like this example. Say hypotheticaly I want to use an array to keep track of the number of player characters online + their class + coordinates. The numbers will be small just for the example. Say there is 100 players online. Obviously I would create detection of anyone else that logs on and add them to the array, but for a simple example we will keep it at 100. So I would create an array like this probably:




Please let me know if I forgot something in above code.

Can someone give me a plain english explanation of how to update an array as needed in a program?
If you choose to give an example, please don't give code example that has a large amount of code that has nothing to do with the example and question at hand. It makes it hard for people like me to understand what is going on quickly let alone at all. A lot of times people give example and explanations that people don't need just for something that should take a smalll amount of code.

Also, I have a couple more questions about Types and arrays

To have dynamic arrays, I read in help files that you should have Arrays at the top of main code. So my question is, if you have multiple #include code files, and you have Arrays that pertain to stuff in the #include code files, can you put the Arrays at the top of the #include code files that they pertain to and still have them be dynamic, or do all Arrays no matter what have to go at the top of the Main code file to be dynamic like help file says?

Types question. Types delclarations that are part of any Array should go at the top of Main code file above Arrays they pertain to, correct? Or can you put Types that don't pertain to Arrays anywhere, even in #include code files?
Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 730 2GB/1TB Western Dig. SSD/Windows 10 Home/Dark Basic Pro 9Ex

No one cares how much you know until they know how much you care.
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 17th Feb 2021 01:12
Quote: "To have dynamic arrays, I read in help files that you should have Arrays at the top of main code. So my question is, if you have multiple #include code files, and you have Arrays that pertain to stuff in the #include code files, can you put the Arrays at the top of the #include code files that they pertain to and still have them be dynamic, or do all Arrays no matter what have to go at the top of the Main code file to be dynamic like help file says?

Types question. Types delclarations that are part of any Array should go at the top of Main code file above Arrays they pertain to, correct? Or can you put Types that don't pertain to Arrays anywhere, even in #include code files?"


Alright, so this might get a little confusing., but as DBP will Auto-Declare and Assign Variables when you first use them this can cause some issues...
The first being that the Auto-Assignment works based on naming: i.e. A = Integer, A# = Float, A$ = String... the only way to not use the # (for Floats) or $ (for Strings) is to explicitly declare them with the 'As' Keyword.
i.e.
A As Integer
B As Float
C As String

What's more you can't have 2 Variables names the same thing... so let's say you use a Variable at the start of your code: ProgramTicks = Timer( )., but later on you're trying to declare it: Global ProgramTicks As Float... well you're going to have a problem, as the Application will think it's already declared and as a different type.

I'd suggest getting in the habit of explicitly declaring every variable you use, with the common exception is a For...Next Loop Variable; as it's common to use a single letter or such just to have a loop counter.
Now if you DO use explicit declaration, like Types and Arrays... well they'll ONLY be usable AFTER you've declared them.
And as #Include appends everything to the END of the Main Source File (with up to 255 Includes allowed., and yes these can be within other includes; but remember that would be appended to that include THEN to the parent source)

This however is where Code Flow functionality comes into play (i.e. Labels, GoSub and GoTo)
These are quite simple to use... we construct a label with the ':' Symbol at the end of an identifier...
We then have 2 Types of Jump Command
GoSub <Label> // This will jump to the given label, but acts as an anchor to where it was called; so when the Return command is called it will jump back to said Anchor point and continue.

i.e.


GoTo <Label> // This is slightly different, it isn't an Anchor point, so even IF we do have a 'Return' Command there is nothing to return to... and in-fact it will cause the application to crash if you include it.
i.e.



In essence we can essentially encapsulate our #Include Declarations in a Label and Return... this would then allow you to call a GoSub at the top of your program to declare everything within said included Source.
Alternatively, said Variables and Types will ONLY be available to that include source and later includes; which is when ordering becomes important.

Now a common trick is to basically name the GoSub something common... so let's say we have a Maths Library Source., well we'd name the file Maths.dba
I tended to use the pre-fix "Include" with the Filename., as it's easy to see that we're in this case GoSub IncludeMaths and that's where all our declarations are and usable by the Main Program.

Quote: "
Can someone give me a plain english explanation of how to update an array as needed in a program?
If you choose to give an example, please don't give code example that has a large amount of code that has nothing to do with the example and question at hand. It makes it hard for people like me to understand what is going on quickly let alone at all. A lot of times people give example and explanations that people don't need just for something that should take a smalll amount of code.
"


There are a few approaches to use., this example I create a Blank Array (with your Types) and have manually added some Template Data.
What the first loop does is Dynamically Grow the Array, while adding each line of Data (at the Bottom)
Then we print the Results in the Main Loop be getting the Data.





Now typically for Static Data., you'd add a Terminator that is checked for; to know when you've reached the end... this is easier loading from Files or Network Messages., as there are definitive ends.
For example with a File you might write Repeat : // Reading Ops : Until FileEOF( FileID )
But you get the idea.
Unseen Ghost
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 18th Feb 2021 03:05
Thank you Raven for the explanation above and the example code. I will play around with your last code snippet to see what I get in a test program and hopefully get more understanding of arrays. I think I see what is going on in your last snippet, I just want to see it when it is ran in front of me. One thing I don't understand in the snippet is why is there a read statement above anything that has the variable info$?

Read Info$

As far as just your snippet only is concerned why is it above everything that even has to do with the variable to even have something stored in the Info$ variable. If the program doesn't have anything stored in the Info$ variable, why read it first? Unless I'm missing something. The program doesn't jump anywhere to have Info$ stored in it.

I'm still thinking about where to put the declarations of the Types and Arrays in my program. I think I mostly understand what you said about where they can be put and how.
Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 730 2GB/1TB Western Dig. SSD/Windows 10 Home/Dark Basic Pro 9Ex

No one cares how much you know until they know how much you care.
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 18th Feb 2021 07:07
Read is just the command to "Read" the next entry in the Data Statement below the Label we restore.

The reason it is the way it is ( instead of being Info$ = Read( ) )., is for Compatibility Purposes with Dark BASIC Classic... and that language does it that way because that's how older BASIC Languages did it.
It's one of the few (odd) examples where it isn't an obvious function that is getting information rather than setting it.

But if that's still confusing, don't worry about it... it's not really an important part of the example, it's just an easy way of adding data without typing everything out in long-form or reading from a file (that obviously doesn't exist).
What you can do is add another DATA line at the bottom, with the same format (Name$, Type$, X, Y, Z) and change the Account = 0 To 3., to Account = 0 To 4
It'll basically add another "Player" Record for you.

I'm quite busy this morning, but I'll throw together a Static Array Example later for you.
Unseen Ghost
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 18th Feb 2021 13:28 Edited at: 18th Feb 2021 18:07
Holy cow, I totally forgot about the data statements at the bottom lol. I have done some data pprogramming awhile back. I made a program the reads from 200 different text files. It prints one character at a time and you can pause the printing and restart it. It has a glitch at some point though and I need to fix it eventually. I forget the glitch, but it works for awhile and youncan choose a verse you want to see on screen from a certain version of the bible. You can get through multiple verses and then it screws up eventually lol

I am better at 3d work and my brother is a master at data reading and manipulation programs. He has a business now though and doesn't have time to help. Looking forward to your example. I need to get data stuff down a lot better
Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 730 2GB/1TB Western Dig. SSD/Windows 10 Home/Dark Basic Pro 9Ex

No one cares how much you know until they know how much you care.

Login to post a reply

Server time is: 2024-04-19 06:38:48
Your offset time is: 2024-04-19 06:38:48