Blackfoot
July 9th, 2015, 00:34
Ok... so I'm working with some code that makes use of string.match and I really need to get a grip on how exactly it works. I've been fudging my way through it up until now with reasonable success but I'd really like to be able to fully understand what all the different codes mean. I found an online reference but it seems a bit incomplete and somewhat incomprehensible in it's explanation.
I'm using string.match to read through the attack line in NPCs.. the code for 3.5 looks like this:
local sDamageRoll, sDamageTypes = string.match(aDamageAttrib[1], "^([d%d%+%-%s]+)([%w%s,]*)");
sCrit, sDamageTypes = string.match(aDamageAttrib[nAttrib], "^x(%d)([%w%s,]*)");
sDamageTypes = string.match(aDamageAttrib[nAttrib], "^%d+%-20%s?([%w%s,]*)");I get that d's are 'all digits'.. and the % is used to identify special characters, w's are 'all alphanumeric characters'... not sure what that means...
Anyway...
In the 1st example...
^ means start at the beginning of aDamageAttrib[1].. The ()'s are a grouping element I think... the []'s are too maybe? The 1st d seems to actually be a d... probably for dice... the second is looking for digits... the %+ and %- are looking for plus or minus signs... if those appear like that are they 'optional'? the %s is looking for a space.. not sure what the + is doing there... my understanding is pretty much starting to disintegrate. :) Help?
I'm using string.match to read through the attack line in NPCs.. the code for 3.5 looks like this:
local sDamageRoll, sDamageTypes = string.match(aDamageAttrib[1], "^([d%d%+%-%s]+)([%w%s,]*)");
sCrit, sDamageTypes = string.match(aDamageAttrib[nAttrib], "^x(%d)([%w%s,]*)");
sDamageTypes = string.match(aDamageAttrib[nAttrib], "^%d+%-20%s?([%w%s,]*)");I get that d's are 'all digits'.. and the % is used to identify special characters, w's are 'all alphanumeric characters'... not sure what that means...
Anyway...
In the 1st example...
^ means start at the beginning of aDamageAttrib[1].. The ()'s are a grouping element I think... the []'s are too maybe? The 1st d seems to actually be a d... probably for dice... the second is looking for digits... the %+ and %- are looking for plus or minus signs... if those appear like that are they 'optional'? the %s is looking for a space.. not sure what the + is doing there... my understanding is pretty much starting to disintegrate. :) Help?