Search code examples
game-makergml

How to compare strings in GML


After reading the documentation I have not found what is the correct way to compare two strings in GML. I've tried the comparator '==' and doesn't seem to work (probably compares that they are the same object, which they are not). Another thing I can think of is using string_pos function to get 0 if they are equal and -1 if not, but seems a little overkill. Is there a more efficient way of comparing two strings?


Solution

  • When comparing anything in GML, you have to use a single '='. Other than in javascript or c#.

    so it would be:

    if "test" = "test"{
        return true
    }else{
        return false
    }
    

    the code above will return true

    But to test variables in other objects, you would use [objectName].[variable] .