Compare text with < and >

Almost every language I’ve used has a way to compare text or strings in ways other than equal and not equal. I desperately wish Gdevelop had the same operators for text (strings) as it has for numbers. =, ≠, >, ≥, < and ≤

I realize this might involve a lot of reworking depending on how the app is made but some things are impossible to do without text comparison (like sorting text) and other actions require unnecessary repetitive conditions.

I mentioned sorting but there are times when I would like to check if something is in a range like between “a” and “e”. Currently, I would need to put 5 conditions inside an OR or use the string find expression but strFind(variable, “abcde”) ≠ -1 isn’t as polished as variable ≥ “a” and variable ≤ “e”. And if you’re comparing multiple character strings it would be impractical to do it.

I understand, text/strings are used in a lot of places. As a starter or compromise modifying or or adding a condition to check two strings using all of the operators would be an excellent helper. I could do a lot with string<string or any other comparison.

3 Likes

Can you post some examples of how this is done in JS or another language? I’m not familiar with the concept and can’t find any references for doing this in big engines from a quick google (unity/unreal), so if you’ve got examples it may help Luni or the rest of the dev team think through how it could be implemented

1 Like

Javascript uses localCompare but you can also use operators

const str1 = "apple";
const str2 = "banana";

if (str1 < str2) {
  console.log(`${str1} comes before ${str2}`);
}

In Visual Basic

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim str1 As String = "apple"
        Dim str2 As String = "orange"
        If str1 > str2 Then
            Debug.Print(str1 + " is greater than " + str2)
        Else
            Debug.Print(str1 + " is less than " + str2)
        End If
    End Sub

Wild, I’ve never seen a local compare or string comparison that way before in JS. That’s interesting.

That said, if it’s doable in javascript, it should be doable as a condition(s). Sadly, while I can think of a few ways to make it an extension, there is no “operator” parameter for extensions, so we couldn’t do a 1:1 “compare strings” condition.

I am not saying that it should not be added but meanwhile you can create a extension and make it a expression/action/condition tho.

1 Like

You cannot easily make it an extension for the reason I mentioned above. Extensions cannot use an operator parameter, unfortunately.

So you’d have to make conditions for “String1 is less than string 2” “String1 is greater than string 2” etc, because you cannot have someone set/choose parameters of < =< > =>, etc. Which doesn’t save a ton of time.

1 Like

Its possible to use a “list of options” parameter and insert all the operators there but ok.

1 Like

I could still make it for myself. Also, the text list parameter would be very close to an operator or operand list. I could add the various symbols. Although, it would also allow other characters. So maybe not beneficial as a public extension.

Maybe a simplier way would be a simple single comparison like is greater than condition? It could be inverted or use a boolean switch? The only issue is there are 5 possible conditions counting ≤ and ≥ 6 if you count ≠ I guess there could be a switch to include equals. I’ll think about it.

I’d still prefer a built-in feature. The UI is already there and it wouldn’t require a fundamental change in thinking. It wouldn’t be a new concept, it would just use the same concept that already applies to numbers.

Another option, is to ask the creator of the array tools to add a sort by string. That would help with the sorting part. That would probably be an easier path… Although, it never hurts to ask. If not now maybe later. And maybe this will inspire something else.

All I ask is a chance to be heard. That’s one thing I like about Gdevelop. They listen and respond and the app is continuously evolving.

2 Likes

Good call, I totally forgot list of parameters existed since it was added after the last extension I submitted fully to the main list.

I don’t know that it being a “native” feature is any different than an extension at this point. If you know the JS to complete it, I’d definitely say build it out and submit it incase anyone else would have use of it, similar to the math tools extension.

1 Like

I’m not to the point yet where I can use the best practices. I’m still a little confused by some aspects. I can get things to work for myself because if it’s not perfect, I can fix it. I don’t currently have the knowledge to release something bug free but I would be willing to share my concept or code snippets.