Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Loop problem

I have been messing around with a script of mine but i can't find how to make this loop works correctly...
Code:
def spring_jump
    if @eventx == nil or  @eventy == nil
      return
    end
    loop do
      $spring_jump = true    
      $h_speed = 5
      unless $game_player.moving?     
        if Input.press?(Input::RIGHT) and $game_player.passable?($game_player.x,$game_player.y-1,$game_player.direction)     
          $game_player.move_upper_right          
          elsif Input.press?(Input::LEFT) and $game_player.passable?($game_player.x,$game_player.y-1,$game_player.direction)        
            $game_player.move_upper_left             
          else
            if $game_player.passable?($game_player.x,$game_player.y-1,8)            
              $game_player.move_up                    
              else
                $spring_jump= false   
              end
            end
          end           
          if @spring_power <= 0        
            $spring_jump= false  
            break
          else   
            @spring_power -= 1
          end
        end
      end

What I want is:
-The character just keeps moving up, until @spring power is 0
-if i press right he moves upright
-if i press left he moves upper left

Thanx for reading!
 
Well, you problem is a loop like this goes by SO fast that you don't have enough time to press those keys. What you have to do is spread this out across the update methods in Scene_Map or Scene_Player. A loop like that can go by in milliseconds.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top