AGS Editor

Further development of AGS Editor

Bug Issue: "Switch" statement does not work with strings

Pages: [1]

Crimson Wizard

  • AGSer
  • Posts: 7,430
« on: 28 Jan 2017, 19:18 »
New script statement "switch" does not work with strings. It seem not to work at all, not comparing properly with string value, nor string pointer:

Code: Adventure Game Studio
  1. String string_test = "test";
  2. switch (string_test) {
  3.     case "test":
  4.       Display("1");
  5.       break;
  6.     case string_test:
  7.       Display("2");
  8.       break;
  9.     default:
  10.       Display("-1");
  11.       break;
  12.   }
  13.  
Above script always displays "-1".

Radiant

  • AGSer
  • Posts: 5,099
  • Return once more to the Two Kingdoms!
« Reply #1 on: 28 Jan 2017, 20:13 »
To be fair, switch doesn't work with strings either in C / C++, so it's not particularly expected to do so in AGS either.

Crimson Wizard

  • AGSer
  • Posts: 7,430
« Reply #2 on: 28 Jan 2017, 22:13 »
To be fair, switch doesn't work with strings either in C / C++, so it's not particularly expected to do so in AGS either.

Strings were claimed to work by the feature author. They worked before, in beta versions, and I added this information to the manual. But they don't work in the latest version, and we already have a user report about that.
« Last Edit: 28 Jan 2017, 22:34 by Crimson Wizard »

Crimson Wizard

  • AGSer
  • Posts: 7,430
« Reply #3 on: 28 Jan 2017, 23:58 »
Update: change is caused by commit 8407af2cb10aca37eda762e7a98f05b7bd4eccc b

Before: strings were compared by value.
After: strings seem to be compared by reference.
« Last Edit: 29 Jan 2017, 00:11 by Crimson Wizard »

Issue updated by Crimson Wizard
« Reply #4 on: 18 Mar 2017, 23:21 »
  • Status changed from New to Resolved
  • Fixed Version changed from (none) to AGS 3.4.1

Radiant

  • AGSer
  • Posts: 5,099
  • Return once more to the Two Kingdoms!
« Reply #5 on: 19 Mar 2017, 21:22 »
But that's odd because in your above example, comparing string_test to string_test yields false.

Crimson Wizard

  • AGSer
  • Posts: 7,430
« Reply #6 on: 19 Mar 2017, 21:43 »
But that's odd because in your above example, comparing string_test to string_test yields false.
There is another bug that local variables do not work in switch:
https://github.com/adventuregamestudio/ags/issues/387

Pages: [1]

Issue Details

  • Reported
    28 Jan 2017, 19:18
  • Updated
    19 Mar 2017, 21:43
  • View Status
    Public
  • Type
    Bug
  • Status
    Resolved
  • Priority
    Normal
  • Version
    AGS 3.4.0
  • Fixed in
    AGS 3.4.1
  • Assigned to
    (none)
  • Category
    (none)

Tags



Powered by: SMF Project Tools 0.5.4 © Niko Pahajoki 2007-2011