❔ 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
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?
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
... really
I'll take that as no one knows what I'm talking about or doesn't want to help... oh well
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:
?
if this is the case, there is probably a much better way because lookup on that is cubic
just show some code
I mean, I add things to the list later on in the code, but eventually the code looks like this
which is not the most readable thing ever
$code
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/i'll be leaving soon, so I will be answering later today
when i can
alright thanks
BlazeBin - cqmytydffquh
A tool for sharing your source code with the world!
the code... is seriously a mess
these are the classes in use btw
this is unity
after talking with chatgpt for a while I noticed I didn't really do any OOP at all
yes it's unity
you failed to mention that on your post
oh crap I did?
sorry
sorry, i have little experience with it, and i prefer not to give advice
fair
are you on the unity discord?
$unity
yes I am
you can probably post in
#game-dev
also
even tho you don't know unity well, how does the code look at a glance?
a lot of bad practice right
i don't know the unity conventions, but the code is a mess
well I didn't follow any, I'm fully self taught and... well...
you can start by attempting to extract responsbilities
SpawnBus, should spawn a bus
not do 100 other things
yeah
I mean I know people say don't trust chatgpt with programming
but when it comes to the most basic level of programming
this actually reminded me to follow OOP
which I went through multiple times while trying to get the basics down
i see
try #game-dev
explain in detail
alrighty thanks for trying man
sorry for the trouble
no worries
and sorry i couldn't help
that ain't on you
this is a C# server not a unity one
yeah
but maybe someone can help you
I'll give it a shot, thanks
but I'm not too good at explaining things
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 readableBut 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
var currentBusGroup = saveData.busGroups[currentBusGroupIndex];
and u r doneHm
then instead of using
saveData.busGroups[currentBusGroupIndex]
all the time u can simply use currentBusGroup
True
That would clean up the code
But I still think triple layered lists might not be that good an idea
hmmm, will be hard to get around the nesting
I will have to try to get proper Oop in place
Instead of directly modifying values, I use functions
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.