Advertisement

Weird string behavior when using ?:

Started by November 28, 2016 03:31 PM
3 comments, last by WitchLord 7 years, 11 months ago
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?

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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
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).

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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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. :)

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement