Before I begin, I would like to point out that you're not using GMatch correctly, based upon from the research I conducted, as I found that it's used for Loops, and not itself alone (According to the Wiki, at least). I would also like to disclaim that I will not be rewriting your code, otherwise I'm doing the work for you. :P
Now, to begin. >:)
To accomplish what you're trying to do, there're 2 ways you could go about this; you could use:
GMatch (when used correctly) - Uses String Patterns (as far as I know); however, you would not use this to accomplish what you're trying to do
Find - This will only return the position of where the keyword is at, and not the word itself; it will also only search for the matching keyword, then stop the iteration
Match - Similar to Find, but the difference is that it'll return the word (not the entire word, however)
Before we proceed, I would like to add a string & a table to handle all this, w/o the need of re-typing over-and-over again:
local String = 'Hello World! I\'m on Scripting Helpers!'
String = string.lower(String)
local toFind = {
Strings = {
'world',
'hello'
},
StringPatterns = {
'h%a+'
}
}
Lets start w/ GMatch: GMatch is a function that will iterate through the string, then return them( I believe? If anyone has a better explanation to this, please let me know; I'm not familiar w/ GMatch, and I'm going off of the Wiki & how its used); think of it as a table, but not a table at the same time:
for v in string.gmatch(String, toFind.StringPatterns[1]) do
print(v, 'GMatch Result')
end
Now, after the code is fired, it'll return 2 results in the Output; this is what will be returned:
However, this will not help you accomplish what you're trying to do.
Now, onto functions I'm more familiar w/! :D We'll be using function Find in our next example, following function "Match". :)
For the "Find" function, it's used to iterate through a specified string (value), and return the first keyword found; however, it will not return the word itself, but the position of it. This is how the "Find" function would be used:
print(string.find(String, toFind.Strings[1]), 'Find Result')
And when we fire that above code, this is what will be returned in the Output:
But, that's only one of the 3 that can be used! :O
Now, for the "Match" function, it's used to iterate through a specified string (value), and return the first keyword found; unlike the "Find" function, it returns the word (it was given) that was found. This is how the "Match" function would be used:
print(string.match(String, toFind.Strings[2]), 'Match Result')
Aaaaand when we fire the above code, this is what will return in the Output:
And wa-la! That's 3 ways to check & find specific a keyword(s) in a string! :D Plays Final Fantasy Victory Theme
I forgot to mention before that w/ "Find" & "Match", if they don't find the keyword that was given to them, they will return nil, so be careful when using them. :o
Stuff touched on, but didn't go into great detail about
"Find" Function
"Match" Function
"GMatch" Function - Tbh, this was a nightmare ;-;
String Patterns
The Output - Retrieves & shows data (such as strings & numbers), warnings, & errors.
Loops
Tables -- Hold (or contains) data, such as strings, numbers, objects, etc.
Functions
Nil
Iteration
I hope this helped you in any way. :)
4 comments
string.gmatch, string.find etc.
Right here is everything with string manipulation -->> http://wiki.roblox.com/index.php?title=Global_namespace/String_manipulation
Looking at it, I think you've just muddled the arguments up. The first argument should be the string your checking, not the phrase that you are trying to find in the string
@JohnnyMorganz I have tried now with if string.find("one", chosenMenuChoice) then but anything below that does not work for some odd reason, print("test") doesn't print either.