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 / storing data

Author
Message
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 15th Jun 2014 07:11
I'm not really sure how to go about saving data or if there is another way. what im trying to do is draw boxes on the screen and when the mouse is released to continue to draw the last box then you can draw another one. I dont want to use sprites or images.




A child's dream never dies.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Jun 2014 22:26
Here's a commented example for ya.




smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 16th Jun 2014 13:26
To me that is a beautiful piece of coding there. That is pretty much exactly what I wanted to Pahelax. I've looked high and low for a good tutorial on arrays and how to use them, Ihave yet to find anything in my book or help files my book seems to cover mostly 3d and 2d not core functions or maths, still dont understand what a type does or dim or how to use data arrays or memblocks, it's frustrating it holds me back frequently i have to come up with complication solution like writing to files to store info. Db is really my first language. Thank you ill see if i can figure it out.

A child's dream never dies.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Jun 2014 03:45
Think of a "type" as a variable with multiple values. Each sub-component can hold a different value. Think of it as like a toolbox. The toolbox holds many different tools but they all belong and are part of that one toolbox. In this case, MyBox is the toolbox. The x1,y1,x2,y2 values are just tools belonging to that toolbox. The boxes array is a garage, it holds many toolboxes.

If you think of your garage as having shelves to hold the toolboxes, then when I call array insert at bottom we're adding a new shelf in the garage to hold another toolbox.

boxes().x1 = x1
boxes().y1 = y1
boxes().x2 = x2
boxes().y2 = y2


This part is where I define the tools in a particular toolbox. Typically, you'd use the array index inside those parenthesis, but DBP has a little undocumented trick. Not specifying an index at all will automatically point to the end of the array (or the last inserted element, I'm not 100% sure). Either way, after we insert a new array element (a new shelf) to the garage, we're assigning the box coordinates (tools) to the newly created toolbox.

DIM is used to allocate a chunk of memory for use with arrays. If you know how many elements you'll have, it's preferred to specify the size upon creation, it's more efficient this way. It's what we'd refer to as a static array, as in it does't change in size. A dynamic array can change in size, which is what this code example uses. It starts out as an empty array, that is, a garage with no shelves for any toolboxes.

smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 19th Jun 2014 08:05
your extremely helpful man. you should be writing tutorials lol, very grateful for your time man.

A child's dream never dies.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Jun 2014 01:45
I have written a few

http://dbcodecorner.com/?page=tutorials

I should probably update them, or least check they're properly done.

smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 21st Jun 2014 02:55
yeah i thought i was getting a lot better, just a causal coder few times a year for a week or so when i get an itch. I really do love the layout and cleanliness of the code very well done actually learned how to properly use functions from this example as well up until now iv just used them for sub routines and to organize never passed variables with hem though

A child's dream never dies.
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 21st Jun 2014 02:56
can i store objects in memblocks?

A child's dream never dies.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 21st Jun 2014 11:34

Login to post a reply

Server time is: 2024-04-19 01:07:29
Your offset time is: 2024-04-19 01:07:29