setting variables based on class and enemy id?

jonthefox

Veteran
Veteran
Joined
Jan 3, 2015
Messages
1,502
Reaction score
677
Primarily Uses
I have some basic questions about using variables:

1. Can I set a variable based on an actor's class? Like, if class = X, then set variable to Y.
2. Same questions, but based on enemy ID. Like, if enemy ID = X, then set variable to Y.
3. I want to call these variables in a damage formula, which should be easy enough (I can find examples of how to do this in the damage formula thread), but WHERE/WHEN do I set these variables? Do I need to create an event at the beginning of the game which will set these variables?

Thank you in advance!
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
1,316
Reaction score
782
First Language
Poland
Primarily Uses
RMMV
#1 - Yes, you can:
Code:
if ($gameActors.actor(1)._classId === 1){ $gameVariables.setValue(1, x);}

#2 - Similar way, but this is for troop event:
Code:
if ($gameTroop.members()[x]._enemyId === 1){$gameVariables.setValue(1, x);}

#3 - Where do you set variables is up to you, except point 2, because we reffer to current battlers in battle, outside battle $gameTroop.members() will return null value, because it's an array of enemies in battle. I'm not sure if you can obtain enemy ID outside of battle since battles are not taking place in the same scene as actuall gameplay.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,791
Reaction score
1,638
First Language
English
Primarily Uses
RMMV
I want to call these variables in a damage formula...but WHERE/WHEN do I set these variables?
Do you use them for other purposes in your game? If you're only doing this inside damage formulae, there's zero reason to use variables at all.

If you're in a formula and you want to use a value that is different depending on another condition, you can use the ternary operator (which you should've seen examples of in the Damage Formula 101 and such threads): condition ? true value : false value
So if I want to use the attacker's ATK and add 10 if he's class ID 1, but only 5 if he's something else:
Code:
a.atk + (a._classId==1 ? 10 : 5);
 

Latest Threads

Latest Posts

Latest Profile Posts

a lot of my maps and battlebacks are me redrawing base rpg maker mv stuff to match with my own artwork... sometimes it comes out ok lol.
Guess I had to do something related to xmas... :kaoswt2:
SWZtrkz.jpg
"16. Do NOT contact other members by private message, on the forum or status feed, inviting them to put additional tools (such as leaderboards, ads, etc - whether yours or another person's) into their game."
Oh no. Necessity is the mother of invention. Do I want to know what happened?

Forum statistics

Threads
117,183
Messages
1,105,268
Members
153,312
Latest member
Homaniac
Top