How do I call variables added by plugins out of scope?

fugahagen

Villager
Member
Joined
Oct 31, 2017
Messages
21
Reaction score
11
First Language
english
Primarily Uses
RMMV
I'm noob so sorry if you don't understand my question but I have the target core plugin and use the variable target and such. I would like to be able to use the target.friendsUnit() var in other places like the in the custom requirement section of my code. Right now I'm just pushing results to the game variables but it seems like extra steps?
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,115
Reaction score
1,525
First Language
EN
Primarily Uses
RMMZ
Like, Skill Core's <Custom Requirement> tag? That supports use of user, you could do:
Code:
user.opponentsUnit()
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,430
Reaction score
7,711
First Language
German
Primarily Uses
RMMV
you need to be more specific in your question.

Basically in a plugin that has been programmed in a professional way the variables can't be used out of scope because they don't exist out of scope. But often that scope is bigger than you think, allowing the variables to be used in specific places where they exist.

So there is no general answer, but if you specify where you want to use what then someone can tell you if it is possible and how to do it.
 

fugahagen

Villager
Member
Joined
Oct 31, 2017
Messages
21
Reaction score
11
First Language
english
Primarily Uses
RMMV
Like, Skill Core's <Custom Requirement> tag? That supports use of user, you could do:
Code:
user.opponentsUnit()
Yes this! How do you know this? It doesn't say that on the skills core page.

you need to be more specific in your question.

Basically in a plugin that has been programmed in a professional way the variables can't be used out of scope because they don't exist out of scope. But often that scope is bigger than you think, allowing the variables to be used in specific places where they exist.

So there is no general answer, but if you specify where you want to use what then someone can tell you if it is possible and how to do it.
I'm using only Yanflys plugins ATM because I trust he/she? programs in a professional way. To be more specific with what I'm trying to do, I'm making skills for enemies like this one:
Code:
<Custom Target Eval>

for (var i = 0; i < target.friendsUnit().aliveMembers().length; ++i) {

var member = target.friendsUnit().aliveMembers()[i];

if (member.hp < 50) targets.push(member);

$gameVariables.setValue(8, [targets.length]);

}

</Custom Target Eval>

<damage formula>

var dmg = $gameVariables.value(8);

value = 200 / dmg;

</damage formula>

<Custom Requirement>

for (var i = 0; i < $gameTroop.aliveMembers().length; ++i)

if ($gameTroop.aliveMembers()[i].hp < 50) {

$gameVariables.setValue(8, [i]);

value = true;

} else {

value = false;

$gameVariables.setValue(8, 0);

}

<\Custom Requirement>
I guess my question is am I going about this the right way by using game variables. Its mostly working but sometimes the game variable I'm using stays 0 and no one does the spell until I hit an enemy under the 50 hp threshold.

Also I have the rmmv scrip call list and plugin command list for Yanfly but how do I find all the functions and variables plugins are using?

Edit: using $gameTroop works but if I could use target.friendsUnit in the requirements sections the player could also use the skill
 
Last edited:

Astfgl66

Veteran
Veteran
Joined
Jan 5, 2016
Messages
722
Reaction score
578
First Language
French
Primarily Uses
How do you think someone else knows?
I mean, there aren't many solutions: you know either by reading the code or by trying it and seeing if it works.

Trying it is easy and requires no understanding other than knowledge of the console.log script call.
Boot up the console, get your target object, and see if the friendsUnit call works.
Hell, do a console.log inside the target eval to know it. Quick, easy, 5 seconds to test in battleTest and you'll have your answer. That's the easy way: It gets you no knowledge about the general case. It justs gets the job done, quick and dirty.

The hard way is by reading the code, and understanding the context of the function call.
Friends unit can be found in the game action class. In there you can see it calls subject.friendsUnit(), that means friendsUnit is actually a function from the subject itself. Subject will either be an actor or enemy object so you go look into there.
Lo and behold, friendsUnit returns $gameParty for instances of game actor, and $gameTroop for instances of game_enemy.
There you have it. You can use friendsUnit on actors or enemies and you know what it will return.
It took me a grand time of 10 seconds searching rpg_objects to find this. As easy as ctrl-f and pasting friendsUnit. Hell, it took me longer to type this than to find this info.

Using script calls without understanding why they work is just a recipe for disaster, and an exercise in frustration. Do yourself a favor, and search the core files before writing a script call, just so you know what you're actually doing.

I'd actually advise also a quick search of relevant plugins you use to see if they're not modifying the behavior of the core scripts for that particular function. This is done easily by using the console.log script call and telling it to return to you the actual function (by omitting the brackets and parameters), it will then tell you in which file, and which line to look, so you can understand what you're dealing with.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,115
Reaction score
1,525
First Language
EN
Primarily Uses
RMMZ
Yea, I just searched through Skill Core's code for the relevant notetag's eval and verified that the user variable is defined there.

It'd be a bit odd to have a function for friendsUnit and not have a counterpart for the opposing side, so I just went to Game_Actor.prototype.friendsUnit in rpg_objects.js and hunted around a little...voila, opponentsUnit. :kaothx:

Problem solved? :kaoswt:
 

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

Latest Threads

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,034
Messages
1,018,446
Members
137,820
Latest member
georg09byron
Top