PDA

View Full Version : String Comparisons


dinrogue
23-06-2007, 06:20 AM
For a mod, I'm trying to gather all ranks of a certain poison and add their counts together. Instead of creating anywhere from 2-7 name variables depending on the poison, I was wondering if I could create one and test this way. For instance:


RR_ITEM_CRIPPLING="Crippling Poison";

--Assume the code is looping through the bags, and this condition is checked every slot and name is the name of the item being checked.

if(name>=RR_ITEM_CRIPPLING) then
--Update count
end



I'm fairly sure this would detect all ranks of crippling poison because rank I would be equal to the variable and rank 2 would be greater than, same goes for all poisons. But I was thinking would it be possible that a certain item would turn up as greater than that because of it's alphabetical value. I'm not sure how Lua compares strings, but in Java some strings would return greater than if they use letters later in the alphabet. Sorry if this is confusing.

Telic
23-06-2007, 12:10 PM
I think you'll run in to problems.

I think the quickest/easiest way to do what you want is to :

string.find(name, PR_ITEM_CRIPPLING)


Check out the following, and the related pages for more information about string functions in LUA :

http://www.lua.org/pil/20.1.html

For example, if you want to test for a name that BEGINS with "Crippling Poison" followed by 0 or more characters then you could do something like :

string.find(name, "^Crippling Poison.*")

[This last suggestion is an educated guess without any testing, but the string.find function works ;p ]

Rowaa
25-06-2007, 08:49 AM
You're misunderstanding string comparsion. It works by comparing each successive symbol in line and checking them if it is different (greater or lesser), proceeding to next one only if they're the same. Therefore any string that starts with "D", "Cs", "Crj", "Criq", etc will be greater than "Crippling Poison". Just as Telic says, you need to use regexps for that.

dinrogue
25-06-2007, 07:07 PM
OK, thanks for the help.