pgimeno wrote: ↑Mon Apr 19, 2021 5:07 pm
There isn't a direct route. At best, you can make a function to do this kind of access, but it's not the path I'd recommend to follow:
I'd advise you to look for alternatives. It's not immediately clear what your plans are, so I can't suggest any.
Hey, thanks a bunch this was very useful. Also thanks grump.
I'm now realizing that a "nested" table setter is something that I need as well (this seems 10x more confusing to do). Let me provide some explanation of what I'm attempting as to hopefully get some more clear direction on what to do.
My application takes in json that defines basics of "objects" in my app. This JSON is converted to a table, and then the code is highly generic code for handling some of these table values. Let me give an example here.
Code: Select all
{
"object": {
"width": 32,
"height": 32,
"position": {
"x": 128,
"y": 128
},
"movement": {
"vvel": 0,
"hvel": 0,
"hspd": 4,
"vspd": 4
},
"held": {
"up": {"movement.vvel": -1},
"down": {"movement.vvel": 1},
"left": {"movement.hvel": -1},
"right": {"movement.hvel": 1}
}
}
}
I just stripped a lot of values from the JSON above, so hopefully I haven't botched the syntax.
Anyhow, the main thing to focus on is the "held" table. I have designed a few tables that my code deals with for key press, hold, and release. They work fine but the problem I'm having is using them to set nested values. As seen above I am trying to set values in the tables movement sub table. This is a string I would like to handle in my games logic that parses through to my table above's specified value and sets it.
It works fine when say modifying the width that isn't in a sub table. Once I get to this nested issue it becomes quite nasty to deal with.
This might be different enough from the original topic to warrant a new topic, but i'll post here first.