C
C#15mo ago
Chris TCC

❔ store data like a filesystem

I'm working on an app, where the data structure is as follows: Group -> subgroup -> values The user can create groups, name them, and add subgroups inside them. The subgroups can have names too, and contain a list of int values. The app will then do some comparisons and list the smallest int value given some conditions etc. (That part isn't too important) How I currently do this is by using a triple layered list, but it is quite messy and is difficult for me to trace myself relative to the hierarchy, such as knowing when a subgroup is added etc. I use events and subscriptions to broadcast adding and removing groups/subgroups/values to the parents and grandparents, and when processing the data I use a for loop to loop through each branch of this hierarchy, comparing them with an if statement to get the value needed. Is there any more efficient way to do this? Sorry if the explanation is bad, I'm not good at doing this. I'm also fully self taught so pls be gentle with me 😅
45 Replies
Chris TCC
Chris TCC15mo ago
I've tried using chatgpt to get a general idea on what I could try as alternatives (idk how to Google this kinda question tbh) and it suggested dictionaries. Would that work in this use case?
Accord
Accord15mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Chris TCC
Chris TCC15mo ago
... really I'll take that as no one knows what I'm talking about or doesn't want to help... oh well
Henkypenky
Henkypenky15mo ago
hi, maybe the post got buried and no one saw it, another reason is that you are describing a problem which you already solved, and you are asking if it can be optimized, it may be possible, however, for that you will need to provide code, so we can get a better understanding of your program when you say triple layered list you mean a list of lists of lists? like so:
List<List<List<T>>>
List<List<List<T>>>
? if this is the case, there is probably a much better way because lookup on that is cubic just show some code
Chris TCC
Chris TCC15mo ago
I mean, I add things to the list later on in the code, but eventually the code looks like this
Chris TCC
Chris TCC15mo ago
which is not the most readable thing ever
Henkypenky
Henkypenky15mo ago
$code
MODiX
MODiX15mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Henkypenky
Henkypenky15mo ago
i'll be leaving soon, so I will be answering later today when i can
Chris TCC
Chris TCC15mo ago
alright thanks
Chris TCC
Chris TCC15mo ago
BlazeBin - cqmytydffquh
A tool for sharing your source code with the world!
Chris TCC
Chris TCC15mo ago
the code... is seriously a mess these are the classes in use btw
[System.Serializable]
public class BusGroup
{
public string name;
public GameObject panel;
public float panelHeight;
public BusGroupManagerScript busGroupManagerScript;
public List<Bus> bus = new List<Bus>();
}

[System.Serializable]
public class Bus
{
public string name;
public GameObject panel;
public float panelHeight;
public BusManagerScript busManagerScript;
public List<BusTimeslot> busTimeslot = new List<BusTimeslot>();
}

[System.Serializable]
public class BusTimeslot
{
public int inputValue;
public GameObject panel;
public BusTimeslotManagerScript busTimeslotManagerScript;
}
[System.Serializable]
public class BusGroup
{
public string name;
public GameObject panel;
public float panelHeight;
public BusGroupManagerScript busGroupManagerScript;
public List<Bus> bus = new List<Bus>();
}

[System.Serializable]
public class Bus
{
public string name;
public GameObject panel;
public float panelHeight;
public BusManagerScript busManagerScript;
public List<BusTimeslot> busTimeslot = new List<BusTimeslot>();
}

[System.Serializable]
public class BusTimeslot
{
public int inputValue;
public GameObject panel;
public BusTimeslotManagerScript busTimeslotManagerScript;
}
Henkypenky
Henkypenky15mo ago
this is unity
Chris TCC
Chris TCC15mo ago
after talking with chatgpt for a while I noticed I didn't really do any OOP at all yes it's unity
Henkypenky
Henkypenky15mo ago
you failed to mention that on your post
Chris TCC
Chris TCC15mo ago
oh crap I did? sorry
Henkypenky
Henkypenky15mo ago
sorry, i have little experience with it, and i prefer not to give advice
Chris TCC
Chris TCC15mo ago
fair
Henkypenky
Henkypenky15mo ago
are you on the unity discord? $unity
Chris TCC
Chris TCC15mo ago
yes I am
Henkypenky
Henkypenky15mo ago
you can probably post in #game-dev also
Chris TCC
Chris TCC15mo ago
even tho you don't know unity well, how does the code look at a glance? a lot of bad practice right
Henkypenky
Henkypenky15mo ago
i don't know the unity conventions, but the code is a mess
Chris TCC
Chris TCC15mo ago
well I didn't follow any, I'm fully self taught and... well...
Henkypenky
Henkypenky15mo ago
you can start by attempting to extract responsbilities SpawnBus, should spawn a bus not do 100 other things
Chris TCC
Chris TCC15mo ago
yeah I mean I know people say don't trust chatgpt with programming but when it comes to the most basic level of programming
Chris TCC
Chris TCC15mo ago
this actually reminded me to follow OOP
Chris TCC
Chris TCC15mo ago
which I went through multiple times while trying to get the basics down
Henkypenky
Henkypenky15mo ago
i see try #game-dev explain in detail
Chris TCC
Chris TCC15mo ago
alrighty thanks for trying man sorry for the trouble
Henkypenky
Henkypenky15mo ago
no worries and sorry i couldn't help
Chris TCC
Chris TCC15mo ago
that ain't on you this is a C# server not a unity one
Henkypenky
Henkypenky15mo ago
yeah but maybe someone can help you
Chris TCC
Chris TCC15mo ago
I'll give it a shot, thanks but I'm not too good at explaining things
cap5lut
cap5lut15mo ago
there is some stuff u could do to make it less messier: use local variables. eg u have dozens of saveData.busGroups[currentBusGroupIndex].blah thingies. store saveData.busGroups[currentBusGroupIndex] in a variable and it becomes much shorter. and more readable
Chris TCC
Chris TCC15mo ago
But you can't make new variables on the fly right? Each item in the list is controlled by the user The user can add or delete during runtime
cap5lut
cap5lut15mo ago
var currentBusGroup = saveData.busGroups[currentBusGroupIndex]; and u r done
Chris TCC
Chris TCC15mo ago
Hm
cap5lut
cap5lut15mo ago
then instead of using saveData.busGroups[currentBusGroupIndex] all the time u can simply use currentBusGroup
Chris TCC
Chris TCC15mo ago
True That would clean up the code But I still think triple layered lists might not be that good an idea
cap5lut
cap5lut15mo ago
hmmm, will be hard to get around the nesting
Chris TCC
Chris TCC15mo ago
I will have to try to get proper Oop in place Instead of directly modifying values, I use functions
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.