Switch statement

Started by m0rph84, Tue 28/02/2017 22:40:10

Previous topic - Next topic

m0rph84

Hello,
someone could tell me what's wrong with this Switch statement/call function:

Code: ags


function bad_Inventory_use(String objcase)
{

  switch(objcase)
  {
    case "cloud":
        .... //do something
        break;

    case "sun":
        ...... //do something
        break;

    default:
       ..... //do something else
  }


and I call it with:

Code: ags


function oCloud_UseInv()
{
  bad_Inventory_use("cloud");
}



but it always execute the default case....I tried to put a Display("%s",objcase) in the default case
to check the value of objcase and it returns "cloud" as it should be.


Khris

According to the AGS release thread:
Quote- Strings do not work with switch/case script commands as intended. They were supposed to be compared by value, but are instead compared as pointers. This worked in some early BETA versions, but was broken at some point. This hopefully will be fixed in one of the future updates.

m0rph84


Crimson Wizard

Yeah, that was an unfortunate oversight, but Gurok fixed this for future version (3.4.1). At the moment you should be using "if/else if" with strings.

m0rph84

Ok, not a problem at all.

Thanks again!

SMF spam blocked by CleanTalk