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 / TYPE-ing tutor?

Author
Message
Mr909
12
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 16th Oct 2012 00:02 Edited at: 17th Oct 2012 00:39
I want to learn to use a TYPE to describe my characters and items within an RPG. I was wondering if you could link me to a good tutorial to describe this process and how to use it.

Also, does anyone know the return for RGBR() and it's brother functions? Because I need to do math (so that the numbers will not exceed 0 going downward or 255 going upward) but I get something I can best equate to a math error.

EDIT: I have some new questions and was courteous enough not to bump:

Is there a way to produce a function capable of accepting different sets of arguments? Like, for example, BOX can be either (x1,y1,x2,y2) or it can also include four colors. I was wondering if there was a way to do this for other functions.

How would I go about implementing complex data types into a function, if at all possible? I have an idea for a function that returns values for an array, but I would obviously need to use that array as an array, get it's top and bottom indices and dimensions, etc.

Also, on the returning end, is it possible to return an array?

Does anyone have a triangle drawing function? Because I sure could use one :\

Anything helps.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 17th Oct 2012 13:00
Quote: "Is there a way to produce a function capable of accepting different sets of arguments? Like, for example, BOX can be either (x1,y1,x2,y2) or it can also include four colors. I was wondering if there was a way to do this for other functions."

Yes, but technically no. Here's the cheat:


Quote: "Also, on the returning end, is it possible to return an array?"

Yes and no again. You can pass pointers if you know how to handle them and make your own data-structures. The example would be a little complicated but along the lines of the above example, only you'd be working with raw data.


Quote: "How would I go about implementing complex data types into a function, if at all possible? I have an idea for a function that returns values for an array, but I would obviously need to use that array as an array, get it's top and bottom indices and dimensions, etc."

Not too sure what you mean there but if you're wanting to have a function modify an array, simply reference the array in the function. Arrays are always global in DarkBasic. There are also DB functions to return an array's index-count etc such as ARRAY COUNT(). Also, arrays in DB are dynamic so you can resize then with DIM, the same way you created them. Expanding an array this way will not erase or displace data, however shrinking will obviously, as will inserting elements.

Quote: "Does anyone have a triangle drawing function? Because I sure could use one :\"

This:


Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 18th Oct 2012 00:01
Quote: "DBPro tutorials for types..."

Do you know how long I've been searching for those?! Each time someone has asked about types I've had to write this long explanation while they've been nicely tucked away in the newsletter. Well, at least I know where they are now.

Quote: "Is there a way to produce a function capable of accepting different sets of arguments?"

This is known as function overloading and DBP doesn't support it for user functions. nonZero's provided a nice work around but if you don't plan on making too many overloaded functions, I'd just put a number after each to differentiate. e.g have box(x1,y1,x2,y2) and box2(x1,y1,x2,y2,r,g,b) etc.

Mr909
12
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 18th Oct 2012 00:55 Edited at: 18th Oct 2012 00:57
Thanks for the link, Batvink!

Thanks very much, nonZero!

As far as the argument workaround, I might use it, but I'm not sure. I have so much dependent on string de-concatenating already that I feel it would get confusing. But still, I might.

Arrays are global, eh? That's good. I am working on something to compress a list, i.e. avoid creating gaps whenever someone takes an item from their inventory, etc. and I was wondering how to go about it.

I feel the fool for not specifying: I meant a filled triangle. Because with it, I could then cover a number of other polygons by using the triangle.

Thanks for your input also, Hodgey!

Oh, also, I'm trying to work on a perk list for characters, but I don't think that TYPES accept arrays, if so I don't know how to do it. Probably going to make perks list a separate array and then move it whenever I move characters around, but does anyone know if I HAVE to do it this way?
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 18th Oct 2012 01:04
I'm on my mac so I can't search through the documentation to confirm but the MatrixUtils might have something.

Quote: "Thanks for your input also, Hodgey! "

Your welcome.

Quote: " I'm trying to work on a perk list for characters, but I don't think that TYPES accept arrays, "

You can't have arrays within types but you can have an array of types.
E.g - won't work:
type sometype
dim a[5] as integer // won't work!
endtype

Mr909
12
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 18th Oct 2012 02:32
Hmmm... all it has is a "flood" command that could be very useful but, to be honest, I don't like where most of the MatrixUtils seem to be going. Maybe later in my programming life.

I thought as much, thanks for confirming. I think I'm going to bind the perks to a separate array and move them as one. Sounds most promising.

Thanks again.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 18th Oct 2012 09:57
Quote: " to be honest, I don't like where most of the MatrixUtils seem to be going. "

I recommend installing them anyway. A lot of the code snippets on this forum depend on them.

Quote: "I thought as much, thanks for confirming. "

One thing I forgot to consider was having a pointer within your type, pointing to an external array. I learnt about pointers after moving away from DBP so I'm not familiar with them in DBP but even if that setup worked, you would still have to set up a bunch of external arrays.

Mr909
12
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 19th Oct 2012 00:54 Edited at: 19th Oct 2012 01:56
Yeah, which I was doing anyway.
Meh, what's the licensing on MatrixUtils?

Also, #INCLUDE doesn't seem to be working as it should (name "setup" is duplicated in "Scribus.dba"). I thought someone gave me the solution but I tried it and it didn't work or I couldn't figure it out, I can't remember which. I'm using the standard IDE. Any help?

EDIT:

Also, are there any functions to get system time? I swore they used to exist, and I wanted to use them for RANDOMIZE seeds.
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 20th Oct 2012 20:17
okay, dunno what the licence is on matrix utils but I know they are free to use so presumably they are free for non-commercial use too. You'll no doubt find a copyright notice in the package.

About the #include command: in simple english; it is stuffed. You have no choice but to use the editor's gui to add additional source files. Myself and others have moaned about this bug for ages but it looks as though it's not high on the tgc priority list coz most ppl like click click click... *sigh* the PC world isn't backwards compatible with me.

Finally, there are two timer commands: TIMER() and PERFTIMER() - no kudos for guessing which is the more accurate, lol. As for seeding, there is a strange reaction DBP has (or at least had) with seeding the random number generator where the results became less random, regardless of what number is (or was) used as a seed. I would, if I were you, either stick with NOT setting a seed, OR using a random number generator from a quick, homebrew dll. Personally, I find I never have to use a seed as I get a sufficiently random pattern for anything I'd do in DBP (enemy encounters, item drops, dice rolls, etc).

Mr909
12
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 20th Oct 2012 21:38
I was referring to the day, hour, and month on the system clock. I know there used to be one in standard DB. And as far as random seeding goes, I ran this Gaussian curve test/integrity check that seemed to indicate that, as long as you generate a new seed frequently enough, random number generation met the patterns I was aiming for (See my random number generator in the other thread)

And sadly, I am (trying to) going commercial with my projects and don't want to use code precluding that possibility. Maybe I'll read through the licensing info.

Editor's GUI? Was'sat?
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 21st Oct 2012 00:17
Quote: "dunno what the licence is on matrix utils"

This was posted by IanM himself.

Quote: "Warranty: None, for any purpose whatsoever.
Conditions of use: None.
Royalties required: None."

So I'd say you could use them for commercial use. If you're still unsure ask in the MatrixUtils thread.

With #include, if you see your source files in the solution explorer then you don't need the use #include.

Mr909
12
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 21st Oct 2012 00:55
Yeah, I shot him an email on it, it appears it's clear but I wouldn't feel right if I didn't at least offer a donation.

Quote: "With #include, if you see your source files in the solution explorer then you don't need the use #include."


Hodgey, you are a genius.

Now that I have that working, I can actually proceed on the engine for the first time in a long time. Thank you.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 21st Oct 2012 01:12
Glad it's all working out, happy programming!

nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 21st Oct 2012 19:24
Quote: "...as you generate a new seed frequently enough, random number generation met the patterns I was aiming for..."

Oh, good. Had a (very) brief look at the thread. Glad to see the issue with seeding seems to no longer be an issue

Quote: "Editor's GUI? Was'sat?"

Not sure if that was sarcasm, OP, as I'm no longer surprised by things posted on this board, lol. Anyhow, just in case it wasn't:


Mr909
12
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 23rd Oct 2012 23:45
@nonZero, yeah I know what a GUI is, I just didn't know where/what the EDITOR'S GUI is. But yeah, for some odd reason they're working despite not showing up in the solution explorer XD

Login to post a reply

Server time is: 2024-11-27 11:04:59
Your offset time is: 2024-11-27 11:04:59