RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Cursor Picture Motion: is RGSS drunk?

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 67
RMRK Junior
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

Quote
class 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

« Last Edit: May 27, 2012, 02:03:05 AM by termina »

**
Rep:
Level 56
RMRK Junior
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.

**
Rep: +0/-0Level 67
RMRK Junior
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.
« Last Edit: May 27, 2012, 03:28:30 PM by termina »

**
Rep:
Level 56
RMRK Junior
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.