Evaluator not properly evaluating logic

I’m trying to build some basic logic into my app that returns a price based on a combination of user properties and donation center properties. In this case - if a user is a new user, they should get paid $100, and if a user is not a new donor, they should get paid $30 (I can probably do this with conditionals, but i’d rather do it as an equation as this will get more complicated).

In the case below, the user has donated before (as you can see, “yes” evaluates to 1), and if i click on exisint_user_incentive, I see $30. However, in the end it evaluates to $0!! What is happening??

BTW, bonus points if you can help me figure out how to use parenthesis - so for example: a + (b+c)*d

Bubble doesn’t follow standard order of operations, so you’ll need to adjust your formula to run sequentially.

So instead of: a + (b+c)*d

It needs to be: b+c*d+a

Bubble works all equations in the order they’re written in (from left to right).

So in your case, you’re multiplying a number buy 0 (current user’s has_dontated_before is No (0)), so the result will always be 0.

I believe there are some plugins that let you use parentheses, otherwise you can utilise custom states to store values, and work with those values in your final equation.

Thanks @adamhholmes , do you mind actually explaining a little bit more? If I understand correctly, if i were to translate my equation into Numbers and evaluate it from left to right as you say, it would be 30x1 + 100x0 which should be 30. I don’t completely understand why its 0.

Bubble doesn’t follow mathematical order of operations, but rather it evaluates equations in the order they’re written (from left to right)

So, in your above example, although the correct answer (following standard order of operations) should be 30, the answer Bubble will give is 0, as it evaluates from left to right…

30x1 = 30
+100 = 130
x0 = 0

Got it, so it recursively applies each operation to the results of all the operations to the left. So its ((((30)*1)+100)*0). What a funky implementation!


Note: So I rewrote it to (image below)


and it works fine now.

However, I don’t know how to do this when I might have two or more 0/1 states. For example: Let’s say if you’re over 150 pounds, I want to give you another $10. If i put the clause for weight in the beginning, it’ll be wiped out if the new user clause is false later on. Any ideas? (maybe @adamhholmes)

This topic was automatically closed after 70 days. New replies are no longer allowed.