(RGSS3 doubts) Problem - My First Script

Hello, I'm doing a "Jump" script, but I have a problem.


Spoiler
class Game_Player < Game_Character  alias tiagoms_jump update   def update    tiagoms_jump    if Input.trigger?🙂C)      if stopping?        jump      end    end  end   def jump      case @direction      when 4 # Left                if passable?(@x-5,@y,@direction)          print "-5 pass \n"        end        if passable?(@x-4,@y,@direction)          print "-4 pass \n"        end                if passable?(@x-3,@y,@direction)          print "-3 pass \n"        end                if passable?(@x-2,@y,@direction)            print "-2 pass \n"          end                  if passable?(@x-1,@y,@direction)              print "-1 pass \n"            end                    if passable?(@x,@y,@direction)            print "0 pass \n"        end                  if passable?(@x-5,@y,@direction) or passable?(@x-4,@y,@direction) or passable?(@x-3,@y,@direction) or passable?(@x-2,@y,@direction) or passable?(@x-1,@y,@direction) or passable?(@x,@y,@direction)        else          print "Not Work \n"          end      end   endend
Following the script (situation)

==aligned==

1 stone: (-5, -4, -3, -2)

2 stones: (-5, -4, -3)

3 stones: (-5, -4)

4 stones: (-5)

5 stones: (Not Work)

==with spaces==

stone, space, stone: (-5, -4)

stone, space, stone, space, stone.... (not work)

 

 

Could anyone help me?

Download Demo: https://drive.google.com/file/d/0B3d2YApCS0RxczllMmcyRndHVDA/view?usp=sharing
Little confused on what you mean. But looking at your script it looks like you did a bit of extra work that you could have cut down using loops

Example:

case @directionwhen 4 x = @x - 5 until passable?(x, @y, 5) # you probably want to put in 5 as the direction instead x += 1 break if x == @x # break loop once we're back to the original x end p "#{x} pass"endwith that loop it'll keep subtracting 1 until it finds a passable tile or breaks once you're at the starting x. Less work then all the if statements.
It's a Jump of script.
In this case, as I would put the command "jump"?

This is a original idea:

Spoiler
class Game_Player < Game_Character  alias tiagoms_jump update   def update    tiagoms_jump    if Input.trigger?🙂C)            jump2          end            end #end update  #-----------------------------------------------------#  #                                                     #  #  JUMP                                               #  #                                                     #  #-----------------------------------------------------#  def jump2      case @direction      when 2 # Baixo        if passable?(@x,@y+3,@direction)          jump(0,3)        else          if passable?(@x,@y+2,@direction)            jump(0,2)          else            if passable?(@x,@y,@direction)                jump(0,1)            end          end        end      when 4 # Esquerda        if passable?(@x-3,@y,@direction)            jump(-3,0)          else            if passable?(@x-2,@y,@direction)              jump(-2,0)            else              if passable?(@x,@y,@direction)                jump(-1,0)              end            end        end            when 6  # Direita        if passable?(@x+3,@y,@direction)          jump(3,0)        else          if passable?(@x+2,@y,@direction)            jump(2,0)          else            if passable?(@x,@y,@direction)              jump(1,0)            end          end        end      when 8 # Cima        if passable?(@x,@y-3,@direction)          jump(0,-3)        else          if passable?(@x,@y-2,@direction)            jump(0,-2)          else            if passable?(@x,@y,@direction)              jump(0,-1)            end          end        end            end   endend
But, not work correctly.

== EDIT ==

Demo Download: https://drive.google.com/file/d/0B3d2YApCS0RxRG1SV2FGOWhOZFk/view?usp=sharing
Yeah I know, but using the loop would be easier and looks cleaner then those next if statements. The problem is most likely that you're putting in @direction for the direction parameter in passable?() . The direction parameter will change the x, y values, which is why I put in 5 in my loop version since 5 means on that tile. So try changing all those @directions to 5. Since you are jumping it shouldn't depend on any of the 4 plane directions anyways.
Result:

Spoiler
class Game_Player < Game_Character  alias tiagoms_jump update   def update    tiagoms_jump    if Input.trigger?🙂C)            jump2          end            end #end update  def jump2      case @direction        when 4          x = @x - 5              until passable?(x, @y, 5) # you probably want to put in 5 as the direction instead                x += 1              break if x == @x # break loop once we're back to the original x              end              p "#{x} pass"          end      endend

Edit ===

image attachment.


===== EDIT 2 =====

Out of curiosity realized:

Spoiler
      when 4 # Esquerda        if passable?(@x-3,@y,2)            jump(-3,0)            p "left -3"          else            if passable?(@x-2,@y,2)              jump(-2,0)              p "left -2"            else              if passable?(@x,@y,2)                jump(-1,0)                p "left 0"              end            end        end    
But in this case, the hero gets out of jumping map.

if passable?(@x,@y,2...3..4..5..6..)

Sem título.jpg
Well from that image, the 11 is the new x he should jump to. But since the jump takes values instead of coordinates, you would have to get the difference in the new x and the current x and use that for the horizontal parameter in jump.

Spoiler
case @directionwhen 4 x = @x - 5 until passable?(x, @y, 5) # you probably want to put in 5 as the direction instead x += 1 break if x == @x # break loop once we're back to the original x end p "jump to (#{x}, #{@y}" jump(x - @x, 0)end 

I also don't understand what you mean in your 2nd edit when you put:

if passable?(@x,@y,2...3..4..5..6..)confused on that 2...3..4..5..6..
the "..." in the Portuguese language (Brazil), in this case, indicates continuity. was an expression.
meaning I tested it with 2, tested it with 3, 4 tested, tested with 5 ...

the code works.
However, I did a little editing.
Reason: when X == @X, the character execute the jump.

Solution:


Spoiler
def jump2    case @direction    when 4      x = @x - 3      until passable?(x, @y, 3) # you probably want to put in 5 as the direction instead         x += 1         break if x == @x # break loop once we're back to the original x       end       if x != @x #NEW =====================================       p "jump to (#{x}, #{@y}"       jump(x - @x, 0)       end     end   end


====== With the objective to study:

Spoiler
def jump2 #Name    case @direction    when 4 # = Direction ( 4 = Left)      x = @x - 3 # Start verification with @X - 3      until passable?(x, @y, 3) # 3 = number of repetions if not passable (Start Loop)         x += 1 # Reduction (or adictional) - (Function from loop)         break if x == @x # Stop/Break Loop with this condiction: if "X == @X"       end       if x != @x #NEW =====================================       p "jump to (#{x}, #{@y}" # Print: "Jump to" ("variable x", @y)"       jump(x - @x, 0) # Command "JUMP" with X (result of loop) - @X (standard), 0 (this is "Y" ?)       end     end   end
in "passable?(x, @y, 3)", If it was not used in a loop, what is the function of "3"?

==== EDIT ====

with "2" (for down or up), not works correctly

 when 2 # Down          y = @y + 2 # "2" in here          until passable?(@x, y, 2) # "2" in here            y -= 1            break if y == @y          end          if y != @y          p "jump to (#{@x}, #{y})"          jump(0, y - @y)        endwith "3" or more, the code works.

==== New Edit ====

I'm test with:

when 2 # Down          y = @y + 2 # "1 or more" in here          until passable?(@x, y, 5) # "5" in here # What is this "5"????????            y -= 1            break if y == @y          end          if y != @y          p "jump to (#{@x}, #{y})"          jump(0, y - @y)        end
What is this position (of the "5")?
Only 4 directions matter in that direction parameter. (2, 4, 6, 8) any other number will all act the same.

If you look at the passable?() method in Game_CharacterBase, you'll see this line:

x2 = $game_map.round_x_with_direction(x, d) y2 = $game_map.round_y_with_direction(y, d)and that round_y_with_direction() and you can go look at those 2 methods in Game_Map. But pretty much for the round_x_with_direction() it adds 1 to x if direction is 6, subtracts 1 if the direction is 4 or does nothing if its not 4 or 6. This is why I put in 5, because we don't want it to alter the x and y values. you could put any number besides 2, 4, 6 or 8. but I like 5, since it's in the middle and 1, 3, 7, 9 are often thought of as diagonal directions.

So

What is this position (of the "5")?

Just means the current tile x, y that you put in the parameter.
Thanks, with your help, I managed to solve my problem and release my first script.

Original thread: https://forums.rpgmakerweb.com/threads/rgss3-doubts-problem-my-first-script.38946/