Searching a string for a word?

This forum is currently in read-only mode.
From the Asset Store
Searching
$16 USD
Searching is a game where you are challenged to find all the images with the requested letter in 30 seconds.
  • Is it possible to search a string for a word? I'm thinking of creating a complex AI, and i want to easily be able to add different skills to the AI. So for example, if i want him to be able to see in the dark, i would simply open his "atributes" string and write "NightVision". Then the code applies certain events for every enemy with nightvision! I could use a bunch of private values, and have for example the value "NightVision" set to 1 if it should apply to that enemy, but it would require more repetition, and be harder to organize. Searching for a word could be used in other ways too, so if it's not allready in construct i suggest you ad it to the to-do list!

  • This should be possible to do in Python.

    Something like this maybe

    if my_attribs.find("NightVision"):
            # Yay, I'm a cat!
    [/code:1c1wabwq]
  • You can do this with the Compare Values condition and the Find() expression:

    Find("Source string, with different words", "different")

    different to

    0

    would mean the word "different" existed in the source string.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Perfect. Thank you guys!

  • I'm bumping this thread now... so what? i don't care!

    eeh.. Is it possible to search for many words at the same time? Something like

    Find("Source string, with different words", "hello", "dude!")

    different to

    0

    Exactly what i wrote seems to do something, but i can't figure out what it does.

  • Surely you could make that another condition in the event? Provided you wanted it to only run the event if BOTH words could be found.

  • The third parameter to Find is the index at which to start searching, but the expression validator accepts a string (eg. "55") but "dude!" will be converted to 0 so it doesn't do what you think... a bit dubious design on my part perhaps. Use a function or condition alias to search for several words at once, maybe.

  • Nice! I'll use the function now that you've told me how it worked. I used multiple conditions before, but one event was bigger then the screen, so it got kind of annoying. the function take up less space.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)