Formulas using self variables

JadeTheurgist

Villager
Member
Joined
Apr 19, 2020
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMMV
So, in my game I'm making upgrade-able skills, where variables are used to change the cost, potency, number of hits, etc. I quickly realized that this approach under normal means would take up a most of the variables in my game (about 20-25 skills took around 100 variables between them), so I decided to try using Yanfly's Self Switches and Self Variables plugin to only take up 7 variables instead.

On a separate map, I have events for each of my skills (just template skills right now). When my game starts, I have a common event run to set all the skill self variables in each to 0. I then reference these self variables in the skills for use in formulas. At least, that's what I'm trying to do.

When I look at my skills in game however, no cost is listed. I'm not sure if there's an error in my code (not very proficient in Javascript) or if it's just that Self Variables can't be detected for formulas this way.

Below is a formula I'm using for MP cost with Yanfly's Skill Core. If someone could tell me what I might be doing wrong (or if using self variables for this just isn't possible), I'd really appreciate it.

Code:
<Custom MP Cost>
var varPotency = this.getSelfVariableValue(20, 01, 30);
cost = 10 * (1 + varPotency);
</Custom MP Cost>
 

Guy_Fellows

Villager
Member
Joined
Jul 30, 2020
Messages
14
Reaction score
7
First Language
English
Primarily Uses
RMMV
I haven't used Yanfly's plugin, so I'm probably not going to be helpful, but just one thought. The code above goes into the the Skill's Note section in the editor, correct? If so, I would wonder if the "this." you are calling is in the correct scope? It may be coming back as undefined because it can't find the function being called.

Can you share the code for where the getSelfVariableValue function is declared? I'm not sure I know JavaScript well enough to help, but I'd like to help if I can (and maybe learn something myself >_>)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,057
Reaction score
13,685
First Language
English
Primarily Uses
RMMV
Self switches and self variables apply to events, not to skills.

I don't know how you have events for your skills, but when the skill core runs, it works on skills from the database, not events, and there is nothing linking that skill back to that event that should make the plugin refer to an event id.
 

JadeTheurgist

Villager
Member
Joined
Apr 19, 2020
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMMV
I haven't used Yanfly's plugin, so I'm probably not going to be helpful, but just one thought. The code above goes into the the Skill's Note section in the editor, correct? If so, I would wonder if the "this." you are calling is in the correct scope? It may be coming back as undefined because it can't find the function being called.

Can you share the code for where the getSelfVariableValue function is declared? I'm not sure I know JavaScript well enough to help, but I'd like to help if I can (and maybe learn something myself >_>)
@Guy_Fellows The getSelfVariableVaule is a script call added in Yanfly's Self Switch and Self Variables plugin. It's used to allow you to grab the self variable designated. The first number is the map id, the second is the event id, and the third is the variable number that you made into a self variable via naming it as such in the variable list.

Self switches and self variables apply to events, not to skills.

I don't know how you have events for your skills, but when the skill core runs, it works on skills from the database, not events, and there is nothing linking that skill back to that event that should make the plugin refer to an event id.
@Shaz I have my skills declared in the database, the events I mentioned are more just containers to hold the self variables that the skill references (guess I didn't explain that well enough). The script call, at least in theory, just gets the variable's value from the event and applies it into the formula.
 

HumanNinjaToo

The Cheerful Pessimist
Veteran
Joined
Apr 18, 2013
Messages
1,226
Reaction score
603
First Language
English
Primarily Uses
RMMV
Sorry if this isn’t helpful, but would it not make more sense to use a plugin for this? Yanfly skill mastery for example, or action sequences?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,057
Reaction score
13,685
First Language
English
Primarily Uses
RMMV
What is making the skill formula look at the event? Certainly not the self switches/variables, and I don't believe the skill core does either.
 

JadeTheurgist

Villager
Member
Joined
Apr 19, 2020
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMMV
@Shaz It was the script call "getSelfVariableValue()" that's added with the Self Switches and Variables plugin. At least, I think it should work. As I stated before, I'm not proficient in Javascript coding so I might be completely wrong about this, but it seems like it should make sense.

@HumanNinjaToo I had looked into that, and may try it if this idea ultimately fails, but I had a number of parts in the abilities that these variable would affect: damage potency, mp cost, secondary effect rate, targeting range. I was going to make "skill tree" maps where the player would upgrade these aspects of the abilities using JP from another Yanfly plugin. I wanted the player to have the option to upgrade skills based on what they needed at the current moment, not forcing them to grind a skill over and over to get it.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,057
Reaction score
13,685
First Language
English
Primarily Uses
RMMV
It was the script call "getSelfVariableValue()" that's added with the Self Switches and Variables plugin
The script call works when you use it in an event.

There is nothing that says it works when you're using it with skills or with the skill core.

As I said, there is nothing in any of those plugins that ties the skill with the event. Self Variables have no meaning on skills.
 

HumanNinjaToo

The Cheerful Pessimist
Veteran
Joined
Apr 18, 2013
Messages
1,226
Reaction score
603
First Language
English
Primarily Uses
RMMV
I see. I had done something similar before by upgrading skills to either more damage or aoe effect. I just created new skills and replaced them as needed. It worked for me because I did not have an excessive amount, about 10 skills per actor and 3 upgrade options per skill so only 40 options per actor
 

JadeTheurgist

Villager
Member
Joined
Apr 19, 2020
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMMV
@Shaz I see that now. It even says it on the plugin page on Yanfly's website. I feel stupid.
In that case, I'll have to try something else. Thank you for your help.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,057
Reaction score
13,685
First Language
English
Primarily Uses
RMMV
There would probably be a way that you could put a direct reference to the $gameVariables._data[...] to reference the correct map, event and variable number, based on what the self variables plugin does internally.
 

TFman

Warper
Member
Joined
Aug 21, 2020
Messages
2
Reaction score
0
First Language
English
Primarily Uses
RMMV
Same here.
I can get the self switches / variables data checked or changed just fine if I do that in simple script calls, I'm still having a hard time figuring out how to do it in a

Var HitEvents = ...
HitEvents.forEach(function(event) {
...
});


this is the whole script call that's not working:

var rangeX = 0.5;
var rangeY = 1.25;
var affectedEvents = $gameMap.events().filter(function(event) { return Math.abs($gameMap.deltaX($gamePlayer.x, event.x)) <= rangeX && Math.abs($gameMap.deltaY($gamePlayer.y, event.y)) <= rangeY && event.y > $gamePlayer.y });
affectedEvents.forEach(function(event) {
var dmg = this.getSelfVariableValue($gameMap.mapId(), event.eventId(), 170);
dmg -= $gameParty.leader().atk;
if (dmg >= 0){ dmg = -1; }
var hp = this.getSelfVariableValue($gameMap.mapId(), event.eventId(), 118);
var nhp = hp + dmg;
if (nhp > 0) { this.setSelfVariableValue($gameMap.mapId(), event.eventId(), 118, nhp);} else {this.setSelfSwitchValue($gameMap.mapId(), event.eventId(), 214, true);}
});

but no self variable seems to work (I even tried changing mapid with 6 and eventid with 7, with no luck).
If I do a simple script call instead:

var dmg = this.getSelfVariableValue($gameMap.mapId(), 7, 170);
$gameVariables.setValue(498, dmg);
dmg -= $gameParty.leader().atk;
$gameVariables.setValue(499, dmg);


variable 498 gets correctly assigned the "self variable 170" of event 7 and variable 499 "self variable 170" minus the leader's attack.

Attached the error log~ I see what's not working but I don't really get why.
 

Attachments

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

Latest Threads

Latest Profile Posts

YES! officially released my games soundtrack on Itunes, Spotify, and Amazon..... kinda cool!

Another old age version of Reid. Trying out different style.
Hey everyone! Not sure how many people know about Cafofo Music on Itch.io, but I highly recommend their Sound Effects! It is amazing quality AND quantity and best of all, they are having a 50% sale! I can't express how much I love sales.
Wow.... My last map GIF got 47 likes, 16 retweet and 2,105 views on Twitter in 24 hours. My game thread here's only got 3k views in 6-7 months. I guess building my Twitter was insanely worth it. :LZSexcite:

Forum statistics

Threads
105,594
Messages
1,014,882
Members
137,264
Latest member
ZeoValinferno
Top