setting variables based on class and enemy id?

jonthefox

Veteran
Veteran
Joined
Jan 3, 2015
Messages
1,499
Reaction score
672
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,307
Reaction score
769
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,717
Reaction score
1,601
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

Surprising nobody, it turns out "next Friday" for the next Jump into Javascript has become "possibly Sunday if you're lucky" XD
Folks, if anyone sends you a message inviting you to add their API to your game, please report them. We don't want people spamming our members asking them to add stuff to their games for their own (or others') benefit. We've updated the forum rules to confirm this.
I'm listening to iiluminaughtii talking about the secrets behind shady businesses and scams. Meanwhile I'm writing a fanfic about Sephiroth from FF7, one specifically for my stepmom. I'll get to give it to her, too, because my boss said I could take the holidays off! Dec. 22-27 I will be in Orlando, and maybe Fort Myers too, visiting my dad and stepmom!
Of course, I bought a handful of games on the Steam Black Friday sale. Will I try them? Will I complete any? Who knows...
I don't really have any neat updates today about how I screwed up programming... But if you want to observe the intensenes of me programming, then you can check out my stream :)

Forum statistics

Threads
117,013
Messages
1,103,805
Members
152,910
Latest member
Mr_Popo
Top