ID:818213
 
(See the best response by Kaiochao.)
How can I compare a text string to a variable in an if statement
Random Example:
mob/var/string = "Hello"

mob/verb/response
if(string == "Hello")
usr<<"Hi"

I know in java you have to use .equals. Is there something syntax based I have to include/change or should I go about doing this a different way?
Just like any other variable, you use == to compare exact values.
e.g. true == (1 == 1) == ("blah" == "blah")

Of course, == is case-sensitive with strings, so you can use a different method to compare. Look up the cmptext() and cmptextEx() proc in the DM Reference. An alternative would be to compare the lowertext() or uppertext() of both strings, but cmptext() is probably a much better way.
The problem is whether I run
if(string == "whatever")
//or
if(cmptext(string, "whatever")


I get a runtime error that says:
Wrong type of value for list

Could you provide a more complete example? You're obviously doing something wrong, but not here. (well, you're missing an end-paren after your cmptext() as well as the () after 'response' in your first example, but I'm sure there could be something else)
Basically I have a proc that checks a var that a player has. If the var equals a value I gave it in a string it should give the player a verb.
mob/player/var/variable = "This"
mob/player/proc
Procedure()
if(variable == "This")
verbs+=/mob/player/other/verb/x()

I also tried
mob/player/var/variable = "This"
mob/player/proc
Procedure()
if(cmptext(variable,"This"))
verbs+=/mob/player/other/verb/x()

I figured ^ didnt work possibly because the first parameter of cmptext was a var and not something in text but I could be wrong
In response to Raruno
Best response
The only problem I see with this code is the () after the verb path. It's just a path, so you're not calling anything.
Your right it was the mistake of putting () on the end. Thanks