Forums

Add shortcode method for numerical comparison

emmexx 20 Sep, 2018
Wouldn't it be useful a method to compare a variable to a number (or to a string) and use the result in a switch?

I often have to switch between a variable that is equal or greater than a value and I must to code a php function and use it or pass its result to a switch.
It would be easier if the Data Provider of switches could manage such comparisons, something like:

in read_data the format is:
id/=:{data:field}
or
id/<:{data:field}

in switch it could be:
{var:varname}/=:3
or
{var:varname}/<:7

and in Values setup:
true:some code if the condition is true
false:some code if the condition is false

maxx
healyhatman 20 Sep, 2018
That would be nice.

In the meantime one thing you could do:

Have ONE PHP action, with
switch($this->get("func", "")) {
case("function1"):
if($this->get("value", "") < 4) { return true; }
break;
so on and so forth.

Call the PHP action with {fn:my_php$value=(var:where_im_getting_the_value_from)&func=function_name_i_want}
emmexx 20 Sep, 2018

In the meantime one thing you could do:
Have ONE PHP action, with


Thank you but a switch would be way better. 🙂

For readability of the code something like (other possible syntax for this new method) the following is much better:

{var:varname} as Data provider and as Values Setup:

<=3:{error:Too low value}
between 4 and 7:{success:Good!}
>7:{success:You won!}{fn:goto_bank}
This topic is locked and no more replies can be posted.