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?
ID:818213
![]() Jun 16 2012, 6:42 am (Edited on Jun 16 2012, 8:38 am)
(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" 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? |
The problem is whether I run
if(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" I also tried mob/player/var/variable = "This" I figured ^ didnt work possibly because the first parameter of cmptext was a var and not something in text but I could be wrong |
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.