1

Today I've had majour problems with GameMakers switch statement being executed. When the HTTP ASYNC EVENT is executed, show_message(answer) is executed, but the switch statement under it does not.

I think this is a compiler error, because it seems that the string_length of the "answer variable" is 1, and using string_digits to make sure, that it escapes all the possible blankspaces or unnecessary characters that could appear when retrieving http callback.

Only possible returning values of variable answer are: 0, 1, 2, 3, 4.

So here is the code of HTTP ASYNC EVENT:

if(ds_map_find_value(async_load, "id") == request_auth) {

    if(ds_map_find_value(async_load, "status") == 0) {
        callback = ds_map_find_value(async_load, "result");

        var answer = string_digits(callback);
        show_message(answer);

        switch(answer) {
        case USERNAME_EXISTS: 
        show_message("username already exists");
        break;

        case ACCOUNT_CREATED:
        show_message("Your account has been successfully created!");
        break;

        case LOGGED_IN:
         buffer_seek(global.buffer, buffer_seek_start, 0);
         buffer_write(global.buffer, buffer_u8, 0);
         buffer_write(global.buffer, buffer_string, "username");
         Send();
        break;

        case INCORRECT_PASSWORD:
        show_message("your password is incorrect");
        break;

        case INCORRECT_USERNAME:
        show_message("your username is invalid");        
        break;

         }

        }



        else {

       callback = noone; 

        }
    }
halfer
  • 19,824
  • 17
  • 99
  • 186
  • Which values in your macros? Is it numbers (`0`, `1`, `2`, etc) or strings (`"0"`, `"1"`, `"2"`, etc)? – Dmi7ry Apr 25 '16 at 04:03

1 Answers1

0

The string_digits returns a string, not a numeric value. So for example, if your string says "1", the returned value will be 49, which is the ASCII code for "1".

I believe that your macros are assigned to numbers (1, 2, 3 ...) and not to their ASCII code ("1", "2", "3" ... = 49, 50, 51 ...). This could explain why the cases are not triggered.

If you are sure that the switch is read, try putting a "default" at the end of the cases. It will be triggered if the cases were not. You could use it to display the value of "answer", for example, and verify that it is what you want.