Problem with if in prototyping

Hi, guys,

I want to implement something like this:

Starting point: “:us:” → “:es:” → “:poland:” and back to “:us:” (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 :slight_smile:

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 “:poland:”. At this time it’s true so #test is assigned the value “:us:
  2. then it goes for the second condition. #test isn’t equal to “:es:” so nothing happen.
  3. For the last condition, #test does contain the value “:us:” so it enter the condition and set #test to “:es:”.

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
  2. add the following logic to all conditions : and #quit == False as shown bellow
  3. inside all condition, after #test is set, change the value of #quit to true

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 “:poland:” to “:us:” and,
  • #quit to true.

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

Hope it helped!

1 Like

Thank you so much, ultimately I got it :smiley:

1 Like