Problem to compare words between variables

Get help using Construct 2

Post » Sun Aug 16, 2015 7:41 pm

I don't find any error but the comparison between the variable (currentWord) and the variable (player.word) or with the spritefont's text (wordField) is giving error when the right word is typed. Some help, please. Thanks in advance.

Image
B
74
S
13
G
3
Posts: 995
Reputation: 7,531

Post » Sun Aug 16, 2015 10:08 pm

By error, you mean it returns "Wrong"? Or if it's an error please give us an error message.

Try str(wordField.Text) to ensure that the data is string. Another approach is to output the data in textboxes to see what's wrong with the data. I always make a layout with some textboxes for testing.
Image
B
14
S
4
Posts: 145
Reputation: 1,943

Post » Sun Aug 16, 2015 10:24 pm

Hi @janlindso

Yes, the script runs the "else" actions. I have tried to force the string and I've used text object instead variables and sprite font object. The text object loaded the data correctly but when I compared the text with variables, the sprite font or with another text object, the result is the same. I really don't understand why this condition doesn't stay true.
B
74
S
13
G
3
Posts: 995
Reputation: 7,531

Post » Sun Aug 16, 2015 10:45 pm

You also tried str where you get the values from the array to force as a string? Did you tried replacing the two to test with a string?

For example:
currentWord = "The word to test"
or
"The word to test" = wordField.Text

This way you'll find out if it's the textfield or the array, but I would guess the array that is causing it.
Image
B
14
S
4
Posts: 145
Reputation: 1,943

Post » Sun Aug 16, 2015 11:33 pm

If you have a situation like this:

Var=word
Text=word
but ..
Var≠Text
(word ≠word)

you probably comparing "word " and "word"
(Var=word& space)

set Var to trim(Var)

System expressions wrote:trim(src)
Return src with all whitespace (spaces, tabs etc.) removed from the beginning and end of the string..


if not.... upload a capx
Image
B
64
S
23
G
7
Posts: 1,481
Reputation: 10,823

Post » Mon Aug 17, 2015 11:02 am

@janlindso

I've tried to force str in several ways but not worked. Thanks anyway.


@korbaach

Great! Trim worked very well. Thanks for helping me again, korbaach.
B
74
S
13
G
3
Posts: 995
Reputation: 7,531


Return to How do I....?

Who is online

Users browsing this forum: adamebastin, Bro7hers and 9 guests