Sounds like something I do every day. Here are two that I use in most situations.
Method 1: Link List:
Each element stores its parent ID, and each parent stores its first child; and each child stores its next sibling.
Room(1).FirstTrigger = 1
Trigger(1).Room = 1
Trigger(1).NextTrigger = 2
Trigger(2).PreviousTrigger = 1
Trigger(2).Room = 1
Action(100).Trigger = 2
Trigger(2).FirstAction = 100
And so on. Use functions to make shortcuts.
Method 2: Matrix1 Raw Memory
Yeah I know it seems a bit low-level, but it is fast and I use functions to make it easy to use. This is the method I use 90% of the time.
List = Trigger(1).List = Memory Address
(They are the same)
FirstAction = ListItem(List,1) = Peek Integer( List )
ThirdAction = ListItem(List,3) = Peek Integer( List + (3 * 4) )
The parent relation is stored in the UDT.
Action(FirstAction).Trigger = 1
Again helper functions are created for shortcuts such as:
ListCount() = (Memory Size(Address) / 4)
ClearItems() = Free Address
Adding a new item requires a change of memory address, if you want do not want a static list.
List = AddListItem( List, 1234 ) [List memory address will change)
The above is achieved with the following, where tuple is the phrase used instead of list:
//==================================================
Function AddTupleInt( tpl, iVal )
n = Memory Size( tpl ) / 4 ` I use a check for zero value aswell
If n => 0
b = Alloc Zeroed( (n * 4) + 8 )
Copy Memory b, tpl, (n * 4) + 4
Poke Integer b + (n * 4) + 4, iVal
tpl = b
Else
If tpl <> 0 Then Free tpl
tpl = Alloc Zeroed( 4 )
Poke Integer tpl, iVal
Endif
EndFunction tpl
Addresses change when the list/tuple is resized. For this reasons, I also store lists in a reference array; so lists can be accessed by reference rather than by value.
Lists( Triggers(1).Actions ) = AddListItem( Triggers(1).Actions, 1234 )
OR
AddItemToList( Triggers(1).Actions, 1234 )
Iteration is done using Peek commands or a helper function: GetItem( address, index ) | GetListItem( list, index )
Again this is a simplified example of what I am doing.