Using database query results for calculations and database update

Godot Version

4.2.1

Question

I am able to write to my database (SQLite), query my database, and pull in the data from the database… I can print the results of the query.

My question is, "How do I pull a specific element from the query result (the query uses a (select_rows) query… here are the results I receive:
[{ “count”: 32 }]

The database table has a field named ‘count’ which holds the quantity of that specific inventory item that the player has…

I want to use the ‘count’ value (32 in this case) to add or subtract from the count based on another field…

Everything works, except I do not know how to pull the ‘32’ from the database query results as a variable that Ii can then use in a calculation before updating the database with the new value.

Any help would greatly appreaciated.

If I understand your question right, result[0]["count"] should work, no?

Assuming you saved this:

to a variable result at least.

here is the line where i pull the data…

var query_results = database.select_rows(“player_inventory”, “player_item = '” + item_to_update + “'”, [“count”])

so, yes, I have the results set to a variable “query_results”

In essence query_results = [{ “count”: 32 }] (is this an array or a dictionary… I guess that is where I cam confused???)

So, how would use the value for “count” (32 in this case) in a formula… how do I pull just the value? It’s probably so simple I’m missing it…

Ok, after more carefully reading your initial response, I was able to get it to work.

Thank you so much for the help!