Look up AirTable reference and return most recent item

lex.langebuhqe
Sat, 26 Dec 2020 15:05:36 +0000
Questions about Thunkable

Hi,

[Note: I initially included 6 screenshots to show what I was talking about, but I’m limited to 3 as a new forum poster. Hopefully I can report in replies later…]

I have been making a game with Thunkable X in which people are able to claim and capture hexes. I have set up an AirTable to record a list of hexes and who owns them, with columns called Hex ID (for the selected sprite), Row (for the internal _id number assigned by AirTable) and Owner (for the currently controlling player).

(Image 1 - the AirTable columns)

I used a tutorial to find the hidden AirTable Row ID reference and record that as a column to register each hex when I select it…

(Image 2 - app showing code for finding and recording AirTable row ID in a column in AirTable)
(This works fine)

When I select a hex, I can get it to display the current hex (first string of numbers/letters in screenshot below), then use this to look up the Row ID in AirTable to display it (second string in screenshot below, all starting with ‘rec’):

(Image 3 - screenshot of app preview, showing two Labels: 1 - Thunkable-assigned ID for current hex sprite / 2 - Row ID of AirTable row with the hex sprite ID listed in it)

With the most recent Row ID for the AirTable, I can then look up other columns and cells in the AirTable, using this as a reference (e.g. to look up the current owner of the hex).

If it is the first time the hex is selected, it displays the Row ID no problem and I can carry on with the program, but…

The problem is if the hex has been clicked previously (e.g. claimed by somebody else or logged earlier), that hex is referred to on more than one row. In this case, the Row ID call from AirTable lists every Row ID that the current hex has ever been referred to in, returning them as a long, comma-separated list, all starting with ‘rec’ (sorry that you can only see a couple of the screenshot, but there are 5 showing on my test phone):

The problem with this is that I can’t then use this to look anything up. For the game, I do want to be able keep and see previous listings for the hex (to see changes of ownership etc.), but I just want to be able to call up the most recent Row ID only so that I can then use this to find other cells.

(The same hex is in this list 5 times, but I only want the most recent ID)

I have found numerous helpful YouTube and Thunkable Community posts that have helped me to get this far, but I can’t seem to get the last roadblock out of the way, since most of these are happy to return a list, when I only want the last value.

This is my code as it stands:

This code works to return the Row ID for the currently selected hex, but unfortunately returns the ID of every row for that hex as a comma-separated list.

When I try to use Lists commands to find the Last in the list, it seems to break it and either return nothing or a single-digit number (the same number for whichever hex I select), so I think I’m doing that wrong.

Desired outcome:

When Function ‘Get Current Row ID’ is run, set variable TempHexRowID (and/or label Label_HexRowID_Hidden) to the most recent Row ID.

Return the most recent Row ID for the selected hex as the outcome for the Function called Get Current Row ID

Any help appreciated! I am so impressed at this community, having done a lot of reading on it recently, as well as back in the day from previous projects (I cam over from App Inventor when Thunkable was new). I hope this makes sense and that somebody is able to help!

12 posts - 4 participants