Check which words is there first in a string

Hi!
Given var(x) = string (free input text)
There is a way to check if, in that string, comes first "word1" and then "word2" or vice versa?
Greetings
Hello! You can check the Index of the words in the string:
Code:
var text = "word1 word2 word3"
if (text.indexOf("word1") < text.indexOf("word2")) {
  //code if word1 come before word2
} else{
  //code if word2 come before word1
}
Thanks!
Can I put the
(text.indexOf("word1") < text.indexOf("word2"))
in the script window of a conditional branch?
Hello! You can check the Index of the words in the string:
Code:
var text = "word1 word2 word3"
if (text.indexOf("word1") < text.indexOf("word2")) {
  //code if word1 come before word2
} else{
  //code if word2 come before word1
}

Thanks!
Can I put the
(text.indexOf("word1") < text.indexOf("word2"))
in the script window of a conditional branch?
Hi again. Can be done many ways. Depends on what you wan't to do...
Could be done this way, using a variable:
Capture d’écran 2020-04-21 à 11.03.07.png
Am I right you've stored the string in a game variable? Then use this in the conditional branch script box:
JavaScript:
let text = $gameVariables.value(x); text.indexOf("word 1") < text.indexOf("word 2")
Am I right you've stored the string in a game variable? Then use this in the conditional branch script box:
JavaScript:
let text = $gameVariables.value(x); text.indexOf("word 1") < text.indexOf("word 2")

Yup, you are right.
Just a clarification: are "word1" and "word2" in your code case sensitive or not?
I mean, I use them as names, but I don't really care if the player writes "mark" or "Mark".
Yes, but here they aren't :LZSproud:
JavaScript:
let text = $gameVariables.value(x).toLowerCase(); text.indexOf("word 1") < text.indexOf("word 2")
Yes, but here they aren't :LZSproud:
JavaScript:
let text = $gameVariables.value(x).toLowerCase(); text.indexOf("word 1") < text.indexOf("word 2")
Perfect as always!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/check-which-words-is-there-first-in-a-string.120478/