[SCRIPTING]NEED HELP WITH REGEX
Posts
Pages:
1
class << self alias datamanager_orig_load_database load_database end def self.load_database datamanager_orig_load_database load_skill_notetags end def self.load_skill_notetags groups = [$data_skills] for group in groups for obj in group next if obj.nil? obj.load_skill_notetags end end puts 'ks_skill_level_up notetagreadproc' end end class RPG::Skill < RPG::UsableItem def load_skill_notetags #uses, skillID, replace? <= order of info (irrelevant) @lvlup_deets = [0, 0, 0] @note.split(/[\r\n]+/).each do |line| case line #<skill_levelup: 74, 1, 0> <= target string to match when '/<skill_levelup:(\s*(\d+)),\1,\1>/' #<= regex that's not working at all @lvlup_deets = [$1.to_i, $2.to_i, $3.to_i] puts "[#{@lvlup_deets[0]}, #{@lvlup_deets[1]}, #{@lvlup_deets[2]}]" end end end end
Help me...
The above code supposedly scans the note boxes of all skills for matches, in order to retrieve 3 integers (stored in an array when a match is found). Easy enough, except that it isn't. I dumped the 'puts' line just to see if it's even matching, and found out that it doesn't. It's no exaggeration to say that I suck at regex :(
Can anyone please tell me what it is I'm getting wrong? This has been driving me nuts for hours...
I doubt it matters, but it's for a skill level-up script for VXA. Also, the above code is based off of yanfly's method.
LockeZ
I'd really like to get rid of LockeZ. His play style is way too unpredictable. He's always like this too. If he ran a country, he'd just kill and imprison people at random until crime stopped.
5958
What's an example of one of the noteboxes that it's supposed to match?
LockeZ
I'd really like to get rid of LockeZ. His play style is way too unpredictable. He's always like this too. If he ran a country, he'd just kill and imprison people at random until crime stopped.
5958
Try this:
I didn't even look at the rest of the code, so hopefully the only problem was your critical failure with regex. I adjusted the way the code was written slightly because I know this way works and I wasn't convinced the other way was working. If you'd rather go back to the way you had it, you can use use the regex
The [ ]* means "0 or more spaces", and the (\d+) means "1 or more digits, which we should store in a variable". I also backslashed the commas and angle brackets. I also got rid of the quote marks around the regex, because regexes aren't strings, and you're not supposed to surround them with quotes.
class << self alias datamanager_orig_load_database load_database end def self.load_database datamanager_orig_load_database load_skill_notetags end def self.load_skill_notetags groups = [$data_skills] for group in groups for obj in group next if obj.nil? obj.load_skill_notetags end end puts 'ks_skill_level_up notetagreadproc' end end class RPG::Skill < RPG::UsableItem def load_skill_notetags #uses, skillID, replace? <= order of info (irrelevant) @lvlup_deets = [0, 0, 0] @note.split(/[\r\n]+/).each do |line| case line if match = line.match(/\<skill_levelup:[ ]*(\d+)\,[ ]*(\d+)\,[ ]*(\d+)\>/) @lvlup_deets = match.captures puts "[#{@lvlup_deets[0]}, #{@lvlup_deets[1]}, #{@lvlup_deets[2]}]" end end end end
I didn't even look at the rest of the code, so hopefully the only problem was your critical failure with regex. I adjusted the way the code was written slightly because I know this way works and I wasn't convinced the other way was working. If you'd rather go back to the way you had it, you can use use the regex
/\<skill_levelup:[ ]*(\d+)\,[ ]*(\d+)\,[ ]*(\d+)\>/
The [ ]* means "0 or more spaces", and the (\d+) means "1 or more digits, which we should store in a variable". I also backslashed the commas and angle brackets. I also got rid of the quote marks around the regex, because regexes aren't strings, and you're not supposed to surround them with quotes.
Pages:
1