S
SmashAdams
Guest
i have a string:
str = "FIST KNIFE SHOTGUN";
I have a substring:
playerText = whatever the player is typing into the input field.
ex: playerText = "FIST";
I want to be able to know if the player has typed either FIST, KNIFE OR SHOTGUN into the input field
without having to do this:
if(playerText == "SHOTGUN){
//do this
}else if(playerText == FIST"){
//do this
}else if //etc...
so I figured I could just count the # of times a substring (playerText) appears in my weapons list (str).
if string_count returns a value >0, then I know the player has typed one of the three weapons.
so I tried that, but it would only return 0.
then I tried simplifying my 'str' string to just str = "FIST";
then when I typed FIST into the input field, string_count returned 1.
why doesn't string_count like me using str = "FIST KNIFE SHOTGUN"?
I know I must be misunderstanding how string_count really works, but i've reread the docs many times.
any help would be appreciated.
an alternative method I think would be to store the 3 weapons as string values in an array, and then loop through each element in that array and check it against string_count to see what it returns. but that could be slow if I have 50+ weapons...
str = "FIST KNIFE SHOTGUN";
I have a substring:
playerText = whatever the player is typing into the input field.
ex: playerText = "FIST";
I want to be able to know if the player has typed either FIST, KNIFE OR SHOTGUN into the input field
without having to do this:
if(playerText == "SHOTGUN){
//do this
}else if(playerText == FIST"){
//do this
}else if //etc...
so I figured I could just count the # of times a substring (playerText) appears in my weapons list (str).
if string_count returns a value >0, then I know the player has typed one of the three weapons.
so I tried that, but it would only return 0.
then I tried simplifying my 'str' string to just str = "FIST";
then when I typed FIST into the input field, string_count returned 1.
why doesn't string_count like me using str = "FIST KNIFE SHOTGUN"?
I know I must be misunderstanding how string_count really works, but i've reread the docs many times.
any help would be appreciated.
an alternative method I think would be to store the 3 weapons as string values in an array, and then loop through each element in that array and check it against string_count to see what it returns. but that could be slow if I have 50+ weapons...