[Solved] Help with numbering Firebase query

Hello, I have hit a wall with this one. What I am trying to do is basically a search within a Firebase database. Everything is working just fine, except I can’t get the number before the name/score to match up properly (See first screenshot).


For some reason, that #5 is always there no matter what name a search for. I am using a different query than the main “Leaderboard” but when I change the text of UserScoreTxt I am using a variable loaded by my main query. Could that be the problem? Here’s the events.

As always any help would be greatly appreciated, Thanks!

I’m not familiar with using Firebase, but I have a few queries about your events :

  • you are querying it in an unconditional event. Shouldn’t you at least have a trigger once on it?
  • you don’t appear to clear out FetchedData. Should it be cleared first before running the query?

But, I suspect the real issue is in the last event on the screen snip. You use the variable i, while in the “For every child…” you have i2. So the value of i is from the previous leaderboard query, whereas I think you want i2, from the current query.

Thanks for your reply MrMen!

First, if I put a trigger once condition on it, it doesn’t show up at all, which is weird because I can put a trigger once condition on the first query with no problems.

Second, I am actually storing this second query in a new variable called FetchedData2, so it should have no effect on the first query.

And last but not least, you are correct about me using the variable i instead of i2. The reason I did this, was because the numbers are actually not part of the firebase database but rather a product of changing the txt of ScoreboardTxt: add ToString(Variable(i) + 1) + ". So if I were to use variable i2 that number would always be 1 because there is only 1 result from my second query. What I was trying to do was get that number from the first query, didn’t work for me though.

Yes, I’m well aware of that.

To be sure I understand you’re problem, is it the “5” in the top right? If so, what value should it be?

image

If so, it’s because you are using ToString(Variable(i)) in that second query. At the end of the first leaderboard query, i is 5. You output i+1 to the leaderboard list, and as the last output number is 6, it means i must be 5.

But let me know if I’ve got the wrong handle on your query.


[edit]

Or do you want the number 5 to be the actual leaderboard position of the name + score combination? In that case, you should use the results of the initial query (it’ll be a structure), and find the key for the name & score combo. Then use key value + 1 as the position number.

Yes! This is what I am trying to do. What do you mean by find the key?

A structure is made up of key-value pairs (like a dictionary in other programming languages).

In your case, what you refer to as "i" is the key, and value is data (from the doc.data, which holds child elements score & name).


From the events you’ve listed, I suspect your FetchedData variable is structured roughly like :

image

(I’ve circled the key values)


In which case change the first query result events to :


and get rid of the second firebase query and it’s related events.

1 Like

You rock MrMen! That worked perfectly. Thank you for taking the time to help.