Variable won't decrease

Discussion in 'RPG Maker VX Ace' started by Jzkann, Mar 15, 2019.

  1. Jzkann

    Jzkann Villager Member

    Messages:
    8
    Likes Received:
    1
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    Hello there. I'm creating some Firearms in my game. Basically, they're Items that when you use them in battle, they call a common event that executes a particular skill and the ammo capacity (a variable) decreases. When this variable is 0, the weapon will reload and shoot if you have other ammo, while, if you have 0 ammo, it will tell you. Right now, I created two weapons: a Handgun (The Arguer) and a Shotgun (Super Shorty). The Handgun works as expected, but not the shotgun: it shoots normally, but the ammo capacity doesn't decrease. Here are the screens:
    Handgun common event:
    [​IMG]
    Shotgun common event:
    [​IMG]
    I checked, and I'm 100% sure the item calls correctly the common event.
    The skill works correctly, although I think it's not the skill's problem.
     
    #1
  2. Andar

    Andar Veteran Veteran

    Messages:
    27,096
    Likes Received:
    5,940
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    several comments:

    1) you should check the correct number of bullets in inventory with a combination of contol variable and conditional branch.
    Using only the conditional branch "in inventory" is true even if there is only 1 bullet in inventory, and that would result in your code giving the player a full reload for a single bullet left.

    2) have you checked if you have a plugin where you missed a configured variable?
    Some plugins use variables to control their options and if one of your plugins do this you are required to make sure it's correctly configured.
    Because if one of your plugins redirected the variable #3 without your knowledge that could cause those problems.

    3) use the search function to find all events that use variable #3 - if it is used at a different event that could also cause problems.

    4) if you still haven't found the cause, add show text commands to all branches giving the values of the variables used, that often helps in localizing the problem. For example it might be something entirely different that causes this, and you need the V[3] in all branches to track the logic.
     
    #2
  3. Jzkann

    Jzkann Villager Member

    Messages:
    8
    Likes Received:
    1
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    Thanks for the tips.
    For the first tip, how do I check how many bullets does the player have? Because I don't know how to do the process that you said (combination of control variable and conditional branch)
    For the second one, I'm sure no script uses the variable #3.
    For the third one, I checked, and no event controls that variable.
     
    #3
  4. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    660
    Likes Received:
    177
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    You can store the number of bullets the player is holding in a variable and then, use a conditional branch to check that variable. For arguments sake I am going to use variable 4 in my example.
    Code:
    Variable 4 = Amount of Bullets
    Conditional Branch: Variable 4 >= 7
      Variable #3 = 7
    Else
      Variable #3 = Variable #4
    end
    Not to be rude but from your event I can be 100% sure that is not your case. Variables are initialized with a value of 0. If your variable is neither equal to 0 nor greater than 0 (thus being less than 0) that means something modified its value somewhere else. It could be either an event or a script but something did change its value, even if you do not know what.

    That said if you do not know what modified its value and everything else works as intended I would recommend you to use a different variable in order to not break other things that are currently working properly. Even so I recommend using "Variable #ID <= 0" instead of just "Variable #ID == 0". This way you handle exceptions together with normal cases. It also allows you to use that variable somewhere else and then reset it automatically once you reload regardless of its value (I still do not recommend using the same variable for multiple purposes unless you are having very serious memory shortage).
     
    #4

Share This Page