Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Problem comparing strings (solved)

A topic by PapaQuark created Feb 05, 2020 Views: 104 Replies: 2
Viewing posts 1 to 2
Submitted (3 edits)

I'm trying to have a computer ask for a password. But when I enter the correct password the if statement still does not return true.

As you can see from the comments I have printed the two strings that are compared and they are the same.

Am I missing something obvious?


   : match "start computer"  {
   : if(is_present "computer"){
      :ask_string question = "ENTER PASSWORD"  var = "my_password";
      //: print "COMPUTER PASSWORD - {computer_password}" ;
      //: print "MY PASSWORD - {my_password}" ;
      :if(my_password == computer_password){
         : print "CORRECT!";
      }
      : else{
         : print "PASSWORD IS WRONG.";}
      }
   }
Submitted

I actually figured it out myself :-) But it was a nice trap so this post might help someone.

I was fooled by the uppercase theme. The input I gave looked uppercase  but it was stored as lowercase in the variable. 

The strings did not match since the computer_password was uppercase in my code.

Host (2 edits)

Well done on solving it yourself :-)

Remember, you can use upper() and lower() functions to transform the text too if you like... 


      :if(upper(my_password) == upper(computer_password)){
         : print "CORRECT!";
      }

Not to do with your question, but you might also want to use an alternate match for computer (in this case) too:

// I would probably type 'use computer', and not 'start computer'
: match "start computer;use computer;switch computer;boot computer" {
}