I need some help with variable.
I would like to use the value of a variable as a list’s name to be able to modify it.
For example : i have two players and i need to change the amount of colored balls owned by the players. Each player has a dedicated button. Same for each ball. And when i click on one of these it changes by 1 the amount of ball of the selected player.
For each player i create a list with item 1 = name, item 2 = number of red ball, item 3 = number of green ball, etc.
First, i select the player.
Then i click on a ball’s button to change the number by 1.
Right now, i can do this by using “if…do” control. But there are too many as the number of player increase and slow down the app.
My wish is to set a variable in the name of player’s list when i select a player.
Then, when i click to modify the amount of ball, call that variable as the list’s name.
Below the blocks of what i have in mind. As it is, it does’nt work.
Maybe i am misusing the variables. I will appreciate any help.
Thank your for your time.
But for hierarchial data (properties with properties, lists of list, etc.) JSON objects are the way to go. Here is one (of many ) example on how to read and create JSON hierarchies.
I’m all about JSON, so if you search for my name and JSON in the list, you will find a lot of examples. Many of the examples cover WebAPI calls, but they will show the techniques for looping thrrough data, checking for values, sorting, filtering, etc.
Not sure if I used it right but I managed to make it work.
It’s like copying to a temporary list, the initial list you want to modify.
I just have to “recopy” the temporary list to the initial one at the end. Correct ?
JSON is the probably the fastest way to do this. Just to add… what you’re really considering is the difference between an “array” and a “record” in programming. An array typically stores one type of value such as scores for each player, while a record stores different types of values (e.g. name, ID, score).
In Thunkable, lists can hold array data but for records like you’re wanting, it’s usually best to use a data source. You can create a blank data source in Thunkable and give the columns the titles you need (name, red number, green number, etc.) and then use the Data Source blocks to get and update the data.