With the title, I don't mean that I want to check if the label text is equal to something, the thing I want to check is if the label text, no matter how long, contains specific characters.

In my game, I have a combination lock which stores all pressed numbers in a label. I don't have a confirm button, as I want it to be similar to games like Silent hill and Cry of Fear.
Let's say the player presses the numbers and the label ends up like this:
117374925863424
In my case, I want to check if the numbers "5863" appear in ANY part of the label above.
11737492 5863 424

Checking the text like this doesn't work, as the label needs to be exactly "5863":

if Label.text = "5863":
    DoSomething()

I would appreciate any help

  • if "5863" in Label.text:

    Or:

    if Label.text.contains("5863"):
if "5863" in Label.text:

Or:

if Label.text.contains("5863"):

    spacecloud Thanks, the first solution worked perfectly. I also tried the second one just in case, but there was an error regarding the use of "contains"

      Darxkl05 there was an error regarding the use of "contains"

      Did you place a colon : at the end?

        Hope people don't mind me hijacking this thread, how efficient is text.contains? Wondering if I could use it for a game debugging/cheat console.

        I haven't looked at the source code, but my guess is that it's as efficient as possible for the general problem it's solving ("Does an arbitrary string contain an arbitrary substring?").

        Whether it's the most efficient way of solving that problem in a game context would depend on whether there are alternatives. For example, hashing strings and comparing the hashes.

        If you need actual string parsing (like for a command console) you'll need to learn RegEx. It's probably overkill for a single string match but if you need anything more complex you can't avoid RegEx (regular expressions).

        spacecloud
        I messed this up slightly, line 17 was garbage = a in b when it should have been garbage = b in a.
        The difference is smaller after fixing that.

        Updated the project to fix this.