Could someone help me with this code?

Hello!

I’m fairly new here and am planning on having a homebrew campaign on astral soon. For that, I was trying to implement the dice rolls with the ranges of “Extreme”, “Good Success” and so forth, but am having difficulties on doing so.

My code follows:

| Roll| dado= !(1d20)
|Results| { dado == 20 and (Int/2+1== 4) ? “Sucesso Bom” : (dado == 19 and (Int/2+1 ==4) ? “Sucesso Normal” : (dado <= 18 and dado >= 10 and (Int/2+1 ==4) ? “Fracasso” : (dado <10 and dado >= 4 and (Int/2+1 == 4) ? “Fracasso Extremo” : “Desastre Total”) )) }|

Could someone point me out where I’m getting it wrong?

The die rolls, but only the “Failure” message appears, so I’m thinking the ternary coding is not well implemented on my part.

Any tips would be appreciated.

Thanks in advance!

Hi,
I think the issue here is that you are trying to store a dice roll on a variable (dado in your case). You can nest IF conditions but you will need to do like:
{!((1d20) == 20 and (Int:2 +1 == 4)) ? …

1 Like

Astral does not currently allow assignment of values. The Feature Request {lastRoll} would solve this problem however.

2 Likes

@athrepos here you go:

| Roll| {dado = !(1d20)}
|Results| {((dado == 20) and (Int/2+1 == 4)) ? “Sucesso Bom” : ((dado == 19) and (Int/2+1 == 4)) ? “Sucesso Normal” : ((dado <= 18) and (dado >= 10) and (Int/2+1 == 4)) ? “Fracasso” : ((dado <10) and (dado >= 4) and (Int/2+1 == 4)) ? “Fracasso Extremo” : “Desastre Total”}

If you use this from an action in your PG sheet / Stat block where the variable “Int” is declared, it should work. At least it worked for me in the chat (replacing Int/2+1 with a number).

Weird thing is that I was receiving an error because I was copying and paste from my txt edit app and the quotation marks were copied in a wrong way. So make sure you write them directly on Astral.

G.

PS: it seems that now it is possible to store a dice roll in a variable (not lasting forever)