Trouble modifying variable in skill Formula

keys9

Warper
Member
Joined
Sep 10, 2018
Messages
3
Reaction score
0
First Language
English
Primarily Uses
RMMV
Okay so what I am trying to do is make it so that if the actor uses a magical attack then my Last Skill Type variable is set to 1 and if it is physical set it to 2. This seems to partially work but not really (I explain everything below). More specifically I'm trying to make an intro battle where the player challenges one of the commander's of the enemy's forces to a battle. The command is immune to all physical damage (I just gave him a REALLY high defense value) but he can be hit with magic. Depending on if the player uses a physical attack or a magic attack different things will happen. If the attack is physical you just get some dialogue between the two characters. If the attack is magic, the battle is aborted with the enemy fleeing. I thought I would handle this logic in a troop Battle Event. Here is the relevant parts of the event:

Battle Event in Troop Swordsman:

Conditions: Turn End Span: Turn

If: Marigold Town State = 3 (variable used to determine if this is the first battle the player is fighting in the intro sequence)
If: Last Skill Type = 1 (If the actor used magic)
(Do some text conversation stuff)
Control Variables: #0002 Marigold Town State = 4 (advance intro sequence after battle)
(More Conversation)
Change EXP: Entire Party, + 80 (Show Level Up)
Force Action: #1 Swordsman, Escape, Last Target
Control Variables: #0004 Last Skill Type = 0 (Reset last used skill to essentially a "null" value that does not represent any skill type for future use)
End
If: Last Skill Type = 2 (If actor used a physical attack)
(More Conversation Text)
End
End


Now here is how I attempt to update my variable Last Skill Type with the formulas in the skills tab:

0001 Attack: v[4] = 2; a.atk * 4 - b.def * 2
0009 Fire Formula: v[4] = 1; 100 + a.mat * 2 - b.mdf * 2


And now for all my variables:

0001: Player Gender
0002: Marigold Town State
0003: cutscene1 (For the abstract intro before the player even sees their character)
0004: Last Skill Type


And Now for what my problem actually is:

When I attack the commander with a physical attack I get the If: Last Skill Type = 2 (If actor used a physical attack) 'code' triggered as expected BUT this also triggers even if I use my fire attack. So the physical attack 'code' is executing regardless of whether I use a physical or a magic attack. I really am confused. I quadruple checked my variables. Any and all help is appreciated. I know I supplied a lot of information but that's so that I can make my problem as clear as possible. If this is not enough I'm happy to upload my entire project (which is very small at the moment) if necessary.
 
Last edited:

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
My instinct is that this might be happening because you are triggering the event only at the end of a turn, meaning that if any actions were performed after your character's Fire/Attack but before the end of a turn (such as if the enemy General is using an Attack), then the variable might be changed before the troop events process. The solution to this would be to find a way to trigger the event immediately after the player takes action (perhaps by using the value of the variable as the page's condition, or perhaps by using Hime's Custom Page Conditions plugin, which I highly recommend to all developers).

The only other thing that looks suspicious to me is the fact that you are changing Variable #4 back to zero AFTER forcing an action which should in theory abort the battle (since everyone has escaped), perhaps ending the combat before the rest of the eventing is processed. I would expect some weird results from this, but I wouldn't expect the dialogue to run as if a physical attack had been used, so I don't think this is the culprit here. Still might be worth trying to move that line further down.

If neither of these seem to be the issue, I would recommend showing a message box with the current value of the variable after every (non-dialogue) line of eventing that you have. This might assist you in figuring out whether the variable is actually what you think it is at all times. (You can even open up the JavaScript Console by pressing F8 and track the variable when the event isn't running, to see when it is changing - after or between skills.)
 

keys9

Warper
Member
Joined
Sep 10, 2018
Messages
3
Reaction score
0
First Language
English
Primarily Uses
RMMV
Edit: Apparently The swordsman is only receiving the used physical state when
the player attacks with physical. I need it so that the swordsman receives this state
when the swordsmen attacks with physical and I'm not sure how to do that. Also thanks for the helpful response before.



Yup that was the problem. The enemy was using a physical attack immediately after I used magic. I now am stuck though with how to make this work. Here is my new attempt which is much closer but there is one thing that is stumping me. On the first turn if I use magic then the appropriate actions fire (I removed the 'code' that ends the battle and replaced the conversations with just two text boxes that say option 1 and option 2 just to see the control flow for debugging). So first move with actor using magic - option 1 fires. Now the enemy goes (normally the battle would end if magic is used but again I removed that for testing purposes). The enemy uses a physical attack and option 2 (physical events) which should not happen because its only supposed to fire when the player attacks, fires. Now the actor goes and uses magic. Nothing happens. Option 1 should fire again but it does not. Next the enemy goes and uses a physical attack. Option 2 fires again which again should not happen since the events are only supposed to trigger when the player/actor attacks.

Troop Event 'Code':

Conditions: Used Physical or Magic (Switch) Span: Moment
where Physical or Magic is turned on whenever 0009 fire or 0001 attack are used by either the enemy or the actor.


If Marigold Town State = 3

If Swordsman is affected by Used Physical (applied to whatever entity uses the attack option)
Control Variables: #0004 Last Skill Type = 0 (Set Last Skill Type to the 'Null' Value so that the following events don't fire (but they still do anyway idk why) )
Change Enemy State #1 Swordsman, -Used Physical
End

(Now that the above if block check is done these events SHOULD NOT fire but the physical attack option still does after the swordsmen attacks)

If: Last Skill Type = 1
Text: None, Window, Bottom
Option 1
Change State Entire Party, - Used Magic
End


If: Last Skill Type = 2
Text None, Window, Bottom
Option 2
Change State Entire Party, - Used Magic
End

Control Switches: #0003 Used Physical or Magic = OFF


End






Now for the skill formulas:

0009 Fire: $gameSwitches.setValue(3, true); v[4] = 1; 100 + a.mat * 2 - b.mdf * 2
where gameSwitch is the Used Physical Or Magic Switch and v[4] is the Last Skill Type Variable

Notes for Fire (Using YEP_Z_ActionBeginEnd Plugin)
<End Action: Add State 11>

where 11 corresponds to the state Used Magic


values for v[4]:

0 = 'Null'
1 = 'Magic'
2 = 'Physical'



0001 Attack: $gameSwitches.setValue(3, true); v[4] = 2; a.atk * 4 - b.def * 2
where switch and variable are the same as above

Notes for Attack(Using YEP_Z_ActionBeginEnd Plugin)
<End Action: Add State 12>

where 12 corresponds to the state used Physical
 
Last edited:

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
Your setup looks solid but obviously, since you're not getting the results you want, something is going wrong. I'm at a bit of a loss, but the first thing I would try would be to (temporarily) stop using Yanfly's plugin to add states, and try adding the state directly in the Features Box as part of the skill's effects (note that this will apply the state to the TARGET, so change your troop eventing accordingly). See if that changes anything.
  • You can also make your life easier by giving this Tutorial General enemy a skill called "Attack" that is different than the default #001 Attack skill that the game uses whenever you tell an enemy to Normal Attack.
If not, try some more event-based debugging. Add a message box after every line of eventing (and add text appropriate to that part of the eventing; e.g. "Player has Physical State applied; resetting to 0" if the player had the 'hit by Physical' state applied. If you're getting any messages that you don't expect, it should be a good hint about what is going wrong, and hopefully that hint will help you solve the problem. If you're getting all the messages you would expect, but the behavior still seems wrong, go ahead and post your project and I'll take a look through the troop.

One other thing I noticed while playtesting my game in Ace (not MV) is that, very occasionally, states which had just been removed from a character would not be reapplied to that character if attempted soon after. I could not figure out what was causing the bug (I instead worked around it by applying the states in a million different places through the skill's logic, including in Common Events triggered by the skill), but I believe the issue to be default behavior of the program that may have been carried over to MV. So as a last resort we could try using an approach that doesn't include States at all.
 

keys9

Warper
Member
Joined
Sep 10, 2018
Messages
3
Reaction score
0
First Language
English
Primarily Uses
RMMV
Thanks for another reply. After doing some more google digging I found you can apply states directly in the formula so that basically solved my problem though it is a bit messy. Here is the new formula for the 0001 attack skill for anyone that may need it in the future: a.addState(12); $gameSwitches.setValue(3, true); v[4] = 2; a.atk * 4 - b.def * 2. Simply add a state to the skill user with a.addState(id);
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,867
Messages
1,017,062
Members
137,575
Latest member
akekaphol101
Top