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
rodascesar1 wrote:
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

  1. module STAR
  2. #change this to the switch ID you want
  3.   SIDEWAYS_SWITCH_ID = 0001
  4. end
  5. class Game_Player < Game_Character
  6.   def update
  7.      # Remember whether or not moving in local variables
  8.     last_moving = moving?
  9.     # If moving, event running, move route forcing, and message window
  10.     # display are all not occurring
  11.     unless moving? or $game_system.map_interpreter.running? or
  12.            @move_route_forcing or $game_temp.message_window_showing
  13.       # Move player in the direction the directional button is being pressed
  14.       case Input.dir4
  15.       when 2
  16.         if $game_switches[STAR::SIDEWAYS_SWITCH_ID] == true
  17.         else  
  18.         move_down
  19.         end
  20.       when 4
  21.         move_left
  22.       when 6
  23.         move_right
  24.       when 8
  25.         if $game_switches[STAR::SIDEWAYS_SWITCH_ID] == true
  26.         else  
  27.         move_up
  28.         end
  29.       end
  30.     end
  31.     # Remember coordinates in local variables
  32.     last_real_x = @real_x
  33.     last_real_y = @real_y
  34.     super
  35.     # If character moves down and is positioned lower than the center
  36.     # of the screen
  37.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  38.       # Scroll map down
  39.       $game_map.scroll_down(@real_y - last_real_y)
  40.     end
  41.     # If character moves left and is positioned more let on-screen than
  42.     # center
  43.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  44.       # Scroll map left
  45.       $game_map.scroll_left(last_real_x - @real_x)
  46.     end
  47.     # If character moves right and is positioned more right on-screen than
  48.     # center
  49.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  50.       # Scroll map right
  51.       $game_map.scroll_right(@real_x - last_real_x)
  52.     end
  53.     # If character moves up and is positioned higher than the center
  54.     # of the screen
  55.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  56.       # Scroll map up
  57.       $game_map.scroll_up(last_real_y - @real_y)
  58.     end
  59.     # If not moving
  60.     unless moving?
  61.       # If player was moving last time
  62.       if last_moving
  63.         # Event determinant is via touch of same position event
  64.         result = check_event_trigger_here([1,2])
  65.         # If event which started does not exist
  66.         if result == false
  67.           # Disregard if debug mode is ON and ctrl key was pressed
  68.           unless $DEBUG and Input.press?(Input::CTRL)
  69.             # Encounter countdown
  70.             if @encounter_count > 0
  71.               @encounter_count -= 1
  72.             end
  73.           end
  74.         end
  75.       end
  76.       # If C button was pressed
  77.       if Input.trigger?(Input::C)
  78.         # Same position and front event determinant
  79.         check_event_trigger_here([0])
  80.         check_event_trigger_there([0,1,2])
  81.       end
  82.     end
  83.   end
  84. end
  85.  
Expand to see the code.
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
rodascesar1 wrote:
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 <.< >.>
instead of

  1.        if $game_switches[STAR::SIDEWAYS_SWITCH_ID] == true
  2.         else  
  3.         move_down
  4.         end
Expand to see the code.
why you just use an "unless"? .-.

  1.       case Input.dir4
  2.        when 2
  3.          move_down unless $game_switches[STAR::SIDEWAYS_SWITCH_ID]
  4.        when 4
  5.          move_left
  6.        when 6
  7.          move_right
  8.        when 8
  9.          move_up unless $game_switches[STAR::SIDEWAYS_SWITCH_ID]
  10.        end
  11.      end
Expand to see the code.

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...
  1. class Game_Player < Game_Character
  2.   #--------------------------------------------------------------------------
  3.   alias switchmove_update update
  4.   def update
  5.     last_moving = moving?
  6.     unless moving? or $game_system.map_interpreter.running? or @move_route_forcing or $game_temp.message_window_showing
  7.       case Input.dir4
  8.       when 2; move_down unless $game_switches[1] == true
  9.       when 4; move_left
  10.       when 6; move_right
  11.       when 8; move_up unless $game_switches[1] == true
  12.       end
  13.     end
  14.     switchmove_update
  15.   end
  16.   #--------------------------------------------------------------------------
  17. end
Expand to see the code.


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:
  1. $game_switches[1] ? execute_your_method : move_up
Expand to see the code.
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.
I actually tried your version blue scope but it doesn't work... or doesn't work for me... don't know why really..

soo.. I will be using gundams thanks though
rodascesar1 wrote:
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 wrote:
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. :o:

@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:
  1.     unless moving? or $game_system.map_interpreter.running? or @move_route_forcing or $game_temp.message_window_showing
  2.        case Input.dir4
  3.        when 2; move_down unless $game_switches[1] == true
  4.        when 4; move_left
  5.        when 6; move_right
  6.        when 8; move_up unless $game_switches[1] == true
  7.        end
  8.      end
Expand to see the code.
And take out the constant if it works ^^

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=70662