JavaScript questions that don't deserve their own thread

Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
I can't seem to get either of those to work. I'm checking to see if Actor 1 is in position 0:

Code:
if ($gameParty.battleMembers()[0].actorId() == 1) {99}; else {5};

if ($gameActors.actor(1) == $gameParty.battleMembers()[0]) {99}; else {5};
That's what I'm trying to use, but to no effect. This is putting a number into a variable via a troop event, and I haven't had any problems using expressions like "$gameParty.battleMembers()[0].def-10" in those events once I figured them out. But this one has me stumped.

Alternatively, I could work with finding out whether a battle member has a state. That might even be a better method, but I'm having a hard time getting that to work either. Darn battleMembers.
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
That's either because if statements don't return values or because you're putting a semicolon between the if and the else block (or both). Can you try using something like:
Code:
$gameParty.battleMembers()[0].actorId() == 1 ? 99 : 5
using the ternary operator?
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
Can you show how it actually looks in the troop event command window?

And have you tried breaking it into multiple lines instead of a single line and see if that works?
 

Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
Thanks! Seems like the semicolon was the culprit. It's working now. Glad to get the figured out. I thought the battleMember thing just wasn't going to work, but now it seems to work normally.
 

Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
If anyone could be so kind...

Why isn't this working?

Code:
if (!$gameParty.Members()[0].isStateAffected(1)) {1} else {0}
It's supposed to be the script setting a variable in an event. As you can see, if the party member is alive, it should set the variable to 1, otherwise to 0. But it's just returning 0 regardless. It's driving me crazy, because I usually know what I don't know, and this one I really think I do know, and it sure looks like it should just work. I've used that sort of syntax before, and I can't find anything wrong with it. There must be something in context I don't know.
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
If you're using Control Variables and setting it to a script call, you can try using:
Code:
$gameParty.members()[0].isStateAffected(1) ? 1 : 0
because:
  1. I personally wouldn't rely on if statements returning values even though in your case it does.
  2. Members() should be members() (JavaScript is case-sensitive)
 

Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
Thanks, it was the capitalization. I actually know how that's supposed to work, but my brain is weird. I had copy, pasted, and altered it, and during that process "checked" that it was capitalized properly, which meant my internal "$capitalization.isCorrect()" value had already returned "true" and that line of processing was skipped thereafter.
 

BurningOrca

Veteran
Veteran
Joined
Apr 14, 2019
Messages
214
Reaction score
187
First Language
German
Primarily Uses
RMMV
I am asking this too late and I am not sure if this is the correct board, but the other javascript related boards seem not be the correct ones for me either.

Is it worth trying to publish a plugin for a functionality that has already been done, maybe also multiple times, but different?
With different I mean the existing plugin(s) may have functionality the one I have in mind lacks, but mine would have functionality the other one(s) seem(s) not to provide.

For a particular example: There seem to be many plugins either in the 'request' or 'released' boards that are related to item and skill sorting.
I found at least 3:
- One that uses database notetags to change the sort order
- One that sorts the skills and/or items just alphabetically
- One that let's the player swap items in the sort order
and I am pretty sure there are many more.

My already released plugin has multiple sort orders included, but they just don't belong into it as the plugin is related to Scene_Battle (Now it is 2 or 3 plugins in one) .

I really want to split my plugin and release another one, but I don't know if it is worth the time?
 

Johnboy

Veteran
Veteran
Joined
Jan 13, 2016
Messages
344
Reaction score
124
First Language
English
Primarily Uses
@BurningOrca I say split it if you feel it will better serve your purpose and/or the community. More options is not a bad thing.
 

Nebu

Villager
Member
Joined
Oct 4, 2017
Messages
29
Reaction score
2
First Language
English
Primarily Uses
N/A
I am using different yanfly plugins, but I am not sure if I need them.

My idea is, that if a player uses a special skill, and the attack will be a critical hit, different things can happen:

1 the target will get a state
2 the user will get a state
3 users party will get a state
4 user gets healed by x% of max hp
5 users party gets healed by x% of users max hp.

Is this possible to do?
If yes how to write the different if clauses?

And the last thing is, I am using yanflys skill mastery, so I want the skills to do these effects from a certain lvl on. This code I found on yanflys page. But I am not sure if I can combine it if an other if clause. Is this possible?

Best regards
Nebu
 

Ellie Jane

Veteran
Veteran
Joined
Mar 17, 2012
Messages
752
Reaction score
1,488
First Language
English (UK)
Primarily Uses
RMMV
Hi,

Any equivalent to this in RPG Maker MV? In VXa I would have done:

if SceneManager.scene_is?(Scene_Map)
#do this
end

So only execute this code if you're in Scene_Map.
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
I believe this could work for that:
Code:
if (SceneManager._scene instanceof Scene_Map) {
    // do this
}
 

Vassim74

It's a Secret!
Veteran
Joined
Jan 7, 2014
Messages
115
Reaction score
85
First Language
English
Primarily Uses
RMMV
Is there a conditional branch script command or something to determine if an event ID has been removed using the erase event command? I am using a parallel event to execute a specific event's move route based on whether the player is moving or not, and I want to be able to have that parallel event stop processing when the event it's controlling has been deleted.
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
I think you can use a script call to:
Code:
$gameMap.event(event_id_goes_here)._erased
in a conditional branch's conditions to check if an event with the specified ID has been erased via he Erase Event command.
 

Vassim74

It's a Secret!
Veteran
Joined
Jan 7, 2014
Messages
115
Reaction score
85
First Language
English
Primarily Uses
RMMV
That worked, thanks!
 

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
379
Reaction score
354
First Language
german
Primarily Uses
RMMZ
What is the method to change player's location / transfer him within same map? Looking for this one

Code:
$gamePlayer.moveTo(x, y);
EDIT:
Found it :) It is
Code:
$gamePlayer.locate(x, y);
 
Last edited:

Dicleon

Villager
Member
Joined
Apr 3, 2016
Messages
20
Reaction score
3
First Language
French
Primarily Uses
Hello all, My question is on the Yanfly Attachable Augment plugin, is it possible that specific weapon and armor are found with Augments already on them? It's doesn't have to be random or anything just pre-determined Augment.
 

BurningOrca

Veteran
Veteran
Joined
Apr 14, 2019
Messages
214
Reaction score
187
First Language
German
Primarily Uses
RMMV
When I look at plugins from other creators I can see two different styles.
Many seem to wrap a self calling function around their code.
Other, e.g. Yanfly does not do this and I just adopted this style of coding.

So I am just curious:
- What are the real reasons for wrapping your code with a self calling function?
- What are the real reasons for not doing this?
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
Mostly a matter of preference.

The real reason for wrapping the code in an Immediately Invoked Function Expression (IIFE) is to encapsulate variables that aren't intended to be public. It's a way to avoid creating global variables.

Code:
const publicVariable = {};
;(function () {
   const privateVariable = 5;
   publicVariable.value = privateVariable ** 2;
})();
Now other plugins can access the public variable but not the private variable. A common purpose is when you create alias for functions, there's generally no need to expose the alias itself to the public.

Alternatively, you can create a namespace for yourself and then run everything off the namespace.

Code:
const MyNamespace = {};
MyNamespace._privateVariable = 5;
MyNamespace.publicVariable = MyNamespace._privateVariable ** 2;
Javascript doesn't have private variables (not yet...), but the underscore is used by convention to indicate that it's supposed to be private.

You can also use a namespace within an IIFE to both encapsulate variables and save some keystrokes.

Code:
const MyNamespace = {};
;(function ($) {
   const privateVariable = 5;
   $.value = privateVariable ** 2;
})(MyNamespace);
Nowadays, all of this is considered "old school" ways of handling variable scope. Web development these days use modules with import/export statements to manage this, however, I don't think the module implementation will be supported by the MV engine or adopted by plugin writers any time soon.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

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.
time for a new avatar :)

Forum statistics

Threads
106,015
Messages
1,018,351
Members
137,801
Latest member
topsan
Top