The RPG Engine

The RPG Engine

Nested IFs in the reference API
I am trying to create a D&D like attribute-modifier points in a character sheet. The roll API accept nested ifs, so it would be possible to create a table-like entry like the following:

IF(A>=18,4,IF(A>=17,3,IF(A>=15,2,IF(A>=13,1),IF(A<=3,-4,IF(A<=4,-3,IF(A<=6,-2,IF(A<=8,-1,0)))))))

However, the reference input-box won't accept this formula -- it will accept only one IF. This seems to be unintended, or possibly a bug. I can get around this limitation by having the players enter their modifier automatically, but it would be nice to have the same capabilities in the roll API and the reference formula box.
< >
Showing 1-2 of 2 comments
Looks like WITH works:

with(A, if(it>=18,4,if(it>=17,3,if(it>=15,2,if(it>=13,1,if(it<=3,-4,if(it<=4,-3,if(it<=6,-2,if(it<=8,-1,0)))))))))

It seems like IF at top-level is not recognised by the reference script interface. I am happy to use with() in front of the IF chain, but being unable to nest IFs in the reference formula (while nested ifs are accepted in the roll API) is a bit counterintuitive.
Apr 17, 2024 @ 3:34am 
Thanks, We'll take a look at this
< >
Showing 1-2 of 2 comments
Per page: 1530 50