# Nested conditional expressions with concatenated strings - crash

This topic is 2150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello!

Apologies if this has already been brought up somewhere, but I found a crash in the scriptstdstring addon when attempting to use a concatenated string as part of a nested conditional expression. I am using Angelscript for the AI in an RTS game, and I had this to let the script show a label for the units:

string s = "Status: " +
(
(m_actionState == AS_MOVETO) ? "moving" :
(m_actionState == AS_FIRE_AT_POINT) ? "firing at point" :
(m_actionState == AS_FIRE_AT_UNIT) ? "firing at unit" :
"idle"
)
+ "\n";

... and that worked fine, so I am assuming the problem is not with the nesting of conditional expressions per se.

Next I wanted to show the current speed of movement, so I changed the "moving" part to a concatenated string like this:

string s = "Status: " +
(
(m_actionState == AS_MOVETO) ? ("moving"+10) :
(m_actionState == AS_FIRE_AT_POINT) ? "firing at point" :
(m_actionState == AS_FIRE_AT_UNIT) ? "firing at unit" :
"idle"
)
+ "\n";


...and this caused a crash in the CopyConstructString function. It appears that the 'other' parameter being given to the function is not a string. Obviously the literal 10 is not the value I really want to use, but after some experimentation I narrowed the problem down to the presence of the concatenation operator. It also crashed with concatenation of two strings.

If the branch of the conditional with the concatenation was never used (eg. no units ever entered the AS_MOVETO state), the program would run ok but random garbage characters would show for the text, and a crash would subsequently occur when releasing the asIScriptEngine object.

This is trivial to work around and is not causing me any real problems, but it seems pretty odd so I thought I would report it anyway.

##### Share on other sites

What version of AngelScript are you using? There was a bug fix related to the condition operator in the version 2.27.1.

##### Share on other sites

argh... apologies again. I was using 2.26.3 and the problem does not occur with 2.27.1 - thanks for all your hard work!!

##### Share on other sites

Thanks for the confirmation on the fix in the latest release. :)

• 13
• 18
• 29
• 11
• 27