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 building a recursive type function?

Author
Message
Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 29th Mar 2019 17:48 Edited at: 29th Mar 2019 17:56
I want to run an indefinite amount of loops.

I have an array of sprites. Each sprite can have 1 parent. But sprites can have many children. If a top level sprite is deleted, I want all the childs, grandchilds, great-grandchilds, etc to be deleted. Currently I record each parent and all the children of that sprite. Going beyond that requires me to implement some sort of recursive function( I think ).

I am stuck on how to solve this problem. Every time I think I solved it I realized I only solved 1 or 2 generations. Appreciate any guidance.


I currently have this. I am not done testing it. I am afraid it has the potential to miss out on Folders, though.

Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 29th Mar 2019 18:49 Edited at: 29th Mar 2019 18:51
This convoluted mess seems to be working for now.

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Mar 2019 19:25 Edited at: 29th Mar 2019 19:30
Like the browse folder dialog, a tree structure?

Attachments

Login to view attachments
Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 30th Mar 2019 01:42 Edited at: 30th Mar 2019 01:49
hey Blink!!

Yes, that is pretty much the idea. I can add them fine, since I limit the additions to just one folder at a time. I was able to delete them, but apparently can only delete 2-3 levels at a time or I hit an array out of bounds error.

I am too tired to see if its something simple, or as I suspect I need a recursive function not an iteration.

Please see my video, I have a few bugs with the sprite movement while dragging the cursor you can ignore( I am too tired to work it out), but you can see where I try to delete too many child folders at once and it errors out. Again, I haven't really hunted for it. Calling it a night.


edit: oh wow... it didn't show the bug lol.... Well the program crashed with an array out of bounds at the end. You can't see the notification box.

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 30th Mar 2019 08:35
I am thinking this might work (Think of groups as folders);


So it works like this
parent Points to the index of the parent group in the groups table
name Is the name of the group (Folder name)
active Tells us that the group is either active or deleted (You cannot physically remove something from the groups table because it will corrupt the pointers). You could have a table of inactive groups that you re-use
entry Is an array of each entry in the group (Files/folders in the folder)

An entry can contain the name of a nuclear element (or filename) or the name of a group (or folder) . A group name is followed by the "|" character and a number which is the index of the group in the groups table for this group (This simulates recursion). You could use GetStringToken() to extract it

Technically you should never find an inactive group because you would traverse the table from the first entry and if an entry was deleted you would remove the parent reference as well



Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 30th Mar 2019 18:19
Thank, Blink0K. That was/is my algorithm. My code to identify duplicates was off. I also found that the .reverse() array command does not work. Or, at least, it does not reverse the order, as I assumed. Whatever it does it looks like a mess.

Login to post a reply

Server time is: 2024-11-23 02:04:13
Your offset time is: 2024-11-23 02:04:13