Calculation with IF ..and.. statement

joba

New Member
(int)$spoints=0;
if((int){fs_event_01_Registered_raw} = 30) and (int){fs_Event_01distance2_raw} = 80) {(int)$spoints = 70};
return (int){fs_event_01___distance2_raw}+{fs_event_01___Registered_raw}+$spoints;

Please help me identify what is wrong with syntax - it does not give me any result.
 
Try it:
PHP:
if((int)'{fs_event_01_Registered_raw}' = 30 and (int)'{fs_Event_01distance2_raw}' = 80){
(int)$spoints = 70;
return (int)'{fs_event_01___distance2_raw}'+'{fs_event_01___Registered_raw}'+$spoints;
}
 
Yes, placeholders should be quoted.
But additionally:
IF needs == (not =) and I don't think (int)$somevar = ... is valid
Code:
if((int)'{fs_event_01_Registered_raw}' == 30 && (int)'{fs_Event_01distance2_raw}' == 80){
$spoints = 70;
return (int)'{fs_event_01___distance2_raw}'+'{fs_event_01___Registered_raw}'+$spoints;
}
And what should happen if not?
 
Thanks for the quick response! I tried it but the moment when I add the IF statement, it does not return any value. It shows that it is calculating.
Yes, placeholders should be quoted.
But additionally:
IF needs == (not =) and I don't think (int)$somevar = ... is valid
Code:
if((int)'{fs_event_01_Registered_raw}' == 30 && (int)'{fs_Event_01distance2_raw}' == 80){
$spoints = 70;
return (int)'{fs_event_01___distance2_raw}'+'{fs_event_01___Registered_raw}'+$spoints;
}
And what should happen if not?

Nothing should happen if not!

I tried all of it - It looks to me as if the "if" command is not understood. I loaded the element-calc extension. Is there maybe something else to load?
 
You may try to check your returned values from elements '{fs_event_01_Registered_raw}' and '{fs_Event_01distance2_raw}'.
I think the best way to code is that:
PHP:
$ev_reg = '{fs_event_01_Registered_raw}';
$ev_dist = '{fs_Event_01distance2_raw}';

//check values
return 'ev_reg='. $ev_reg . ', ev_dist=' . $ev_dist;
if($ev_reg == 30 && $ev_dist == 80){
$spoints = 70;
return ($ev_dist + $ev_reg + $spoints);
}
else {
return 'false';
}
 
Just FYI, best to just return an empty string ...

PHP:
return '';

... for a "don't return anything", as 'false' isn't really a displayable value, and in some circumstances could render as 0 rather than nothing.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top