Main Menu
  • Welcome to The RPG Maker Resource Kit.

Cursor Picture Motion: is RGSS drunk?

Started by termina, May 27, 2012, 02:00:00 AM

0 Members and 1 Guest are viewing this topic.

termina

Hello there!

I'm currently making a simple Zelda menu with pictures using script.
Everything's OK, except this: cursor-picture movement.

What I want is moving a picture as a cursor whose possible positions form sequences ( X_pos1 -> X_pos2 -> X_posn  and  Y_pos1 -> Y_pos2 -> Y_posn ) that don't obey any mathematical law.

On testing RGSS reads my script very strangely: at some intermediate positions the cursor moves to the left instead of right, at others it merely skips 2 positions. :o

Here is a test-script of this called by an event; could aynone tell me where my error is?

Thank you

Quoteclass Cursor_Menu
 
  #------------------------------------------
  #  4 position for the cursor  X=20  ; X=50 ; X=100  ; X= 200
  #-------------------------------------------
def initialize
    @image = Sprite.new
    @image.bitmap = RPG::Cache.picture("your cursor picture name")
    @image.x = 20        # initial X co-ordinate
    @image.y = 200
    @image.zoom_x = 0.2
    @image.zoom_y = 0.2
   
    loop do
      Graphics.update
      Input.update
      cmd_update
      @image.update
    end
   
  end

    #------------------------------------------------
def cmd_update
   if Input.trigger?(Input::LEFT)
      if @image.x == 20
         @image.x = 200       #20 being min. position, place the cursor to the max. one
      end
      if @image.x == 50
          @image.x = 20
      end
      if @image.x == 100
        @image.x = 50
      end
      if @image.x == 200
        @image.x = 100
      end
   end
   if Input.trigger?(Input::RIGHT)
      if @image.x == 20
        @image.x = 50
      end 
      if @image.x == 50
          @image.x = 100
      end
      if @image.x == 100
          @image.x = 200
        end
      if @image.x == 200
        #  @image.x = 20  #200 being the max. position, place the cursor to the min. one
        end 
   end 

end
end


Trihan

Change your ifs to elsifs. Right now it's going through every if statement in sequence, so imagine this:

"Okay, the X position is 20 and you're pressing left. That means I need to change the X to 200!"

"Is X 50? No, let's move on."

"Is X 100? No, let's move on."

"Is X 200? Why yes it is! That means I need to change X to 100!"

The script has no way to differentiate when it's already moved the cursor when it checks the next conditional; by making them elsifs instead, it'll only ever do one check and one movement.
It's more like a big ball of wibbly wobbly...timey wimey...stuff.

termina

#2
Thank you for your tip!
I'm gonna try it.

EDIT: that works like hell, thanks!

That's strange, though: I remember when i programmed the cursor with common events only, I used the same kind of conditionnal structure as the script I show you, and it behaved exactly as I expected.

Trihan

That is weird. If you did a common event the same way it should cause the same problem. Oh well.
It's more like a big ball of wibbly wobbly...timey wimey...stuff.