RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[VX]Attempting to create skill with damage based on variable, having problem

0 Members and 1 Guest are viewing this topic.

**
Rep:
Level 56
RMRK Junior
I actually am not really sure what the problem is. I know the code is working. The only part that isn't is the part
where its supposed to read the chosen variable as the integer. Here's the code:

     
Code: [Select]
#----------------------------------------------------------------------
      # <damage: -x variable hp>   <damage: +x variable hp>
      # <damage: -x variable mp>   <damage: +x variable mp>
      # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      # This will cause MP and HP damage based on variable X. This damage is
      # affected by variance criticals, elements, and guarding.
      # --- Example --- - - - - - - - - - - - - - - - - - - - - - - - - - - -
      # <damage: -20 variable hp>
      # <damage: -20 variable hp>
      #----------------------------------------------------------------------
      when /([\+\-]\d+)[ ]VARIABLE[ ](.*)/i
        var = $game_variables[$1.to_i].to_i
        case $2.to_s
        when "HP"
          hp_dmg = var
        when "MP", "SP"
          mp_dmg = var
        end
        healing_formula = true if var < 0
        ignore_elements = false
        ignore_variance = false
        ignore_critical = false
        ignore_guarding = false
        ignore_inflates = false

The code is derived from another melody code, which it only differs from slightly (and I know this one works under the same conditions I set for my new code):

     
Code: [Select]
#----------------------------------------------------------------------
      # <damage: -x% current hp>   <damage: +x% current hp>
      # <damage: -x% current mp>   <damage: +x% current mp>
      # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      # This will cause the target to lose x% of their current HP or MP. If
      # a negative value is used for x, then the target will take damage of
      # that percent. If the value is positive, the target will recover that
      # percent instead. The damage is unaffected by variance, criticals, and
      # elements and guarding.
      # --- Example --- - - - - - - - - - - - - - - - - - - - - - - - - - - -
      # <damage: +50% current hp>
      # <damage: -25% current mp>
      #----------------------------------------------------------------------
      when /([\+\-]\d+)([%?])[ ]CURRENT[ ](.*)/i
        percent = $1.to_i
        case $3.to_s
        when "HP"
          hp_dmg = target.hp * percent / -100
        when "MP", "SP"
          mp_dmg = target.mp * percent / -100
        end
        healing_formula = true if percent > 0
        ignore_elements = true
        ignore_variance = true
        ignore_critical = true
        ignore_guarding = true
        ignore_inflates = true

I think its breaking down where its supposed to read the variable as an integer, but I don't understand why, seeing as I've done this sort of thing before with variables. When I try to use it in battle, I get 0 damage. I feel like the answer is pretty basic, but it isn't coming to me. I'm going to continue looking. 

EDIT: Just as a clarification, I know the code is being read and performed in battle. That can't be the problem. I know because when I futz with the code and put in a value that's not defined, it kicks back an error message when the enemy attempts to use the skill. So, as far as I can tell, it is performing the operations when the skill is being used, and I haven't overlooked anything when it comes to actually getting the operation to perform.

EDIT 2: Okay, I did some experimenting and it is definitely the part where it is supposed to convert the value of the variable into an integer. Thing is, I've done this before, so I have no idea why it won't read the variable's value as the damage value. Any help would be appreciated.
« Last Edit: June 27, 2013, 08:01:03 PM by dudeguy119 »

I support:



*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
I don't have time to look at this in any detail right now, as I am about to leave for a trip and need to pack, but one quick thing that I've noticed is that your REGEXP accepts any lowercase or uppercase string for your second group, but you are only checking for uppercase incarnations in your case branch. Thus, nothing would be read if you had:

-20 variable hp

It would need to be:

-20 variable HP

To fix that, you could change the case line from:

Code: [Select]
case $2.to_s

to:

Code: [Select]
case $2.upcase

Also, $ results from a match are all strings, so no need to covert them.