[Bug 1.126] - Parsing of Exponents doesn't respect parentheses

The way that the game parses exponents is incorrect. They incorrectly include the previous term of the equation even through parentheses.

Equations like: 0+(0.5x^2) are processed as if they were: 0+(0.5x)^2
Same with addition: 0+(0.5+x^2) is processed as if it was: 0+(0.5+x)^2
Parentheses: 0+(0.5+(x^2)) is processed as if it was: 0+(0.5+x)^2

Take this example policy:

#,Test_1,default,0,0,0,0,FOREIGNPOLICY,20,200,0+(1.0x),0,0,500,0+(1.0x),#Effects,“Patriot,0.5+(0x)","Capitalist,0+(0.5x^2)”,“StateEmployees,0+(0.5*(x^2))”,“Socialist,0+(0.5x^4)","Environment,0+(0.5(x^4))”,“Conservatives,0+(0.1+(x^4))”,“Farmers,0.1+(0+(x^4))”,“Unemployment,(x^4)+0.1”,“ForeignRelations,(0.1)+x^4”,“BusinessConfidence,(0.1)+(x^4)”,“Environmentalist,0+(0.840896415254*(x^4))”,“Corruption,0+(-0.1591+(x^4))”

The first 5 terms should all be equal to 0.5 when x = 1 as shown in this graph:

But this is not the case in the game: (look at Patriot though The Environment)

The next 5 show that the same is true for addition as well. They should all be equal to 1.1 when x=1:

But that is still not the case: (look at Conservatives though Business Confidence)

This issue also causes innocent lines like:
-0.1+(-0.5*x^0.5)

to crash the game as it incorrectly causes a root of a negative number.
(As seen in my previous post:[Bug 1.126] - Game crash when multiplying an exponent with a negative number )

Also incidentally adding both before AND after the exponent also causes a crash:

(0+(x^4))+0.1

I’m guessing this is an unrelated separate issue.

All is not lost however! For the time being mod makers can use this workaround:

Instead of writing: 0+(0.5x^4)
Just calculate and use the appropriate root of the constant that you want: 0+(0.840896415254
(x^4))

This will create an identical curve to the one you originally wanted:

And the final 2 entries show that this works in game: (Enviornmentalist and Corruption)

But please don’t let this temporary workaround stop you from fixing the bug cliffski :smile:

2 Likes

These are good suggestions! Have they been implemented?

We do not support parenthesis outside of our specific format and never have. This is definitely not a bug, its just not the way the game currently works. We may change that in future, once the game has shipped, as its super-low priority.

1 Like