Skip to main content

Hi, guys,


I want to implement something like this:


Starting point: “🇺🇸” → “🇪🇸” → “🇵🇱” and back to “🇺🇸” (it must work like a loop where clicking it changes to the next flag).


However, I am facing a problem with the “ifs” in prototyping. When I try to click on the icon, it changes until the Polish flag, and after that, I expect to receive a USA flag as it was at the start. Instead, I have the Spain flag again. Why is this happening?


I implemented it in the following way:



Thank you in advance 🙂

Hi @vbaisha


The problem


When the polish flag is displayed and you click on it, here’s what happening :



  1. it goes for your first condition and it checked if #test is equal to “🇵🇱”. At this time it’s true so #test is assigned the value “🇺🇸”

  2. then it goes for the second condition. #test isn’t equal to “🇪🇸” so nothing happen.

  3. For the last condition, #test does contain the value “🇺🇸” so it enter the condition and set #test to “🇪🇸”.


A solution


You want this logic to only be able to set the #test variable once per run.

Create a boolean variable #quit set to false



  1. before your first condition set #quit to false

    image

  2. add the following logic to all conditions : and #quit == False as shown bellow

    image

  3. inside all condition, after #test is set, change the value of #quit to true

    image


Adding the #quit boolean, ensure that #test can only set once per click.

If we take a look at the problem again : You’ll enter first condition and change:



  • #test from “🇵🇱” to “🇺🇸” and,

  • #quit to true.


When the third condition will be check, #test will be equal to 🇺🇸 but #quit won’t be equal to false so it won’t enter the condition.


Hope it helped!


Thank you so much, ultimately I got it 😃


Reply