Case insensitive string comparison

Get help using Construct 2

Post » Mon Jul 14, 2014 3:07 pm

Hi!

Is it possible to compare a string variable in an case insensitive manner?

Let's say my variable can have "a" or "A". I tried to make an =equal to "a"|"A" expression, but it didn't work.
B
9
S
1
Posts: 97
Reputation: 715

Post » Mon Jul 14, 2014 3:23 pm

You can use the lowercase() expression to convert your string to lowercase, then compare to a lowercase version.

"a" Equal lowercase("A") will be true
ImageImageImage
B
71
S
21
G
220
Posts: 3,649
Reputation: 123,727

Post » Mon Jul 14, 2014 5:14 pm

Thanks for your reply!

That doesn't seem to work in my situation, because I'm looping through positions in an array, so there is no place where I can insert the lowercase() expression.

My code is like this:
myArray For each X element
--myArray currentValue ="a"

I also don't want to permanently manipulate the contents of the array (I need to retain the mixed case letters, just not for the comparison).

Damn.. this is more difficult than I thought. I wonder why =equal to "a"|"A" is not working.
B
9
S
1
Posts: 97
Reputation: 715

Post » Mon Jul 14, 2014 6:16 pm

You would have to compare lowercase(myArray.CurrentValue) is equal to lowercase("a").

As for the equal to "a"|"A", | is a logic operation, it will do "a" OR "A" which returns 0 or 1, so you were actually comparing the value to 0 or 1 (not sure what it should even try to return int hat case)
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Mon Jul 14, 2014 7:02 pm

Thank you so much! That worked!

If someone else with the same problem is reading this, let me point out that to do what Aphrodite suggested, I had to choose "system"-->"compare two values" instead of "compare variable".

Thanks again!
B
9
S
1
Posts: 97
Reputation: 715


Return to How do I....?

Who is online

Users browsing this forum: apalm1341, blissfulwizard, Yahoo [Bot] and 17 guests