Help with an if statement on a script

Well, I don't know if this should go here, but if it's in the wrong forum please move it to the right one.


With that aside. Hi, I've been having troubles modifying a script with an if statement.


The script is Dual Wield Separate Attacks by Lytanathan. The script let you specify a number of skills and then, if you are dual wielding when using one of those skills, it calculates the damage of 2 separate hits, 1 for each weapon. Thanks to this thread, one can modify the script to fix one problem while unarmed and to sort of modify the damage of the second hit via applying and removing a state. The problem is that, if using this solution, the actual weapon that gets its damage reduced with a state, its the first one, not the second one, that leads to confusion with some things, but basically, I tried to add an if to let the first attack happen and then, with the state, reduce the damage of the second attack.


This was my attempt:

Spoiler
      $wfa = "main"                                                             #I added this line here
      #Remember equipped weapons
      weapon_list = @subject.weapons


        #Perform attacks
        if $wfa == "off"                                                          #And changed the line that was here for the if
          target.add_state(12 + current_weapon)
          lyt_dwsa_apply_item_effects(target, item)
          target.remove_state(12 + current_weapon)
        elsif $wfa == "main"
          lyt_dwsa_apply_item_effects(target, item)
          $wfa = "off"
        end

It just end up going for the elsif all the time and I don't know why because the second time it should take the normal if.


I don't know a lot of ruby so I checked the manual on the editor for help about variables and conditionals, but I don't understand why this isn't working.


If anyone can help me with a lead or something I would really appreciate it.
Well, I don't know if this should go here, but if it's in the wrong forum please move it to the right one.


With that aside. Hi, I've been having troubles modifying a script with an if statement.


The script is Dual Wield Separate Attacks by Lytanathan. The script let you specify a number of skills and then, if you are dual wielding when using one of those skills, it calculates the damage of 2 separate hits, 1 for each weapon. Thanks to this thread, one can modify the script to fix one problem while unarmed and to sort of modify the damage of the second hit via applying and removing a state. The problem is that, if using this solution, the actual weapon that gets its damage reduced with a state, its the first one, not the second one, that leads to confusion with some things, but basically, I tried to add an if to let the first attack happen and then, with the state, reduce the damage of the second attack.


This was my attempt:

Spoiler
      $wfa = "main"                                                             #I added this line here
      #Remember equipped weapons
      weapon_list = @subject.weapons


        #Perform attacks
        if $wfa == "off"                                                          #And changed the line that was here for the if
          target.add_state(12 + current_weapon)
          lyt_dwsa_apply_item_effects(target, item)
          target.remove_state(12 + current_weapon)
        elsif $wfa == "main"
          lyt_dwsa_apply_item_effects(target, item)
          $wfa = "off"
        end

It just end up going for the elsif all the time and I don't know why because the second time it should take the normal if.


I don't know a lot of ruby so I checked the manual on the editor for help about variables and conditionals, but I don't understand why this isn't working.


If anyone can help me with a lead or something I would really appreciate it.



Is it because you spelled elseif wrong?
Is it because you spelled elseif wrong?

I don't think so because in ruby it's suppose to be "elsif".
I'm no expert, but this is the way I am seeing the issue. Every time you attack, the script is called and checked, and every time it comes to this line "$wfa='main' ", it is setting the $wfa to 'main', then it goes through and checks the next bit of code, the "If, elsif" statement. And since it sets the $wfa to 'main' at the beginning, it always will go to the elsif because it is always reading that it is 'main'. Even though at the end of the bit of code you add in the "$wfa = 'off' ", the first thing it does when it gets run again is set $wfa to 'main'.


I'm pretty sure that is what the problem is.


Just read the thread you posted and they seem to tell you how to do exactly what you are looking for in the last two posts. Shad3 says that the line: "target.add_state(101 + current_weapon)" adds the state slot numbered 101 to the first weapon and state 102 for the second weapon. So whatever state you want to affect the secondary weapon, place in state slot 102. Which is what Dinhbat3 says he is going to do.


Quoted Dinhbat3: "Now does anyone have insight on how to have the second strike do half damage?" and "So I have 101 blank and 102 add the PDR 50% since it is applied just before action and unapplied after."


Basically, it sounds all the coding you inputted wasn't necessary. Under #Perform Attack, all you needed was this: 


          target.add_state(12 + current_weapon)          lyt_dwsa_apply_item_effects(target, item)          target.remove_state(12 + current_weapon)


Except change the 12 to 102 and add your reduced damage state in the 102 slot.
Thanks again GreyStone!


I tried still using state 12, because basically it seems that whatever state you put in the lines it's gonna be used on the first attack and the next slot state is going to be used on the second one.


I thought that the game only checked the script once, because I thought that the two damage calculations were made on the "for" below the line were I initialized the variable. Glad to know the real issue now. As for the other thread, it seems I didn't understood really well how the 3 lines of Shad worked, basically I thought that the only state applied was the one specified on the lines, I don't really know why it works like it does, but well, that's why in my "if", in one condition I used the original line, and on the other condition I used the lines of Shad.


Anyways, you've saved me again, thanks man!
No problem, hope it all works out for you because I honestly don't know why it works like that either, lol. I am just going off what the thread says.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-an-if-statement-on-a-script.63382/