IF condition does not work correct with string comparison in background event handler

I've found strange behavior of IF condition in a background handler.

In the main part I store some 'command' to be read in the background event handler:

Application.Storage.setValue("command", "do123");
System.println("command 'do123' is set");
Background.registerForTemporalEvent(Time.now());

In the background event handler the following code:

    function onTemporalEvent() {

		var command = Application.Storage.getValue("command");
		System.println("command is read: '" + command + "'");

		if( command == "do123" ) {
			System.println("I heard it right");
		} else if( command == "321od" ) {
			System.println("thgir ti draeh I");
		} else {
			System.println("the cat is dead");
		}

        Background.exit(true);
    }

... gives the result:

Background: command is read: 'do123'
Background: the cat is dead

If transmitted command is changed to int number (123 instead of "do123"), then it works as it is supposed to do.

Do I do something wrong here?

  • Monkey C is like Java: string equality with "==" does not work as you might expect ("==" does not compare string contents). You have to use the String.equals() function.

    e.g.

            if (command != null && command.equals("do123")) {
                System.println("I heard it right");
                //...