How can I access one particular data from array?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Suleymanov

I store multiple data in a variable called “data”:

data = {
"Lap Time" : newBest, 
"Player" : userName, 
"Circuit" : int(get_tree().current_scene.name.right(6))
}

My question is, how do I check each data?

Say, I want to check “Lap Time”, can you please show me an example how it can be called/accessed?

Thank you for your time!

Never mind, got it.

data["Circuit"]

Suleymanov | 2021-07-18 09:10

:bust_in_silhouette: Reply From: MxtApps

As you can see in the godot’s dictionary documentation, you should get the value of the dictionary object and if it returns null, it does not exists.
If it exists, then you can check its value with the same function or with data["Lap Time"]
An example:

if(data.get("Lap Time") != null):
   print("Lap Time exists and its value is %s", data.get("Lap Time"));
else:
   print("Lap time doesn't exists");

I hope this will be useful for you.
MxtApps :slight_smile: