Weird string behavior when using ?:

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

Recommended Posts

Encountered a weird behavior in string addition today on the latest SVN build:

string foo = "foo" + (true ? string("bar") : "bar");
string bar = "foo" + (false ? "bar" : string("bar"));
string foobar = "foo" + (true ? "bar" : "bar");
print(foo); // barbar
print(bar); // foobar
print(foobar); // foobar

The obviously-broken case here is the first one, which turns into "barbar". I wasn't able to reproduce this with integers or a simple script class with an opAdd method, so perhaps this is exclusive to the scriptstdstring addon?

Share on other sites

Probably not a problem with the scriptstdstring add-on but rather a specific case for registered value types.

I'll investigate it and have it fixed as soon as possible.

Share on other sites
Just ran into another string-related issue, perhaps it's related. The following never passes:

if (wButton.m_func == "scenario " + m_currentScenario.GetID())
Neither does this:

string id = m_currentScenario.GetID();
if (wButton.m_func == "scenario " + id)
But this DOES pass:

string id = "scenario " + m_currentScenario.GetID();
if (wButton.m_func == id)
Here, wButton.m_func is defined in scripts, and GetID() is a method registered by C++ with declaration "string GetID()".

This seemed to have started happening after updating the WIP SVN version (we were already using the WIP version before but we were a little behind).

Share on other sites

I've reproduced all the problems mentioned. I'll try to find the time to have them fixed at least by the end of this week.

Share on other sites

I've fixed this now in revision 2368.

All of the scenarios were caused by the same bug. A temporary variable was being overwritten when invoking overloaded operators with left-to-right evaluation. This bug was introduced in the WIP itself. Good thing you identified the problem before I released the new version. :)

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 9
• 11
• 11
• Forum Statistics

• Total Topics
631775
• Total Posts
3002279
×