I have a quiz game with over 1000 questions. I am implementing a new level screen and each level will have 20 questions meaning I will need 50 level buttons. So when level1 is clicked, it loads first 20 questions.
The challenge I have is I will have to create blocks for each levels. So wondering if is there no simple way of saying, IF button1 is clicked, Do this, ELSEIF button2 is clicked, DO this, etc.
Right now am having to do this meaning I will need 50 of that:
Does each level have a different screen? It would be more efficient to have 1 button that plays the sound and just change the data on screen via local db, or firebase if thats your thing
You could have 1 screen that when the button is clicked, records the answers in local db, then changes the bales and text inputs etc on screen to show different text, retrieved from the local db.
You should instead have a variable âlevelâ which would go from 1 to 50.
And each of the level button would call the same general question handling function, passing the parameter 'button_clicked" as argument, which will be 1 for Level1_Button to 20 for Level20_button.
And that function you called would combine the level value (i.e. (level -1)*20 ) with the button argument passed to derive the question ID which can then range from 1 to 1000.
Then, you know what question/answer set to access, since that is the index of your quiz game reference database.
No need for an extremely tedious bunch of âifâ âelse ifââŚ
Ignore the playbutton sound, the issue I am talking about is each level loading 20 different questions. How would you use the blocks so you donât have to have 50 âwhen buttonxxx is clickedâ
Why do you need 50 buttons to start with?
You could have 10 only (1 to 10), and relabel them by adding 10*n to the caption, where n is the âpageâ of the level.
That way, each button serves multiple times. You only need to manage the fact that when clicking button 1, it means clicking 11, 21, 31, or 41 depending on the âpageâ, no?
This is a level based game, so when you click on level 1, it loads questions 1 to 20 and after you completed Q20, it takes you back to game level to click on level 2 which then loads Q21-Q40 and so on.
So all I am asking is, is there no way to code all button clicks with a single event and each event loads its corresponding questions.
Another way of explaining this is if we had a block that says âWhen button 1 is clickedâ, then do XYZ ELSEIF when button 2 is click, then do XYZ. This way all the code are in an IFELSE statement rather than having different blocks for button click separate
Each button is defined as an area. A zone bounded by 4 corners, in terms of X,Y coordinates.
The operating system monitors the activity and when it detects a click somewhere, searches through the list of all the zones defined as valid buttons. When there is a match (the zone touched has its X coordinate bigger than X1, smaller than X2; and the Y is between Y1 and Y2? Then, user touched buttonA) the system creates an event, a signal that the thunkable program receives as âuser has clicked buttonAâ.
What this means is that there ISNâT an event that says âuser has clicked a button, and it happens to be buttonAâ where the button value is passed as a parameter.
You can create something that will be a close enough approximation, by having ALL the buttons click events call the same procedure, but with a different argument (i.e. button1 will call âbuttonclicked(1)â and button2 will call âbuttonclicked(2)â)
You will STILL need to have as many events has you have buttons.
But your âbuttonclicked(buttonid)â function would work just like this block that you envision.
One way of having the sort of thing you describe would be to use canvas (it does not exist in X thunkable, but I implement exactly that in one of my thunkable classic app) to cover the WHOLE area, and to use the âtouchdown(x,y)â event. Finding out which specific button was drawn at that location is then your responsibility.
In Thunkable X there is really no Canvas, but there is a Map on which you can draw markers, draw rectangles and click on them. I think it is not necessary to explain how this can be used in conjunction with the ability to determine if the point of pressing a map hits the rectangle.