Announcement

Collapse
No announcement yet.

Switch w/ String Not Working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Switch w/ String Not Working

    Hi Everyone,

    This string split function doesn't appear to be working properly:
    Code:
        `Log(parts[0]);
        switch(parts[0]){
            case "initclient":
                //send challenge response
                SendText(ClientInfo);
                break;
            case "assignzone":
               `Log("Assigning zone "$parts[1]);
                ZoneId=int(parts[1]);
                break;
            case "kickclient":
                //we need to kick the client with the character ID specified
                break;
            case "saveplayersandexit":
                `Log("Saving players and exiting...");
                SafeExit();
                break;
    The code prints:
    saveplayersandexit
    Which is therefore the value of parts[0]. But it does not then afterward print "Saving players and exiting", indicating that that case is never called.

    What's wrong here?
    parts is an array<String>

    #2
    bump - please answer

    Comment


      #3
      Congratulations, you've found a bug in UDK unrealscript runtime.

      I replicated your scenario as you posted. It looks like when you use parts[0] then switch against that, it's not returning a properly typed string for the runtime to compare against correctly. I'm guessing it's casting it to something that it can't be, and then it's becoming "none". So, you can workaround this issue by assigning parts[0] to a string variable first then switching against that. Consider the following...

      Code:
      local array<String> test;
      local String testTmp;
      
      test[0] = "ImaValue";
      testTmp = test[0]; // You need to do this first
      
      // Then switch against your temporary string
      switch (testTmp)
      {
      	case "ImaValue":
      		WorldInfo.Game.Broadcast (self, "WAS ImaValue");
      		break;
      	case "ImAnotherValue":
      		WorldInfo.Game.Broadcast (self, "WAS ImAnotherValue");
      		break;
      	default:
      		WorldInfo.Game.Broadcast (self, "WAS NOTHING");
      		break;
      }
      I hope this helps.

      EDIT: Also, you should ALWAYS have a default case which asserts (false) when something should never happen, or at the least print out an error message to the log. You would have been able to catch this error if you did, because you would realize the comparison isn't matching correctly and it's jumping down to the default case.

      Comment


        #4
        Ha! I thought that was weird.

        Yeah, I was going to make a default case. I thought the issue was maybe a space before or after the command, all resolved now.

        +1

        Comment

        Working...
        X