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 Professional Discussion / Help with array setup for items

Author
Message
wickedly kick it
20
Years of Service
User Offline
Joined: 13th Jul 2006
Location: Fort-worth Texas
Posted: 5th Sep 2014 04:38
It's been a while since i diddled in dark basic pro, but i'm making a game engine for my games right now, and i'm working on items, and each item has a "Flag" associated that effects the way each item behaves later in code, however i need multiple flags for this type, and i know it is impossible to put arrays in UDTs, but is there a work around?
What i'm working with:


WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 5th Sep 2014 04:50
If you setup your array as an array of UDT's. You can use a DBPro trick and set a DWORD value equal to the UDT array. This will set the DWORD value as a pointer to the array. Then store the DWORD in your original UDT.

arrayPtr as dword
arrayPtr = myArray()

wickedly kick it
20
Years of Service
User Offline
Joined: 13th Jul 2006
Location: Fort-worth Texas
Posted: 5th Sep 2014 04:57
aha! thanks

WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 5th Sep 2014 05:06 Edited at: 5th Sep 2014 05:14
You could also use - make memblock from array - and store the memblock ID in your UDT.

Edit: If your array contains string values the memblock will contain pointers the the strings.

luskos
19
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 8th Sep 2014 05:43
This looks interesting.I've never used pointers before.Can you give definition of a pointer and for what it's used best for.Simple example of pointer in action will be most appretiated.

Coding is My Kung Fu!
And My Kung Fu is better than Yours!
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 8th Sep 2014 14:29
This is a simple little demo. It is using a UDT array with a string and an integer value. Pointers are used to print the values. Look in the help file under Principles - Data types and variables, for more on pointers.



luskos
19
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 8th Sep 2014 23:48
What is "4" in the example?Why you inc ptr exactly that value?

Coding is My Kung Fu!
And My Kung Fu is better than Yours!
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 9th Sep 2014 02:00
After setting the pointer to the dword value, it will point to the first value. The first value is a string. So, the pointer is pointing to a dword pointer to the string. A dword occupies four bytes, thus to get the next value we increment the pointer by 4.

Login to post a reply

Server time is: 2026-07-18 07:32:32
Your offset time is: 2026-07-18 07:32:32