I am trying to get the value of child “TimeTaken” of structure TrackInfo.
Here is how I try to get it:
TrackInfo: “{"FinalPos":10,"PlayerPos":{"A1":7},"TimeTaken":89.49269913073026,"TrackName":"Tutorial"}”
The problem is, It returns zero.
I am trying to get the value of child “TimeTaken” of structure TrackInfo.
Here is how I try to get it:
TrackInfo: “{"FinalPos":10,"PlayerPos":{"A1":7},"TimeTaken":89.49269913073026,"TrackName":"Tutorial"}”
The problem is, It returns zero.
Not sure i’m reading it correctly, but what is the goal in logging timetaken as a json? If you have the correct child, wouldn’t you just log ToString(Trackinfo.TimeTaken)?
It was one of my attempts to solve the problem.
Using your way:
Using your way without ToString():
Just trying to wrap my head around this. Is TrackInfo a global variable and is TimeTaken defined as a number?
I replicated your array and this code correctly updated my log with the random number assigned to trackinfo.timetaken
I think my array being in this form when converted ToJson is the problem.
Here is how it looks like:
{"1":"{\"TimeTaken\":0}","2":"{\"TimeTaken\":0,\"TrackName\":0}"}
You’ve mistyped “TrackInfo” - you’ve got it with a lowercase “i”, when it should be capitalised. The error message below the red squiggly line should explain it.
That’s an array. You won’t be able to access it using TrackInfo[“…”]. The value in the square brackets needs to be the index, which is a number. Structures are accessed using keys, which are usually strings.
Can you provide a screen snip of the events that populate TrackInfo, or where it is defined?
Yes, but playerpos is an array
I can’t, I get the structure from storage event.
How did that slip from my eyes’ attention…
It’s supposed to be a structure.
Oh no, maybe the events saving the structure to storage are not doing it correct.
The scene that loads the structure is called Menu,
The scene that saves is called Finish.
Fills in info to structure:
Saves info to storage:
Why have you blurred out some of the events? Can you repost the screen snip without the redaction?
What are the parent events of the first screen snip?
What does the variable TracksCode contain?
Where is TrackDesc defined, and what is it - an array or a structure?
Because it has nothing to do with my problem.
These are the full events:
The parent of these events is an event with a condition:
At The beginning of the scene.
All tracks (or also called levels) in this game are defined by 2 Global Arrays.
TracksCode and TracksDesc.
TracksCode contains the code for each track.
TracksDesc contains the title and description for each track.
Their contents:
I think you asked this because you want to know what am I trying to do here:
Simply, I am checking if the track that the player just finished is an official track of the game or is it a custom track.
If it is, use the name instead of code to refer to the track.
Like here:
A few posts back you had this action:
That’s not in the unblurred screen snip. What are the events around that?
Where do you read the results from storage? You’ve provided the save to storage, but not the read.
And have you checked the information in storage, to check how it’s saved?
The screen snip you are talking about is one of the events that load tracksinfo. They are in a scene called menu. The screen snips I sent are about saving tracksinfo into storage. I am loading the storage into tracksinfo before checking the value.
I think the issue is with the loading actions - they’re missing one vital step. In this event:
the results are stored into TrackInfo. This is a text variable, not a structure. So when you access “TrackInfo["TimeTake"]
”, it returns 0 because it doesn’t exist.
You need to convert the JSON in the text variable into a structure using the Parse JSON string
action. There’s an explanation on storage save and load in this post.