setting variables based on class and enemy id?

jonthefox

Veteran
Veteran
Joined
Jan 3, 2015
Messages
1,502
Reaction score
676
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,315
Reaction score
772
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,787
Reaction score
1,632
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 Profile Posts

Mod name: "[Game name] Gameplay Overhaul"
What they actually mean: "Here is a mod that makes the game harder."
I decided to reinstall one of my most favourite game of all times, Gothic 2. Time to get back to Khorinis!
So much game make... I needs to rest. The foods call.
-Casino with bunnysuit green check.png
1638563168795.png
Monday December 6th 2021 at 7PM Hawkzombie will stream A Thief's Voyage on his Twitch.

Hawkzombie Twitch

Check it out.​

Forum statistics

Threads
117,166
Messages
1,105,083
Members
153,256
Latest member
stormydev
Top