2016년 11월 17일 목요일

"For each item" behavior/sequence


I have a FirebaseDB1 query that gets a list of words. When the list is received, I want to do a FirebaseDB3 query for each word in the list, to get the score of each word. For each score I get, I want to add that word to a list X times the score.

For example, if I have a list with the words APPLE and PEACH, I'll lookup the score of APPLE (2) and PEACH (3). I would end up with this list : APPLE APPLE PEACH PEACH PEACH.

However, with my current blocks, I end up with PEACH PEACH PEACH or whatever is the last word in the word list from FirebaseDB1.

What am I not understanding?

BTW, I'm trying to do a weighted randomizer so the odds of picking a word in the word list depends on the word score.

-- 
There is something strange in your when.FirebaseDB1.GotValue:
Whatever the value, you always set global var_words to an empty list
Somehow you are missing an if there.
Cheers, Ghica.

-- 
The purpose of that is to make sure I start with an empty list before doing this routine, so it looks ok from my POV. Could it be that my DB3 requests loop is so fast that the Got Value only handles the last loop? How can I make sure that DB3 waits for Got Value to finish before each new loop?

-- 
I still think it is strange that you are using multiple Firebase databases. If it works, it works, but apparently it does not. What is so difficult about making a case statement like the blocks shown here? Anyway, you could prove your hypothesis by having two global variables, one which counts your calls to GetValue and the other that counts the GotValue. You can find their values after your test with DoIt on a loose get block.
A way to postpone the call to GetValue is to do it within the GotValue event block, but you will have to iterate through your values differently than a foreach.

But the first thing I would try is to do the set ProjectBucket outside the loop (do you really have to set it, apart from maybe at initialize??
Cheers, Ghica.

-- 
I'm afraid I don't understand you block example on how it relates to my problem. I can confirm now that the For Each loops runs X times and only then will the Got Value run X times, which is bizarre I find.

-- 

I'm including the minimized code and firebase structure to give more detail on what I'm trying to do.




-- 
My block example was related to an earlier question of why you would need so many Firebase instances.
If you want further help, I need an .aia to work from.
Cheers, Ghica.


-- 
Ok I see. Well I guess I could make dynamic queries by pushing a tag variable to a single FirebaseDB1.

I'll upload my file tonight, thanks

--

Ok, here's the code, thanks



-- 
What I see is an error message each time the app starts: invalid firebase URL.
I have no time today anymore to look further. To be continued.
Cheers, Ghica.


-- 

댓글 없음:

댓글 쓰기