find() expression is not case-sensitive

Bugs will be moved here once resolved.

Post » Tue Nov 10, 2015 4:28 pm

Problem Description
using find() expression is not case-sensitive. Because it isn't, you have to use more complicated methods to get the results you need. It'd be better if find() is case-sensitive.

Attach a Capx
http://1drv.ms/1PmPKxi

Description of Capx
text object has an instance variable holding a string ABCDabcd. find() is used to get index of "b", but it returns an index of 1 instead.

Steps to Reproduce Bug
    run capx

Observed Result
It doesn't return the index of "b"

Expected Result
it should return an index of "b", which would be 5. It should be case-sensitive.

Affected Browsers
  • Chrome: (YES)
  • FireFox: (YES)
  • Internet Explorer: (YES)

Operating System and Service Pack
vista sp2

Construct 2 Version ID
216
B
43
S
19
G
65
Posts: 1,105
Reputation: 37,949

Post » Tue Nov 10, 2015 5:43 pm

I don't think it should be case specific, unless you tell it to be.
For that try regex.
Image ImageImage
B
169
S
50
G
169
Posts: 8,287
Reputation: 108,218

Post » Tue Nov 10, 2015 6:03 pm

having to use regex just to find the index is troublesome, because in some cases you might have to escape specific characters. If you can simply use find(), it would make the process simpler for users.
I don't mind specifying whether to use case-sensitivity as long as there is the option to do so.
B
43
S
19
G
65
Posts: 1,105
Reputation: 37,949

Post » Tue Nov 10, 2015 7:14 pm

Then it's a feature request, and not really a bug.
In the meantime you can use regex, or you can use comparisons using basic operators, string="b", string variable="B", etc.
Btw text object compare text can be case sensitive.
Image ImageImage
B
169
S
50
G
169
Posts: 8,287
Reputation: 108,218

Post » Tue Nov 10, 2015 7:19 pm

I'd say it's a bug considering javascript's indexOf() is case-sensitive. There's no explanation or even mentioning why find() isn't case-sensitive in the manual. If someone wants to find where "string" is, and they have "strinG" before it, it will return the wrong index.
B
43
S
19
G
65
Posts: 1,105
Reputation: 37,949

Post » Thu Nov 12, 2015 3:16 pm

find() appears to be deliberately case insensitive, probably because most features in C2 are case insensitive too (e.g. matching animation names is case insensitive). I won't change it, since it could break compatibility with existing projects. For the next build I've added a new findCase() system expression which works identically but is case sensitive. I'll update the documentation to reflect this as well (which normally we do just before the next stable release).
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,772

Post » Thu Nov 12, 2015 4:14 pm

Thanks!
B
43
S
19
G
65
Posts: 1,105
Reputation: 37,949


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 2 guests