Making a space battle troubleshooting (random variable problem and also a background movement issue)

Discussion in 'RPG Maker MV' started by JayIsrael, Jun 10, 2019.

  1. JayIsrael

    JayIsrael Veteran Veteran

    Messages:
    87
    Likes Received:
    23
    First Language:
    English
    Primarily Uses:
    RMMV
    Hey there,
    Hope I am posting in the right place.
    I am working on a Star Trek fan game and I got it in my head that I could make a space battle by tricking the player into believing they are controlling their ship when in fact they are actually controlling the enemy ship. Part of this was by inverting the movement controls, then setting an overlay layer of stars, to move only when you move and in the direction the "klingon ship" is moving against.
    It is a little hard to describe.
    Anyway - in order to make sure the player doesn't realize that they are controlling the Klingon ship, the map is covered with invisible switches that when touched will make the klingon ship move in random directions, "fire" on the Enterprise, cloak, or stay still for a few seconds before moving. This works great - except when it doesn't.
    For some reason the switch, which is set to act when the player touches it, and to randomly select a different self switch, sometimes chooses an option I didn't know it had: Do nothing.
    You can see in the video below. I took one of the random switches and put an image over it (blue portal) so that you could visually see that it sometimes stays exactly the same when the Klingon ship touches it.

    I attached a photo of the common event which should be making random switches happen. Also note that the random things are not happening as randomly as I'd like. I only have one number set for cloaking and yet the ship seems to want to cloak every chance it gets.

    I also have a second problem - which is that I want the background to move when the player is moving the ship, but not when the ship is moving by itself. I set the background movement (as shown in the illustration) to only move with the player when the switch "BG move" is on, and then set it to turn off "BG move" before every random movement by the Klingon ship, before turning it back on – but for some reason the game continues to move the background overlay with the ship's movement, even when the ship is being controlled by the computer.

    I also attached photos demonstrating this.
     

    Attached Files:

    #1
  2. mathmaster74

    mathmaster74 just...John Veteran

    Messages:
    285
    Likes Received:
    184
    Location:
    Sheboygan, WI USA
    First Language:
    English
    Primarily Uses:
    RMMV
    @JayIsrael Okay. For the random part, you're saying first, if greater than or equal to 6, then set self switch A. Then you set the next conditions for equal to 6, equal to 7, and equal to 8...so nothing happens for 1 through 5. Instead, make the first part say greater than or equal to 4 and then make each subsequent value 1, 2, then 3. Now every value will be covered and you'll always do something. My guess is the cloaking was the favorite when things happened because it was the greater than or equal to 6 thing which always happened along with any of the 6, 7, or 8 things. Concerning the rest, I need to look at it more, but in the meantime it would help to let the crowd know you're using Galv's layers plugin for those layer plugin commands.

    EDIT: I don't think the self switches in your common event do anything. Self switches only affect the event in which they are placed, and generally are used to activate other pages, which your common event doesn't have. They could be used within this event if there were other code below them that only worked in relation to them...but there's not. If there's something you're trying to control with those switches that functions in another event, you need to set up a plain old switch...not a self switch. The stars seem to hold still and move properly with your movement, so it's just the "reset" ship location after cloak or destruction you're trying not to follow...right?

    EDIT 2: Hmmm...then again...looking at your Random event...there's nothing for those self switches to control either, yet you're getting the random effects? Perhaps self switches work across the whole of common events? Interesting.

    EDIT 3: You also shouldn't need the ELSE on the LAYER plugin command for holding still. You can take that whole branch and those code lines out. It will hold still by default and only move left if Player is moving and facing left or move right if Player is moving and facing right. By placing that hold still code in an else where you have, you're saying if Player is moving but not facing left (i.e. moving right, up, or down) then layer holds still. This is technically okay when moving right because right after that you say, but also if moving and facing right, stars move right...so you get the desired effect, but only after you run some needless lines of code. This may, however, still give undesired effects when moving up or down, so bottom line...remove that code.

    EDIT 4: Next advice...you named an event Klingon Ship Move and begin with a line of code that checks if Klingon ship move switch is ON. You should rename that switch. Why? First, it's confusing to have a switch and event called the same thing (even if they have slight differences in capitalization). Second, if you ever wrote some JavaScript that referenced the Klingon ship move switch and capitalized wrong, you'd be trying to write code for a switch that's looking to an event, which would throw an error and possibly confound you because everything looks right when you pore over the code trying to find the error. Third, you should just avoid having spaces in switch names. There's a programming naming convention called CamelCase. Don't know if you've heard of it, but basically if you run words together in a name, (be it a variable name, switch name, function/method name, etc.) every new word gets capitalized...so KlingonShipMove for the switch would be better though still confusing. I get why you're naming things the way you are. It's easier to see when the event is supposed to run and what it's supposed to do when looking at the plain text code. There are ways to do this with less confusion. One solution might be to call your switches BirdOfPreyMove, BirdOfPreyCloak, etc. while leaving your event named Klingon Ship Move (spaces here for the event name are okay). At least then you still know what everything does and you know your switch controls have the "BirdOfPrey" designations where your event is the generic "Klingon Ship" designation.
     
    Last edited: Jun 10, 2019
    #2
    JayIsrael likes this.
  3. Wavelength

    Wavelength Pre-Merge Boot Moderator

    Messages:
    3,880
    Likes Received:
    3,263
    Location:
    Florida, USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    Problem 1: As @mathmaster74 noted, you are checking four different conditions: whether the random var is 6 or greater, whether it's equal to 7, whether it's equal to 8, and whether it's equal to 6. If it picks 6, 7, or 8, two different switches will be turned on; if it picks 1, 2, 3, 4, or 5, then no switches will be turned on. If you want to make sure one of the switches is always turned on, change the first condition to "If the random var is LESS THAN 6" (or if it's Less Than Or Equal To 5" - either is fine).

    Problem 2: Your Parallel Event is not well-formed. It might take further steps to actually get things working exactly the way you want, but I think I can tell you why you're seeing the behavior that you're seeing. In your three-layer "If" Branch to control the starfield, you only have the Plugin Command's X-move parameter be set to 0 when the player is "not moving" (according to RPG Maker, which means that the Event marked as the "Player" is moving around; it does not mean that the person playing the game is necessarily hitting arrow keys). You do NOT have the same plugin command in the case where the player "is moving" but the BG Follows switch is set to OFF. Therefore, the starfield will continue to move in the direction it was last set (when the player had moved it using Left/Right), perhaps a few seconds ago. A few possible approaches you could take as a first step toward fixing this include:
    • Giving every Conditional Branch in the chain an "Else" block and adding the "0 Movement" Plugin Commands to every Else statement in that chain
    • Doing the above, and setting a Variable (to -1 for Left, 0 for No Movement, and 1 for Right) at every point in the chain instead of using the Plugin Command; then, after all the logic has been handled, using simple conditional branches to give one of the Plugin Commands based on the variable. You could even check to see whether the variable is different from last time you ran it so that you don't have to sacrifice performance by constantly giving Plugin Commands
    • Checking whether a button is pressed rather than using a script to check $gamePlayer.isMoving() - the standard Conditional Branch dialog contains an option for checking whether keys such as the Left Arrow or Right Arrow are currently being pressed by the player
    I also encourage you to add 2 Frames or so of Wait time to the end of the Parallel Event if feasible, to avoid having serious lag problems later on. Otherwise, your event will run 60 times per second, which (especially if you're not using the "set a variable" approach I suggested above) will cause significant lag as you build out your game and add in more Parallel events. It will mean that a ridiculously quick hit of Left or Right by the player won't always be registered, but that's a small price to pay to avoid crippling lag.

    Finally, just want to say that the idea for simulating "control" of a starship in this way is really neat! It reminds me a lot of some electronic toys I played with before the video game era, and it's a masterful illusion that really can be convincing without putting too much tax on middleware like RPG Maker.
     
    Last edited: Jun 11, 2019
    #3
    JayIsrael likes this.
  4. mathmaster74

    mathmaster74 just...John Veteran

    Messages:
    285
    Likes Received:
    184
    Location:
    Sheboygan, WI USA
    First Language:
    English
    Primarily Uses:
    RMMV
    @JayIsrael Hopefully some clarification for you...

    :oops: I followed the wrong indent. @Wavelength is right. You have the "don't move layer" code properly placed under "is not moving" here. That being said, the paragraph below kind of makes the point moot.

    o_O I think you meant "less" than or equal to.

    :thumbsup-right:I think this is the simplest way to go for you Jay. By changing your checks from isMoving script checks to simple Key press checks you ignore running any "moving layer" code unless a movement key is pressed...which means you ignore movement unless the player is controlling the movement of the ship. This also takes away the need for facing checks, since the arrow key tells you both the desired facing and that movement is being called for by the player. Further, this permits you to teleport the ship outside the player's control without having a simultaneous screen shift, and...it allows you to remove all of that nasty nesting that confuses logic flow. You can simply have four ifs that check for Up Arrow, Down Arrow, Left Arrow, and Right Arrow and for each have the layer move as desired. You really shouldn't need a bunch of elses that say "hold the layer still". The only caveat with that is, what happens when the player is pressing two buttons together? If you're using 4-directional movement, then the player can only go 1 of 4 ways whereas the layer would seem to go diagonally. I also don't know about the necessity of the 2 frame wait for lag, but I think it's certainly feasible to include a line of code to Wait 2 frames at the end of the rest of the code here. An ounce of prevention... :wink: Best!
     
    #4
    JayIsrael and Wavelength like this.
  5. Wavelength

    Wavelength Pre-Merge Boot Moderator

    Messages:
    3,880
    Likes Received:
    3,263
    Location:
    Florida, USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    Yes, you're right. I've edited my post accordingly - thank you for the catch! :D
     
    #5
    JayIsrael likes this.
  6. JayIsrael

    JayIsrael Veteran Veteran

    Messages:
    87
    Likes Received:
    23
    First Language:
    English
    Primarily Uses:
    RMMV
    Thank you both for these well thought out and incredibly helpful responses. I was able to implement Mathmaster's first recommendation regarding fixing the random numbers, and learned something helpful about the event that I could only learn after getting the event working. When I have the Klingon ship be "still," that is still considered an action, and so the player isn't able to take control so that they can take aim at the Klingon ship.
    The easy solution would be to just have nothing happen when that "klingon ship is still" option comes up, but what if the player decides to not move at all, and suddenly they realize that the Klingon ship won't move unless they move? That breaks the illusion. So maybe it sets an invisible timer, and after a few seconds of allowing the player the ability to move the Klingon ship, it will make a random movement.

    The other things you brought up is something I still need to wrap my mind around, because I am not a programmer so this stuff tends to make me very confused.

    I remember when I had initially used a condition to change when you pressed the "left" button to make you go right (my first attempt to invert the movement before finding a script to do it), it didn't work, as it made the character take a step in the right direction, but then suddenly switch directions, as if the program did not know what to do if you held the button down. I wasn't quite sure what was wrong and am a bit nervous about using the "press button" condition again for switching the layer direction. However, I do use a "touch button" condition for making the Enterprise fire its phasers when "ok" is hit, and that seems to work fine .
     
    #6

Share This Page