How do you turn on a Switch inside a damage formula on RPG Maker MV?

Could someone show me how to turn on a Switch inside the damage formula in RPG Maker MV? My current damage formula is:

v[17]*5*2 - b.def*1

I would just like to turn on the Switch independent from the damage being done. So if you could show me how to write it into the formula without affecting the current formula's calculations it would be a big help to me.
for most cases it would be better to use an attached common event.

that said, there is a pinned topic in the forum about using javascript inside the damage formula.
You've gotten a good answer, so just out of morbid curiosity...why *5*2 instead of *10? 😛 And why a *1?
You don't.
I would advise against trying to turn on a switch in the damage formula. This is because the damage formula is evaluated by the AI to determine which skill to use, which may result in the switch being turned on even if the skill was not used.
for most cases it would be better to use an attached common event.

that said, there is a pinned topic in the forum about using javascript inside the damage formula.

I was hoping to conserve common events because I'm running out of them. So I was going to try and turn on switches in the formula so I can use the same common event but have it interact differently depending the skill being used.

I looked through the pinned topic on damage formula before I posted this, but wasn't able to find what I was looking for. I found a few examples on the internet, but sadly they were for other versions of RPG Maker and not MV.

You've gotten a good answer, so just out of morbid curiosity...why *5*2 instead of *10? 😛 And why a *1?

It's just for testing purposes and to make it easier for me to adjust the formulas.

You don't.

That would explain why I wasn't able to find anything on how to do it then. lol ; ;

Thanks for clearing that up for me.

I would advise against trying to turn on a switch in the damage formula. This is because the damage formula is evaluated by the AI to determine which skill to use, which may result in the switch being turned on even if the skill was not used.

I see, and thanks for the advice. Guess I'll move on to Plan B then, once I figure out what Plan B is.
I was hoping to conserve common events because I'm running out of them.
that sounds as a very inefficient use of common events.
you might want to make a new topic giving examples of your CE use and ask for optimization tips.
I was hoping to conserve common events because I'm running out of them.
As Andar says, that sounds like you're doing something wrong/inefficiently. One should be able to recreate a full-sized game like one of the Final Fantasy or Dragon Quest titles and not come anywhere near to using all of those common events.

My project is admittedly incomplete, but uses all of 30.

So I was going to try and turn on switches in the formula so I can use the same common event but have it interact differently depending the skill being used.
Have you looked at all at common plugins for MV? Something like Yanfly's Skill Core that allows you to execute code directly from a skill would be far more efficient. You can also do it with action sequences.

I looked through the pinned topic on damage formula before I posted this, but wasn't able to find what I was looking for.
I Googled "rpg maker mv script call switch" and immediately found threads with the correct syntax. It's also in the pinned MV Script Call List. $gameSwitches.setValue(switch ID, true/false)

That would explain why I wasn't able to find anything on how to do it then. lol ; ;
Andar said you don't (as in it's not the correct thing to do, which was elaborated on by Amaranth), not you can't.
I was hoping to conserve common events because I'm running out of them.
How? I have a lot of custom mechanics in my game and I'm using like 30 common events.
that sounds as a very inefficient use of common events.
you might want to make a new topic giving examples of your CE use and ask for optimization tips.

I probably could have been more efficient with them. When I first started working on the game I didn't know I had a limit of a 1,000 (I probably should have checked that). So I probably used them more freely than I should have. Plus I have noticed that when my common events get too large they have a tendency to crash the game, which seems to corrupt my files, especially when it happens while I'm saving. So I try to split them up into multiple smaller common events as much as I can.

One day I'll go through them all and see how much space I can free up and then post a topic to see if I can get some tips. That's a good idea. In the meantime, I'm just trying to be as conservative as I can with them.

On a good note: I was able to get the effect I wanted by just adding a temporary State to the enemy and use that to distinguish which skill was being used during the common event. So the moderators can mark this as solved if they like.

As Andar says, that sounds like you're doing something wrong/inefficiently. One should be able to recreate a full-sized game like one of the Final Fantasy or Dragon Quest titles and not come anywhere near to using all of those common events.

My project is admittedly incomplete, but uses all of 30.


Have you looked at all at common plugins for MV? Something like Yanfly's Skill Core that allows you to execute code directly from a skill would be far more efficient. You can also do it with action sequences.


I Googled "rpg maker mv script call switch" and immediately found threads with the correct syntax. It's also in the pinned MV Script Call List. $gameSwitches.setValue(switch ID, true/false)


Andar said you don't (as in it's not the correct thing to do, which was elaborated on by Amaranth), not you can't.

I'm not very good at using script commands and mostly just try to mimic what others do when I use them. I don't understand all the syntax or how the language works. I use a different search engine, but I was only able to find two examples and they were for RPG Maker Ace and MZ. Although I do think I tried that specific command you posted (it was from the MZ example I think) but it was messing up my damage formula when I tried to include it. So I wasn't sure on how to write it into the formula without affecting the damage. Thanks for showing me the script command.

If the Switch is turned ON independently of the skill being used during AI processing, then I doubt I could use this method anyway. It would probably just mess the common event up. I think I found a work around by having the Items and Skills I want to share a common event add a temporary state to the target that allows me to differentiate which was being used during the common event. That seems to be working so far. So I think I'll just use that method since the Battle Formula/Switch idea I had seems problematic.

How? I have a lot of custom mechanics in my game and I'm using like 30 common events.

lol, I'm not sure. I just use a lot of them.
I use a different search engine, but I was only able to find two examples and they were for RPG Maker Ace and MZ.
If you were intent on including things about "damage," that could've screwed up your search results. As I demonstrated, the damage formula is simply a JavaScript field. There's no "damage"-specific syntax for switches, it's just the standard script call.

The function in MZ is the same.
If you were intent on including things about "damage," that could've screwed up your search results. As I demonstrated, the damage formula is simply a JavaScript field. There's no "damage"-specific syntax for switches, it's just the standard script call.

The function in MZ is the same.

Good to know.

I do think I came across that command during my search, but I was probably just writing it incorrectly into the formula to where it was negatively affecting the damage output. I thought that was likely a high possibility, which is why I included an example of one of my damage formulas and asked if someone could show me how to include it.

Luckily I found a workaround that solved my problem (least so far). I usually try to avoid using scripts as much as possible since I don't really understand how the language works.
Plus I have noticed that when my common events get too large they have a tendency to crash the game, which seems to corrupt my files, especially when it happens while I'm saving.
That is a lot of wrong assumptions.

the length of the common event has nothing to do with anything like that, and there are very few event command sequences that could crash the game at all (basically only recursive call common events), although a wrong loop can freeze the gamr.

Furthermore, NOTHING in common events can corrupt your files.
The only thing that could corrupt files is when you store your working folder in a cloudsync'd drive or if you have an impending hardware failure on your drive.
And that again has nothing to do with common events.

So I strongly suggest you go back to bughunting and find out what really corrupts your files...
That is a lot of wrong assumptions.

the length of the common event has nothing to do with anything like that, and there are very few event command sequences that could crash the game at all (basically only recursive call common events), although a wrong loop can freeze the gamr.

Furthermore, NOTHING in common events can corrupt your files.
The only thing that could corrupt files is when you store your working folder in a cloudsync'd drive or if you have an impending hardware failure on your drive.
And that again has nothing to do with common events.

So I strongly suggest you go back to bughunting and find out what really corrupts your files...

Would it help if I were to post one of the common events that frequently seems to cause the game to crash when I am working on it? Because it only seems to happen on the big ones, and when I split it up into smaller ones it no longer crashes. So I don't know what else could be causing it except for its size.

If it was just a bug or a wrong loop, I would think it would happen regardless if I split the event up or not. Because it is literally the same exact common event, just divided up into multiple common events instead of one huge one.

I should also point out the crash I'm talking about occurs while I'm using the development kit. Not during actual gameplay of the game itself.
1) as said above, make a new topic for that.

2) yes, posting a full common event there can help us find where you went wrong.
Don't forget screenshots of whatever event or skill calls or triggers that event.

3) there is no way to simply "split" a common event due to the way they are triggered. There are ways to chain common events, but each of them does a lot more in the code behind them than to simply "split" them. So yes, doing that can change a lot in the way the common event is handled.
1) as said above, make a new topic for that.

2) yes, posting a full common event there can help us find where you went wrong.
Don't forget screenshots of whatever event or skill calls or triggers that event.

3) there is no way to simply "split" a common event due to the way they are triggered. There are ways to chain common events, but each of them does a lot more in the code behind them than to simply "split" them. So yes, doing that can change a lot in the way the common event is handled.

Ok. I think I know of a way to test this then to see if its bug related. What if the common event was literally the same thing just being repeated many times over for the sake of a experiment?

For example:

Common event 1:

If Variable1 = 1
Add Item 1
End

Common event 2:

if Variable1 =1
Add Item 1
End

x1000

If that same simple condition was repeated a thousand times in the same common event, that should have no effect on whether it crashes or not is what you are saying, correct?

Also, I added this to avoid confusion but was probably too late. The crash occurs while I'm using the development kit. So there is nothing triggering the common event yet.
The crash occurs while I'm using the development kit.
What does that mean?
What does that mean?

It means while I'm actually writing the larger Common Events - that's when RPG Maker MV crashes. It's not during actual gameplay that it happens. They all run fine once the game starts. But while I'm working on them in the Database, it seems to struggle to load the larger common events and often seems to cause crashes, usually when I go to save the changes, and often results in my data file for common events getting messed up.
It means while I'm actually writing the larger Common Events - that's when RPG Maker MV crashes.
So you're talking about MV the editor, the software, is crashing. This is not at all what you've been saying:
one of the common events that frequently seems to cause the game to crash
I have noticed that when my common events get too large they have a tendency to crash the game
In point of fact, your game is not crashing at all.

That points to something wrong with your MV installation, your system resources, your actual computer hardware, etc.
So you're talking about MV the editor, the software, is crashing. This is not at all what you've been saying:


In point of fact, your game is not crashing at all.

That points to something wrong with your MV installation, your system resources, your actual computer hardware, etc.

Yes, when I said game earlier I was talking about the editor. I saw the confusion which is why I clarified. You don't have to point out earlier quotes of what I said. lol I wasn't blaming you or anyone else for the confusion, don't worry.

It probably is a computer issue. I don't know what is causing it. All I know is it has something to do with my common events getting too big. So until I know how to fix it, I'll have to work around it. Which means I'll have to make more common events than I would otherwise like to, since I have to keep them all small enough to where they don't crash the editor when I work on them.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-you-turn-on-a-switch-inside-a-damage-formula-on-rpg-maker-mv.160972/