View Full Version : Syntax help appreciated
masterdtwin
02-27-2014, 08:32 PM
I'm getting a comparison error fixnum to nil on '<' from this line
(CharSetting['cast_count_4'] += 1 and CharSettings['infuse_count_4'] += 1) if (130 < end_roll < 141)
My best guess is the previous line isn't capturing the end_roll and is still using the nil value. Or my syntax is wrong because I'm not overly familiar with ruby
end_roll = Integer($1) if line =~ /.* \=\= \+(\d+)/i
Help would be appreciated
Tgo01
02-27-2014, 08:40 PM
Have it echo the value of end_roll before the comparison to make sure the value isn't nil.
masterdtwin
02-27-2014, 10:52 PM
It's looking like you can't use end_roll until after you have broken from the 'while line = get'
Fortunately, I think I have found a creative way to bypass that - should have an answer soon
edit: it seems no matter what I do - it refuses to pull the endroll properly, or allow me to use it
Tillmen
02-27-2014, 11:16 PM
You probably shouldn't be using an inline "if" statement here. Your regex will certainly match the end roll when one appears, but you are presumably testing every line for an end roll. Obviously not every game line contains an end roll. When it doesn't, end_roll is going to be nil, and your code is going to try to use it anyway. Try something more like this:
if line =~ /^\s*CS.*== ([\+\-]\d+)/
end_roll = $1.to_i
(CharSetting['cast_count_4'] += 1 and CharSettings['infuse_count_4'] += 1) if (end_roll > 130) and (end_roll < 141)
end
For no particular reason, Integer($1) annoys me, so I changed it to $1.to_i
I tweaked the regex to avoid matching chats (and thoughts/whispers/etc even though those are less likely), and to give you a negative number if the end roll is actually negative.
(130 < end_roll < 141) does not do what you think it does.
end_roll = 9001
(130 < end_roll < 141)
((130 < end_roll) < 141)
((130 < 9001) < 141)
((true) < 141)
true < 141
true.<(141) # this line is equivalent to the previous. It's attempting to call the < method of an object with 141 as a parameter
true.method_missing(:<, 141) # < is not defined for TrueClass
true # method_missing is defined for TrueClass (in Lich), and it always returns true
masterdtwin
02-28-2014, 12:17 AM
Okay, after a few hints from Tillmen I got things working properly
I've made some major changes to infuseme, once I get some good stats I'll post it up
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.