Save-Point
Strange behavior RGSS - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Games Development (https://www.save-point.org/forum-4.html)
+--- Forum: Code Support (https://www.save-point.org/forum-20.html)
+--- Thread: Strange behavior RGSS (/thread-2916.html)

Pages: 1 2


Strange behavior RGSS - Charlie Fleed - 03-05-2009

Today this strange thing happened to me.
I was testing the 2.12 version of my BS, where I had just added a few features, and I discovered that the interpreter that runs common events called by executed skills was running an instruction two times, the second one causing an error btw.
Other instructions were executed once, I tried putting something before and something after that instruction.
It was a script call to $scene.switch which is a method I defined. It is there since version... I don't know, but it's not new and it was not changed recently.
Guess what? The problem was solved by putting a return instruction at the end of that method...

I'm confused...


[Resolved] Strange behavior RGSS - Zeriab - 03-08-2009

What is the line before that return command? (Or line before that if it's an 'end')


[Resolved] Strange behavior RGSS - Charlie Fleed - 03-08-2009

Well, here's the whole method
Code:
def switch()
    # Remove the sprite
    party_position=$game_party.remove_switched_actor(@active_battler.id)
    @spriteset.remove_sprite_in_pos(party_position)
    # Add the actor
    $game_party.add_switched(@switch_id, party_position)
    sprite=@spriteset.add_sprite_in_pos(party_position)
    sprite.animation($data_animations[SWITCHED_ACTOR_ANIMATION_ID],true) unless SWITCHED_ACTOR_ANIMATION_ID==nil
    @status_window.refresh
    return
  end

Thanks for your interest in this strange case. :)


[Resolved] Strange behavior RGSS - Zeriab - 03-09-2009

Sounds like @status_window.refresh returned something odd
Try putting p @status_window.refresh ^^


[Resolved] Strange behavior RGSS - EJlol - 03-09-2009

def switch() <-- why the ( and ) ?


[Resolved] Strange behavior RGSS - Charlie Fleed - 03-10-2009

Zeriab Wrote: Sounds like @status_window.refresh returned something odd
Try putting p @status_window.refresh ^^
It returns false.
p @status_window.refresh works (without the return) as the return value becomes that one of p, I guess.

It's switch() because I like consistency and switch seems odd to me... personal taste of someone who usually programs in C/C++.


[Resolved] Strange behavior RGSS - Zeriab - 03-15-2009

There's your reason.
Returning false has a special meaning in call scripts.


[Resolved] Strange behavior RGSS - Charlie Fleed - 03-15-2009

Code:
# If return value is false when trying to execute event command
      if execute_command == false
        return
      end
      # Advance index
      @index += 1

This is at the end of a loop in the Interpreter::Update method... I guess that's what you're talking about.
Ok, it remains to figure out what I changed to make this happen only now...

Anyway, a return does not cost that much... :D


[Resolved] Strange behavior RGSS - Zeriab - 03-15-2009

You added a return statement which returns nil rather than false.


[Resolved] Strange behavior RGSS - Charlie Fleed - 03-15-2009

Yes, now I know.
I meant, what did I do before when the problem started to happen?
I must have changed something in that refresh method that I don't remember and that caused it to return false, and then caused switch itself to return false to the interpreter.
But I'm too busy with other things to investigate.

I appreciate your help Zeriab, thanks.