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 DBPro Corner / Loading Entities/Objects with Statistics

Author
Message
Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 23rd Nov 2012 03:44
So i know i've been using DBP for a long time now, but i've been avoiding types and arrays and UDT's and all that, but i have a question.

Can someone explain a little better than the help file does, how exactly i make an entity that i can load into my game using a button or something that i'll code up in my game later, so essentially i'm asking:

say if i wanted to define, speed, health, shield strength, model filename, normal, texture, and lightmap filenames, scale, position, rotation etc... in an array? and how wouldi load the array into my game?
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 23rd Nov 2012 04:01 Edited at: 23rd Nov 2012 04:02
STYX

I would use an INI file for that...

Alternatively you could look at Matrix1Utils if that has INI handling too...

Of course there are a plethora of other methods too

Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 23rd Nov 2012 04:08
Hmm, ty very much for your quick response, i used to have styx on another account of mine, however i sold it for a steam account that had a few games i wanted on it... i do have Matrix1Utils... but i was wondering how i should set up my commands to do the arrays...
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 23rd Nov 2012 04:30
Are you not familiar with Arrays?

Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 23rd Nov 2012 05:07
No, i'm not, i've avoided them for years...
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 23rd Nov 2012 05:13
I would suggest looking at a few tutorials on here...

Part IV of TDKs tutorials may help

Or alternatively you could buy the Hands On Dark Basic Pro Books
Volume 1 Volume 2

Or alternatively, ask away, but if you search for "Arrays" at the bottom of this page in the "Google Forum Search" box, you may find more stuff on them

I would love to explain as much as I know, but I need to get going and will be busy for the next 6-7 days

Unless someone drops by and explains them in the mean time

Good Luck!

Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 23rd Nov 2012 05:20
Thanks for your help, Happy Thanksgiving!
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 23rd Nov 2012 05:21
Happy Thanksgiving! back

Sorry I could not be of more help right now...

Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 23rd Nov 2012 10:26
Unfortunately, i am unable to find any examples of say... loading an object and it's stats. like FPSC does with guns for example, if anyone can help, i'd appreciate it.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 23rd Nov 2012 12:14
What kind of statistics... Can you show a screenshot of an example or something?

I may have an idea of what you are asking of...

Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 23rd Nov 2012 12:20
Well, for example, remember those old drag and drop game creators? load a model, assign statistics to it, etc.. like in FPSC, that type of stuff.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 23rd Nov 2012 13:47
Do you mean data of the model... Not statistics...

Easy... Limb data etc?

Get limb name?
Get limb count?

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Nov 2012 17:33
DarkBASIC is a step away from FPSC. It doesn't support any drag-and-drop features right out of the box. This doesn't mean you can't program them yourself though, you just have to put some thought into designing your own little system for this.

First off, Arrays. Have you ever had the following situation?



Now what happens if you want to make 100 enemies attack? Make sure you have a spare keyboard because the C and CTRL keys are probably going to explode.

We're not going to even go there though. Arrays are always used when you have more than 1 thing in your program. So, if we were to convert the latter so it uses arrays, this is what it would look like:



You may be asking yourself why I used the number 5 when there are actually 6 enemies. The reason for this is because arrays start at 0, not at 1, so you have to subtract your maximum value by 1.

Excellent! Now, what happens if your enemy has more than 1 variable? Something like this for example:



This works, but it's not a very nice way of doing it. You have to create an array for every single variable your enemy has.

This is where UDTs (User Defined Types) are helpful. UDTs allow the programmer to create a hierarchy and structure their values. So lets look at how the above would be solved using a UDT:



Alright, cool. Now we didn't necessarily write less code for that, but think of it this way. If you want to add or remove more parameters for your enemy, you only have to edit what's between the type and endtype keywords. That, and your program is a lot more structured.

There is actually even more structure we can get into it. You see these lines?



Because the word Position is used 3 times, we could create a UDT for it as well. Let's see how that would look:



As you can see, you can use UDTs inside other UDTs. This gives you the power to create and manage larger structures. Just for example, in my RTS game (click my sig) I have a UDT that looks like this:



Lots and lots of UDTs there.

Now, the other cool thing about what we have right now is that you can save the array to a file. I believe the command is save array:



And later on, you can load your enemy back into memory:



I hope this helped! If you have any further questions, I'd be happy to answer them.

TheComet

Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 23rd Nov 2012 20:45
You did a great job, however, how would i go about assigning that to a model?
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Nov 2012 21:06
You just add that to the UDT. Taking the example above, this is what you'd do:



TheComet

Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 23rd Nov 2012 21:18
Ah, thanks, very awesome. ty so much.
Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 26th Nov 2012 19:28 Edited at: 26th Nov 2012 19:29
I have a question/comment related to TheComet's post.

Quote: "
Save array
"


I believe there is no such thing as saving UDT arrays in darkbasic, correct me if I'm wrong.



I've heard there is a matr1x ultilities plugin, but me personally couldn't make my UDT get saved that way either.
Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 26th Nov 2012 20:39
Once you know how arrays work, remember that you can store the data outside of your program, say, in a .CSV file (Comma Separated Value, which is kinda like a spreadsheet).

Using .CSV files, you can handle all sorts of data for your game. Everything from menu text, character names, weapon attributes, everything! Why I personally like them is that once working, if I want to change a value, I just edit the .CSV file and re-run my game. No need to edit the source code.

Stick with learning arrays for now, you'll need to understand as much as you possibly can about them. Post up your code too so we can check it for you.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 27th Nov 2012 01:19 Edited at: 27th Nov 2012 01:27
You can't save arrays using the Save Array command, if the array is UDT defined.


UDT arrays can be converted to memblocks using MAKE MEMBLOCK FROM ARRAY, and memblocks can be written to file; although I prefer to use banks from Matrix1 utilities, as stated above; slightly slower than memblocks, but you are not limited to 255 memory banks.

You can then convert your array to a memblock, which can be mapped to file via memory banks; all of this is discussed in full detail in the help files attached.

The second way; although really there are 100s of ways to save statistics; is to store each property in its own array like so:


Each of those can be saved seperately, this requires more house keeping but is more versatile than UDTs, because more commands work with standard arrays. Each of these files can reside inside of a single file; be it file blocks, or write file to file.

Another easy way is to use what FPSC uses; INI files; although FPSC has its own INI structure. Matrix1 utilities has a Lookup section that handles INI manipulation; an INI file looks like this:



This way is easy to use, but the slowest. Styx XML is faster, and is better for relational data; but not very hard drive friendly; the smallest XML data block is 4 bytes long; which only stores 1 byte of data
, which styx cannot understand. Other XML libraries such as Kaedroho's XML plugin might be able to read it.

The difficult way is to store your statistics is to write directly to memblocks or banks. Why would you do such a thing, you might think. But actually doing that will teach you many tricks of the trade; it's a good way to force yourself to become comfortable with programming. Getting good with memblocks and banks is an investment worth taking if you are taking this seriously. Although, Arrays are still the fastest for temporary storage; things that do not need to be saved to disk.

Just to clarify, FPSC's source code has memblock stuff everywhere, and you can do things with them that you can't with UDTs, such as having a variable amount of variables per class, storing classes in classes, copying sections of classes to other sections and making your own datatypes or file formats, not to mention memory sharing between apps and networks. Here's a hint:


As you can see, there's still alot of plain english with memblocks; and this example is not even full managed; you can see how you can make it a breeze to store and share data using functions which automate things so you won't even need to write a single memblock command directly.

More on memblocks and datatypes here

Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 27th Nov 2012 07:00 Edited at: 27th Nov 2012 07:04
Well, here is my code...i am very ashamed to post it...



Also, i don't know if anyone can help me with multisync or not but it seems i broke the bit where players can see each other >.> somehow...
Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 27th Nov 2012 07:01 Edited at: 27th Nov 2012 07:04
A mod can delete this, sorry for the double post.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 29th Nov 2012 01:50
That's alot of code to read, how did everything go? I see lots of effect commands in there; any screenshots available?

Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 29th Nov 2012 04:46 Edited at: 29th Nov 2012 04:48
http://www.stbc2.com/upload/c:%5cScreenshot-6.png
http://www.stbc2.com/upload/c:%5cScreenshot-7.png

There's more, i'll have to make a gallery or something for it :p

What i really need is someone who knows about DBP to help me lol.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 29th Nov 2012 11:29
Very nice! You should post up a WIP, this looks better than some of the WIPs. I like the blue glow on the thrusters.

Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 30th Nov 2012 23:51
I am still having problems comprehending how i would go about loading a model in an array... sorry i know this seems repetitive.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 1st Dec 2012 03:01 Edited at: 1st Dec 2012 03:03
The array doesn't contain the actual model. All the array does is store a "pointer" to the object.

If you load an array from a file, you still have to go through every element and additionally load objects for it. For example, let's assume you load an array from a file and it has a total of 2 indexes:



What you've done there is load data describing what the entity should look like. It doesn't automatically set up everything for you. You have to now go through all elements of the array and do that yourself, for example, like this:



Why are you so fixed on an entity system anyway? My suggestion is to forget about all of this and just start at an easier level, it'll be a lot less painful for both of us, and you'll get a grasp on this stuff later on anyway.

TheComet

Login to post a reply

Server time is: 2024-11-23 18:22:52
Your offset time is: 2024-11-23 18:22:52