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 Discussion / equivalent of C structures

Author
Message
fatmanfat
21
Years of Service
User Offline
Joined: 24th Jun 2003
Location:
Posted: 25th Jun 2003 02:27
I've written a few games in C where usually things are based around structures which hold different types of information, eg.

struct player
{
int x;
int y;
real health;
char *name;
};

sorta thing

Is there any way of doing this in db. There's obviously no built in way but is there a clever way of organising data to get the same sort of flexibility?

-fatmanfat-
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 25th Jun 2003 02:35
giggles at the new users
look up types bro for DBP.

Ag3ntSm1th
22
Years of Service
User Offline
Joined: 13th May 2003
Location:
Posted: 25th Jun 2003 03:55
i know you're a moderator and all, but these are the DBC forums.

"The secret to creativity is knowing how to hide your sources." - Einstein
my DarkBasic creations - http://www.sixurbanninjas.tk
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 25th Jun 2003 04:28
"DARKEDIT" has access to types which are cascaded back to arrays for classic.

lol giggles at other users.

fatmanfat
21
Years of Service
User Offline
Joined: 24th Jun 2003
Location:
Posted: 25th Jun 2003 13:15
couldn't find anything about that in the documentation - i'll dig around some more - thanks.

Furiousuk
22
Years of Service
User Offline
Joined: 10th Jan 2003
Location: United Kingdom
Posted: 25th Jun 2003 13:32
The TYPE command in the editor is, for most purposes, exactly the same as 'struct'. The source below just outlines a simple implementation of the command.

Your other option for creating your data is to use parallel arrays, whereby,
dim Player(2) = holds x,y and health data.
dim Player$(1) = holds name and (e.g.) weapon name data.
Furiousuk
22
Years of Service
User Offline
Joined: 10th Jan 2003
Location: United Kingdom
Posted: 25th Jun 2003 13:38
Oh, also, you'll be aware of how useful the 'C' command 'switch' can be. This is also implemented within DarkEDIT using the 'select' command.
fatmanfat
21
Years of Service
User Offline
Joined: 24th Jun 2003
Location:
Posted: 25th Jun 2003 15:46
Thanks, that's brilliant, just what I was looking for. I'd worked out that you could do it with parallel arrays but it's a bit of a do.

I saw there was a select command mimicking switch.

So... is there anything that works like a pointer?

-fatmanfat-

fatmanfat
21
Years of Service
User Offline
Joined: 24th Jun 2003
Location:
Posted: 25th Jun 2003 22:04
Aha, Memblocks - right?

Juventus
22
Years of Service
User Offline
Joined: 22nd Apr 2003
Location: Australia
Posted: 1st Jul 2003 18:54
Types look like they could be extremely useful. Are there any good tutorials on them around?

Thanks.

http://www.geocities.com/jux_of_my_newt/
Furiousuk
22
Years of Service
User Offline
Joined: 10th Jan 2003
Location: United Kingdom
Posted: 1st Jul 2003 22:14
I haven't found any yet, although if you can get your hands on a C book, look up structs. Most of the theory about using them is the same, you just have to translate the syntax.

fatmanfat:
I haven't got as far as working out memblocks yet, I thought I'd wait till I can afford DarkBASIC Pro and learn then. Pointers scare me anyway.
fatmanfat
21
Years of Service
User Offline
Joined: 24th Jun 2003
Location:
Posted: 2nd Jul 2003 01:35
yes - i'm not sure that memblocks will do the trick.

i haven't had a lot of time to play dbc this week but i'm finding it quite frustrating to work around the clunkiness of basic.

pointers are scary when you first use them, but i found that if you forget about the theory and just concentrate on the use then they're not too bad. and they're incredibly useful - you can have things like an entity structure which includes a pointer to an animation structure. makes for nice neat code.

Furiousuk
22
Years of Service
User Offline
Joined: 10th Jan 2003
Location: United Kingdom
Posted: 3rd Jul 2003 21:32
Yeah, I was starting to realise that the theory to pointers is more complicated than the application, thanx for the tip though.

I always think that BASIC feels a bit 'flimsy', like it'll break or slow down when pushed to the limits, and C++ just feels slicker somehow. Still, with DarkBASIC you can get a lot up and running very quickly.

I'm still looking for info on how to use memblocks and in what situations they are the best (quickest) option.
Dreadlox
21
Years of Service
User Offline
Joined: 31st May 2003
Location:
Posted: 6th Jul 2003 17:07 Edited at: 6th Jul 2003 17:11
C : Don't even go there, this programme is just far too advanced for me.
C++ : An extreme amount of effort and work required for very little return.

I've tried to learn these languages, but there complexity bogged me down and was the reason I was put off being a programmer proffesionally.
Life's too short.

Login to post a reply

Server time is: 2025-05-19 22:41:20
Your offset time is: 2025-05-19 22:41:20