I have seen this problem with this script mentioned before. And I can offer a guess as to what the problem is. However, it would be nice if somebody more experienced with Ruby could help to confirm my guess.
My guess is this:
Because of the way the script checks for the <no step sound> notetag on the Actor, the variable used to detect it (@no_step_sound_player) stores the information as an integer.
Code:
# This is the line that checks the Actor notebox for the tag.
@no_step_sound_player = actor.note =~ /<NO STEP SOUND>/i
The "=~" operator here returns the letter position in the text data (the Actor notebox in this case) where the phrase being checked gets detected (if it exists), so it would be "0" if the <no step sound> tag was the first thing in the notebox, "1" if there was a single space or some other letter before the tag, "2" if there's 2 spaces or two letters, "10" if you had some other 10-letter notetag before the step sound one, etc, etc. And if there is no detection and the <no step sound> tag is NOT in the notebox, the value returned is "Nil".
But I digress, it doesn't really matter what the number is/how many characters down the notebox the tag is. The point is that the detection is stored as either a number or Nil.
After that, whatever the value of the variable ends up being, the script then continues to check it against any equipment and states applied on the Actor to see if any of them also has any <no step sound> tags in their noteboxes.
Code:
actor.equips.compact.each do |equip|
@no_step_sound_player |= equip.note =~ /<NO STEP SOUND>/i
end
actor.states.each do |state|
@no_step_sound_player |= state.note =~ /<NO STEP SOUND>/i
end
The problem is that the way he does THESE checks uses the |= operator. If I am not wrong, this operator will do different things, depending on what kind of object it is being used on. If it is used on a number, it becomes the Bitwise-or operator and flips digits on the binary value to return another number.
BUT if it is used on an object whose value is "True" or "False" or "Nil", it becomes a comparison operator that then returns true or false. True and False in Ruby is not the same thing as the numbers 0 and 1, they are actually whole objects called TrueClass and FalseClass (I think Nil is also a FalseClass) and these classes overwrite the |= operator. They make it so that if a TrueClass object calls it, it will always return True. And if a FalseClass or Nil calls it, it will check the value on the right-hand side and return False if the other value is also False or Nil, otherwise it will return True.
I suspect this true/false outputting was what Victor Sant MEANT to use it for. And it works if the value of @no_step_sound_player is either True or False or Nil when the check is performed. But if the value is a number, I suspect it attempts to apply the bitwise version of it instead. And since the value of the right-hand side, Nil, is not a number, it throws a crash when it tries to do it (I don't know what would happen if you engineered it so that all the equipment/states on the Actor actually DID have the tag and none of the checks returned Nil).
So the solution I would offer is this:
Code:
# Replace this line:
@no_step_sound_player = actor.note =~ /<NO STEP SOUND>/i
# With this line:
@no_step_sound_player |= actor.note =~ /<NO STEP SOUND>/i
Since the value of "@no_step_sound_player" is Nil by default, it will run the FalseClass version of the operator on whatever is detected by "actor.note =~ /<NO STEP SOUND>/i" and so will return True instead of directly setting the value to the number outputted by the check on the notebox, if the notetag exists (if not it will return False).
Basically, it will prevent it from becoming a number and making the following checks screw up later on by trying to run the bitwise operation.