MV Javascript Context Assistance

I'm searching about and I can't find the context I need to express what I want.
I have a variable for which enemy group you face. It corresponds to the troop number and I'd like to use a bit of script instead of a ton of if/thens in an event.

Something to the effect of $GameTroop.setvalue($gameVariables.value(id)); perhaps?

Lol I feel like a tourist with a common phrases handbook.
This link may help you with what you're looking for, it contains all sorts of script calls. Aside from that, I don't think your line is valid syntax. In the link I posted, I did a quick CTRL + F and found this:

1692627531990.png

Maybe replacing troopId with $gameVariables.value(id) will do something? Didn't test it though.
If you want to fight a troop with variable ID, the Battle Processing command has that option:

screenshot.png
If not, maybe try to explain what you're trying to do rather than how you've tried to do it.
I'm searching about and I can't find the context I need to express what I want.
I have a variable for which enemy group you face. It corresponds to the troop number and I'd like to use a bit of script instead of a ton of if/thens in an event.

Something to the effect of $GameTroop.setvalue($gameVariables.value(id)); perhaps?

Lol I feel like a tourist with a common phrases handbook.

If you want to fight a troop with variable ID, the Battle Processing command has that option:

View attachment 274053

If not, maybe try to explain what you're trying to do rather than how you've tried to do it.
Oh SNAP, I usually don't use the regular combat so I'm not familiar with the features as much as other parts of RPGMaker.

The context is I wanted to simplify the method of selecting backgrounds, enemies and actors in an automated arena style combat thing. That should work for the troops but I'll probably use a bit of script for the battlebacks and actors (which also correspond with the troops, the enemy version has a script to call the stats from the actor version).

Eventually I wanna make various RPG characters fight each other. I've been playing with some of the sprites already, I have Celes from FF6 sized and sorted out as a SVBattler Sheet.

1692628081891.png

This link may help you with what you're looking for, it contains all sorts of script calls. Aside from that, I don't think your line is valid syntax. In the link I posted, I did a quick CTRL + F and found this:

View attachment 274052
Maybe replacing troopId with $gameVariables.value(id) will do something? Didn't test it though.
I was looking for that right before I posted actually! Thanks!
Thanks everyone, Got it lookin nice and simple now.
Here's what it looks like in case it might help someone else.

Top script clears party & 2nd one adds an actor corresponding to variable 10.
1692631127646.png
Just to put it out there...unless you're reusing that Random Player variable someplace else that we can't see, there's not really a reason to use two separate variables for the random player and the random troop.

You can simply assign the actor, then re-randomize the same variable for the troop ID.

For that matter, if you're already using a script call, there's no reason to use a variable for the party member at all. Just put the random value right in there:
Code:
$gameParty.addActor(Math.randomInt(7)+1)
Just to put it out there...unless you're reusing that Random Player variable someplace else that we can't see, there's not really a reason to use two separate variables for the random player and the random troop.

You can simply assign the actor, then re-randomize the same variable for the troop ID.

For that matter, if you're already using a script call, there's no reason to use a variable for the party member at all. Just put the random value right in there:
Code:
$gameParty.addActor(Math.randomInt(7)+1)
Hahahhaha, because I'm not that good at programming and don't really have a command of Java as a language even if I underestand more or less what I'm looking at. Thanks for simplifying it even further! I've implemented the code as you have it there, eliminating the variable.

I also realized I needed to init the party member which I found how to do easily enough

"$gameParty.all_members, initalize = true"
Hahahhaha, because I'm not that good at programming and don't really have a command of Java as a language
MV uses JavaScript, not Java. Similar name, two different languages.

I also realized I needed to init the party member which I found how to do easily enough

"$gameParty.all_members, initalize = true"
I have no clue where you got that from, but that is not valid code.
- The syntax with the comma is wrong
- The game party has no all_members property

To initialize the actor is $gameActors.actor(ID).setup(ID)
Yes, the actor's ID is supplied in two places.

Or, a bit longer but it doesn't require you to supply the actor's ID manually:
Code:
$gameParty.members()[0].setup($gameParty.members()[0].actorId())
Hahahhaha, because I'm not that good at programming and don't have proper command of functions like that at this tme, but thanks for simplifying it even further!


I also realized I needed to init the party member which I found easily enough

"$gameParty.all_members, initalize = true"

MV uses JavaScript, not Java. Similar name, two different languages.


I have no clue where you got that from, but that is not valid code.
- The syntax with the comma is wrong
- The game party has no all_members property

To initialize the actor is $gameActors.actor(ID).setup(ID)
Yes, the actor's ID is supplied in two places.

Or, a bit longer but it doesn't require you to supply the actor's ID manually:
Code:
$gameParty.members[0].setup($gameParty.members[0].actorId())
Yeah I'm realizing that wasn't working after watching it for a bit. I'm looking up something so simple as initializing a party member but I'll be damned if I can find any useful information on it.

Haha the code? I made that up because I have no idea what I'm actually doing. I can never seem to retain any information on how to actually format the code. Thanks for the corrections. I was just coming back here to see if I could find anything more about it.
Oh, ok, that didn't work either.

$gameParty.members[0].setup($gameParty.members[0].actorId()) seems fairly straightforward.... this isn't the first time I've taken a line of code from some forum or tutorial and had it return some error about not being able to read part of the code.

I've placed it AFTER the bit that adds the actor, so it should be getting the actor ID from party slot 0, I can see that. I don't understand what the error means, what is undefined? I was reading this post earlier and I was getting the same error then and I figured it wasn't the code I needed since it wasn't working. I realize that's MZ but sometimes it's the same commands innit?


Ugh I hate having to ask questions about this stuff too, it's such a simple thing.
Zero is the first slot in the party right? I swear I read that earlier tonight.
Haha the code? I made that up because I have no idea what I'm actually doing.

Oh, ok, that didn't work either.

$gameParty.members[0].setup($gameParty.members[0].actorId()) seems fairly straightforward....
You need to slow down and be more careful. Computer code is very specific, every character has to be correct. There is zero point in trying to make anything up, it has close to a 0% chance of working. Either look it up or ask.

Speaking of which - I had a typo in mine 😛

You need parentheses after members. I've corrected it above, but here it is again:
Code:
$gameParty.members()[0].setup($gameParty.members()[0].actorId())

Sorry about that...I must've been distracted or something.
You need to slow down and be more careful. Computer code is very specific, every character has to be correct. There is zero point in trying to make anything up, it has close to a 0% chance of working. Either look it up or ask.

Speaking of which - I had a typo in mine 😛

You need parentheses after members. I've corrected it above, but here it is again:
Code:
$gameParty.members()[0].setup($gameParty.members()[0].actorId())

Sorry about that...I must've been distracted or something.

Oh yeah I know that for sure, just my lack of formal programming language training leads me to accomplish things on kind of a trial and error basis, and not because of the code itself but because of the formatting and it's really frustrating tbh.

I managed to do a whole little game in Adventure Game Studio earlier this year, but there were definitely some big walls over simple stuff. Especially frustrating after breezing through something you personally feel is more complicated. Using Notepad++ is nice because it formats and colors for code which is easier on the eyes at least.

Thanks for the edit in the code! :LZSgrin: I usually try pretty hard to come up with the solution on my own or at least find it on my own, but this one was really getting me.
I applied what I learned regarding the actors to the enemies and went further and disabled the plugin I've been using to trigger a common event on death, instead adding it to the code. 😀

(Variable 19 & 20 are the win counters for the left and right, and left stopped working with the script so I &&'d it into the event callback bit)

Code:
//Clear Party
$gameParty.members().forEach(function(actor)
{$gameParty.removeActor(actor.actorId());
});

//Add Random Actor
$gameParty.addActor(Math.randomInt(8)+1)
$gameParty.members()[0].setup($gameParty.members()[0].actorId())

//Select Random Enemy & Start Battle
BattleManager.setup(Math.randomInt(8)+1, false, true)
BattleManager.setEventCallback(result => {
if (result === 2) $gameVariables.setValue(19, $gameVariables.value(19) + 1) && $gameTemp.reserveCommonEvent(5);
});
$gamePlayer.makeEncounterCount();
SceneManager.push(Scene_Battle);

@ophidic, please avoid double posting, as it is against the forum rules. You can use the "Edit" function on your posts to add additional information you've forgotten or respond to multiple people. You can review our forum rules here. Thank you.

(Variable 19 & 20 are the win counters for the left and right, and left stopped working with the script so I &&'d it into the event callback bit)
That's...pretty hacky. && is a logical operator to make code produce a boolean result, not a way to shoehorn multiple commands into one statement.

If it works for you, then whatever, but it would be better practice/more correct syntactically to just add braces and make it two statements.
Code:
BattleManager.setEventCallback(result => {
if (result === 2) {$gameVariables.setValue(19, $gameVariables.value(19) + 1); $gameTemp.reserveCommonEvent(5);}
});
Double-post notice: @ophidic

Sorry bout that, i got excited and forgot this place has stricter forum rules than I'm accustomed to.

That's...pretty hacky. && is a logical operator to make code produce a boolean result, not a way to shoehorn multiple commands into one statement.

If it works for you, then whatever, but it would be better practice/more correct syntactically to just add braces and make it two statements.
Code:
BattleManager.setEventCallback(result => {
if (result === 2) {$gameVariables.setValue(19, $gameVariables.value(19) + 1); $gameTemp.reserveCommonEvent(5);}
});

Thank you, it was pretty hacky. I only sorta know what I'm doing and I'm glad to hear about a better way to accomplish it! Thanks again for all the help everyone! I'll give this a shot later today.

Ahh I see, if you want the result to do two or more things you contain it all in curly brackets and end each thing with a semicolon. Excellent to know. 😀

Original thread: https://forums.rpgmakerweb.com/threads/javascript-context-assistance.160486/