PricingBlog

Is this the best way to write this formula?

  • gerson_ca-1276320386161573888

    Gerson CA

    1 year ago

    Hi I’m learning toddle by doing some projects I did when I was studying intro to python. Is this the best way to write this formula? Or is there another method?
    1276320386912485477-Screen_Shot_2024-08-22_at_18.16.18.png
  • lucasg-1276321190759108752

    Lucas G

    1 year ago

  • Wait, sorry I misread it
  • lucasg-1276321916722090025

    Lucas G

    1 year ago

    This will work, but I guess what you are asking is maybe if there’s a more condensed way of setting it up?
  • gerson_ca-1276323230893867098

    Gerson CA

    1 year ago

    Yes that’s what I’m asking, the formula is working. It’s just looks a bit overwhelming compared to the few lines I had to write in python. I think Toddle also lets you write custom code so would what be a better way to do it?
  • lucasg-1276324203057905724

    Lucas G

    1 year ago

    Not necessarily. I agree that chaining IF statements can get overwhelming pretty quickly but there are benefits to using the built-in formula editor
  • Such as taking advantage of SSR
  • Custom actions/formulas (code) will run client-side so it is possible to see flashes of text changing for example if used to render it
  • gerson_ca-1276325312417759376

    Gerson CA

    1 year ago

    Im sorry im very new to Toddle, what is the SSR?
  • lucasg-1276325312602574899

    Lucas G

    1 year ago

    Something you can do is 'take out' repeating parts of the formula and have them be their own formula with their own inputs
  • This can help tame some of the larger formulas
  • lucasg-1276325392659255367

    Lucas G

    1 year ago

    Server-side rendering
  • lucasg-1276325703368835094

    Lucas G

    1 year ago

    It's not particular to toddle, but rather a way to put together a page before displaying it. SSR is good and not every builder does it so you'll want to take advantage of it when possible
  • lucasg-1276326036631584779

    Lucas G

    1 year ago

    In this case, your AND nodes could be their own formula for example, where the 2nd numbers that the variable is being compared to can be inputs for the formula
  • Then you'd have 1 node there instead of the small AND branch
  • Does that make sense?
  • gerson_ca-1276327472081797253

    Gerson CA

    1 year ago

    So you’re saying I could make a formula for comparing greater AND less than. Which then I could call with the if statements?
  • lucasg-1276327555770613871

    Lucas G

    1 year ago

    Correct
  • You’d give it inputs so you can reuse it
  • gerson_ca-1276328735938842706

    Gerson CA

    1 year ago

    Wait how do I give it inputs to reuse it?
  • lucasg-1276330310996594719

    Lucas G

    1 year ago

    On the left where you name it
  • lucasg-1276330946693562420

    Lucas G

    1 year ago

    1276330946488176731-image.png
  • Something like that
  • gerson_ca-1276332064265736243

    Gerson CA

    1 year ago

    Oh I see those inputs are meant to help me build the logic of the formula right?
  • Tod-1276332066388050002

    Tod

    1 year ago

    Great energy @Gerson CA! Your continuous contribution to the toddle Community just made you advance to Community Level 1!
  • gerson_ca-1276332267874025574

    Gerson CA

    1 year ago

    Because I just make a formula for each condition (breakfast, meal and dinner) and call them in another formula using the if noddle like this
  • 1276332340192215072-Breakfast_Formula.png
    1276332340720697374-Main.png
  • lucasg-1276337351299436627

    Lucas G

    1 year ago

    You don’t even need to make separate ones
  • If you look at the screenshot I posted, that formula has inputs on the left
  • When you then go to use that formula, you can reuse the same one for each condition
  • And use those inputs for each number you’re comparing against
  • 7 and 8, 12 and 13, etc
  • gerson_ca-1276344122298339419

    Gerson CA

    1 year ago

    Ohhhh I just did it. Thank you so much 🙌
  • gerson_ca-1276344619189141516

    Gerson CA

    1 year ago

    This means I can make a formula that will be use many times and just called it inside any other formulas
  • lucasg-1276353111195258910

    Lucas G

    1 year ago

    You got it