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.

AppGameKit Classic Chat / help with array/udt design

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Mar 2017 20:43
Thought I'd take another look at my old XML import code and decided that with AGK2 allowing arrays inside UDTs, I could make it better. Below is the structure I came up with. However, I can't use use a UDT inside itself. So I was hoping for suggestions how I might arrange a similar design. I feel like it's probably something very simple I can do but having a brain fart. Basically, object of type A can contain multiple objects of type A.


"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 2nd Mar 2017 23:05 Edited at: 2nd Mar 2017 23:06
I'm not sure if this would work but maybe you could have a function that has the required xml array defined within it.
It would populate the array and return the array.
So you could go something like;
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 3rd Mar 2017 07:57
The problem with your original code is that you have what is essentially a recursive array. So as you would need an infinite amount of memory just to store the UDT.
Perhaps you could set children as integer which is the ID reference within an array of XML_Element?
AGK V2 user - Tier 1 (mostly)
MadBit
VIP Member
Gold Codemaster
15
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 3rd Mar 2017 08:03 Edited at: 3rd Mar 2017 08:05
Unfortunately, you can not declare a variable in a type of itself.
So I solved the problem like this: All elements are stored globally in an array. In the element itself, for the child elements, are stored only the indices of the global array.
Just like here:


Another solution would be for children to take their own type and then declare it into the element.
Just like here:


I hope this inspires a little.

EDIT:
And again too slowly.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Pixie-Particle-Engine
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Mar 2017 12:46
Quote: "Perhaps you could set children as integer which is the ID reference within an array of XML_Element?"

I think that'll work. And thanks for agreeing with Scraggle Madbit

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-11-24 19:33:19
Your offset time is: 2024-11-24 19:33:19