[VXAce][Victor Engine - Step Sound] The <no step sound> command on actors crashes the game.

Discussion in 'RGSSx Script Support' started by CarlosDavilla, Apr 24, 2019.

Thread Status:
Not open for further replies.
  1. CarlosDavilla

    CarlosDavilla The Insolent One Veteran

    Messages:
    55
    Likes Received:
    5
    First Language:
    Portuguese
    Primarily Uses:
    RMVXA
    Hello there. Good to see you guys again.

    So, new problem.

    I'm using the Step Sound script from Victor Sant, and it works fine, but the <no step sound> command for actors doesn't work.

    You see, I've tried to put it in my followers on their Note boxes in the Database so they won't make sounds when the player is walking, but when I try out if it works in the game, it crashes to this window:

    [​IMG]
    What could be causing that?
     
    #1
  2. Ateliae

    Ateliae Defying Gravity Veteran

    Messages:
    31
    Likes Received:
    4
    Location:
    Alistavia
    First Language:
    English
    Primarily Uses:
    RMVXA
    Did you try using the script on a blank demo to see if there's some compatibility issues?
     
    #2
  3. CarlosDavilla

    CarlosDavilla The Insolent One Veteran

    Messages:
    55
    Likes Received:
    5
    First Language:
    Portuguese
    Primarily Uses:
    RMVXA
    I certainly did, and it resulted in the same error from my project.
    Looks like it's a problem coming from the script itself.

    [​IMG]
     
    #3
  4. Traverse

    Traverse Veteran Veteran

    Messages:
    115
    Likes Received:
    66
    First Language:
    English
    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.
     
    #4
    CarlosDavilla and KK20 like this.
  5. KK20

    KK20 Just some XP Scripter Veteran

    Messages:
    103
    Likes Received:
    42
    Location:
    Orange County, California
    First Language:
    English
    Primarily Uses:
    RMXP
    Correct, though your solution would only work once I believe. @no_step_sound_player on the second pass through could be true, meaning all the |= will always result in true forever. You need to reset @no_step_sound_player, which is probably why the first one was just a plain equals.
    Code:
    @no_step_sound_player = (actor.note =~ /<NO STEP SOUND>/i) != nil
    would be better.
     
    #5
    CarlosDavilla and Traverse like this.
  6. CarlosDavilla

    CarlosDavilla The Insolent One Veteran

    Messages:
    55
    Likes Received:
    5
    First Language:
    Portuguese
    Primarily Uses:
    RMVXA
    Well, I'll be damned, it actually worked.
    Thank you guys. I was really needing a solution for this one.
    The thread can now be closed.
     
    #6
  7. slimmmeiske2

    slimmmeiske2 Little Red Riding Hood Moderator

    Messages:
    5,736
    Likes Received:
    4,172
    Location:
    Belgium
    First Language:
    Dutch
    Primarily Uses:
    RMXP

    This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

     
    #7
Thread Status:
Not open for further replies.

Share This Page