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.

movement

This is a request for a script for a game i am slowly working on...

the script is meant to not allow the player to move up nor down while a switch is on.. this should not interrupt the "if the up button is being pressed" conditional branch.. thats basically all I need.. oh.. and the sprite shouldn't change either... if the switch is off than normal movement is used... it sounds pretty simple but its giving me problems with eventing... this is for XP
 

Star

Sponsor

rodascesar1":290dudzx said:
This is a request for a script for a game i am slowly working on...

the script is meant to not allow the player to move up nor down while a switch is on.. this should not interrupt the "if the up button is being pressed" conditional branch.. thats basically all I need.. oh.. and the sprite shouldn't change either... if the switch is off than normal movement is used... it sounds pretty simple but its giving me problems with eventing... this is for XP
OMG I DID IT, I actually think I can help someone in scripts..

Put this above main. If you want a demo I can upload that as well

Code:
module STAR

#change this to the switch ID you want

  SIDEWAYS_SWITCH_ID = 0001

end

class Game_Player < Game_Character

  def update

     # Remember whether or not moving in local variables

    last_moving = moving?

    # If moving, event running, move route forcing, and message window

    # display are all not occurring

    unless moving? or $game_system.map_interpreter.running? or

           @move_route_forcing or $game_temp.message_window_showing

      # Move player in the direction the directional button is being pressed

      case Input.dir4

      when 2

        if $game_switches[STAR::SIDEWAYS_SWITCH_ID] == true

        else  

        move_down

        end

      when 4

        move_left

      when 6

        move_right

      when 8

        if $game_switches[STAR::SIDEWAYS_SWITCH_ID] == true

        else  

        move_up

        end

      end

    end

    # Remember coordinates in local variables

    last_real_x = @real_x

    last_real_y = @real_y

    super

    # If character moves down and is positioned lower than the center

    # of the screen

    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y

      # Scroll map down

      $game_map.scroll_down(@real_y - last_real_y)

    end

    # If character moves left and is positioned more let on-screen than

    # center

    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X

      # Scroll map left

      $game_map.scroll_left(last_real_x - @real_x)

    end

    # If character moves right and is positioned more right on-screen than

    # center

    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X

      # Scroll map right

      $game_map.scroll_right(@real_x - last_real_x)

    end

    # If character moves up and is positioned higher than the center

    # of the screen

    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y

      # Scroll map up

      $game_map.scroll_up(last_real_y - @real_y)

    end

    # If not moving

    unless moving?

      # If player was moving last time

      if last_moving

        # Event determinant is via touch of same position event

        result = check_event_trigger_here([1,2])

        # If event which started does not exist

        if result == false

          # Disregard if debug mode is ON and ctrl key was pressed

          unless $DEBUG and Input.press?(Input::CTRL)

            # Encounter countdown

            if @encounter_count > 0

              @encounter_count -= 1

            end

          end

        end

      end

      # If C button was pressed

      if Input.trigger?(Input::C)

        # Same position and front event determinant

        check_event_trigger_here([0])

        check_event_trigger_there([0,1,2])

      end

    end

  end

end

 
 
dude it only seems to work on switch one... but that doesn't matter..

:D it's perfect... you got what I wanted with amazing accuracy.. man!! :D expect big credit on my game if its released.. I will be working on it this summer.. :P thanks a lot...

its amazing :P
 

Star

Sponsor

rodascesar1":2hchi01c said:
dude it only seems to work on switch one... but that doesn't matter..

:D it's perfect... you got what I wanted with amazing accuracy.. man!! :D expect big credit on my game if its released.. I will be working on it this summer.. :P thanks a lot...

its amazing :P
You have to change SIDEWAYS_SWITCH_ID = 0001 to the Switch you want to use
Lets say you want Switch 25 to do the trick..

Put SIDEWAYS_SWITCH_ID = 0025

No problem, man

Be well <.< >.>
 

Atoa

Member

instead of

Code:
        if $game_switches[STAR::SIDEWAYS_SWITCH_ID] == true

        else  

        move_down

        end
why you just use an "unless"? .-.

Code:
       case Input.dir4

       when 2

         move_down unless $game_switches[STAR::SIDEWAYS_SWITCH_ID]

       when 4

         move_left

       when 6

         move_right

       when 8 

         move_up unless $game_switches[STAR::SIDEWAYS_SWITCH_ID]

       end

     end
also don't add zeros before integer like this:
SIDEWAYS_SWITCH_ID = 0001
the correct is
SIDEWAYS_SWITCH_ID = 1
 
I see a bit of criminal intent here again, not only including a constant for a single switch name, but also wrapping it into a whole new module... >_< (I like how rodascesar perfectly proved that those silly constants aren't any more apparent to the average non-scripter than the variation without constants - thanks for that, it's really apprechiated!)

I do get that people tend to complicatedness within these forums, but if anyone still cares for a clean coding version...
[rgss]class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  alias switchmove_update update
  def update
    last_moving = moving?
    unless moving? or $game_system.map_interpreter.running? or @move_route_forcing or $game_temp.message_window_showing
      case Input.dir4
      when 2; move_down unless $game_switches[1] == true
      when 4; move_left
      when 6; move_right
      when 8; move_up unless $game_switches[1] == true
      end
    end
    switchmove_update
  end
  #--------------------------------------------------------------------------
end
[/rgss]

On a side note @rodascesar: As you're apparently trying to make something work on the up and down buttons while not being able to move there, note that you can perfectly use a line as the following to include that right there and save an awful lot of unnecessary event handling:
Code:
$game_switches[1] ? execute_your_method : move_up
 

Star

Sponsor

I don't necessarily understand if you're trying to tell me if I'm a criminal or not. But I have learned that just like events, in scripting there are more than one way to do things. One way might work, and another maybe simpler and clean. But they both work don't they? Unless maybe you're saying that an unclean version could and would be affected by other scripts put into the game, for which then I understand why you would want perfection. Is that what you're saying?
 
Well thanks to both of you... I would rather not continue this conversation the way it seems to be going..

on that side note: thanks for all of that blue scope.. eventing is probably the best thing i can do... I think it can be as efficient as scripting.. since it basically is... but events cant go through other events and that was getting the way of my plans so...

It would be a great thing to finish that game and include all of you on the credits.. thanks!
 
Don't worry here, I'm not looking for trouble at all ^^"

The thing is just that I'm trying to win a hopeless war against useless constant usage and cluttered coding. The criminal thing was a somewhat sarcastic thing, but yeah...

@Gundam: There are indeed more than one way to go about stuff, but just because something works doesn't mean it's good. I'm being picky about that because I see a lot of (especially PC-)Games released nowadays that are effectively in beta phase, simply because their makers didn't care all that much, and I also think that people being in these forums are likely to end up in game design something, so yeah...
As far as constants go, they're meant to be an array of stuff that doesn't changes ingame anymore (even though Ruby allows it - never think about doing it though!) and from which you can read at multiple places within the script. However, your constant is only used twice, within the same method even (allowing you to use a local variable if necessary) and therefore spawns a few more lines of coding ran through the interpreter than necessary. While this isn't much, it's still something worth thinking about.
As for the shortening, you can see I did this with an array. I can't go into detail right now, as I'm at work and don't have too much break time, however, aliasing greatly improves compatibility for "paste above Main" scripts (yours would be a "replace the original" script) as well as makes the whole thing downright more compact.

@rodas: No need to credit me, as I merely shortened Gundam's script... doesn't make it mine.
 

Star

Sponsor

rodascesar1":1ohhksi0 said:
Well thanks to both of you... I would rather not continue this conversation the way it seems to be going..
Don't worry, I respect Bluescope more than you'll ever know.

rodascesar1":1ohhksi0 said:
I actually tried your version blue scope but it doesn't work... or doesn't work for me... don't know why really..
He doesn't have RMXP anymore, he probably can't test it. :eek::

@Bluescope: Just Call me Star! :) The only reason why I brought it to you like that is because I'm still learning, and I wanted a good reason why I should write perfect coding. I'm gonna try to improve on what I've learned and probably still make tons of mistakes but hopefully I'll be in your shoes one day.
 
@Star: Well, my shoes are quite big (48.5, German sizing :p ), so you might wanna think about a different way to put this XD However, I'm glad if I can contribute to you improving your RGSS abilities, however, I'm not quite seeing how I'm the shining scripter your post describes me as ^^"

@rodas: If that's the case really, I assume that the aliasing messes it up (I couldn't test it)... you can definately use this part though:
[rgss]     unless moving? or $game_system.map_interpreter.running? or @move_route_forcing or $game_temp.message_window_showing
       case Input.dir4
       when 2; move_down unless $game_switches[1] == true
       when 4; move_left
       when 6; move_right
       when 8; move_up unless $game_switches[1] == true
       end
     end
[/rgss]And take out the constant if it works ^^
 

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