What am I doing wrong here?

Hello, it's me again. I'm feeling reticent about asking so many questions but I've spent the whole day trying to make two skills work and at this point, I have no clue how.

So, the skills I want are supposed to "steal" stats from one ally and then give those stats to another ally.

The first skill is supposed to store the targeted ally's ID and then run a common event. The skill has the following notetags:

Spoiler: Notetags
JavaScript:
 <Instant Cast>

 <Custom Requirement>
  if $gameSwitches.setValue(2, true) {
     value = false;
   } else {
     value = true;
   }
  </Custom Requirement>

 <Custom Execution>
$gameSwitches.setValue(2, true);
 </Custom Execution>

<Before Eval>
var targetId = target.actorId();
$gameVariables.setValue(21, targetId);
</Before Eval>

The code that is relevant for this skill's purpose is the part in the "Before Eval" notetag but I've included all of it just in case something else may be causing issues as well. I've checked if the actorID is actually getting stored in the variable during testing and it seems to be working correctly, so I don't think the issue is here.

The next part is the common event that is run by this skill. I've tried a dozen different methods, most of which didn't even come close to working but I've settled on two methods that seem to me as being close to correct. Those are as follows:

Spoiler: Method 1
S1.png

Spoiler: Method 2
S2.png

In this method, B_Reuse1 is the name of Variable 21 where the Actor ID is stored.


And finally the second skill that is supposed to transfer the stored stat to another ally. It has the following notetags:

Spoiler: Notetags
JavaScript:
 <Instant Cast>

<Custom Show Eval>
if ($gameSwitches.value(2)) {
visible = true;
} else {
visible = false;
}
</Custom Show Eval>

<Custom Execution>
$gameSwitches.setValue(2, false);
</Custom Execution>

<After Eval>
var value = $gameVariables.value(5);
target.addParam(0, value);
target.gainHp(value);
</After Eval>

I strongly suspect the issue happens during the CE, but after reading through many tangentially related threads as well as running the code through a few javascript code checkers to make sure I didn't make a simple syntax error, I'm at a point where I have no idea how to get this to work. Any and all help would be greatly appreciated!
"<Custom Requirement>
if $gameSwitches.setValue(2, true) {
value = false;
} else {
value = true;
}
</Custom Requirement>"

Just letting you know that this if statement will not execute because of how it is written. It needs to be:
JavaScript:
<Custom Requirement>
  if ($gameSwitches.value(2)) {
    value = false;
  } else {
    value = true;
  }
</Custom Requirement>

As for the rest of it, I'll have to take a better look when I get a chance to sit down and check things through.
Code:
 <Custom Requirement>
  if $gameSwitches.setValue(2, true) {
This is incorrect. You're setting a value on the switch, not looking at what it is.

The correct function to check the switch's value is $gameSwitches.value(2)

It's also not going to run the code at all because it's the incorrect syntax. You must have parentheses around a conditional.

The correct version of this notetag would be:
Code:
if ($gameSwitches.value(2) == true)
    value = false;
else
    value = true;
and the efficient way to write it would be:
Code:
value = !$gameSwitches.value(2);

Code:
<Before Eval>
var targetId = target.actorId();
$gameVariables.setValue(21, targetId);
</Before Eval>[/CODE]
This isn't wrong, but there's also no reason to declare a variable you only use once. It's half as many lines and less typing to simply say
Code:
$gameVariables.setValue(21, target.actorId());

The next part is the common event that is run by this skill.
This reads as unnecessarily convoluted; I don't understand why you're storing the target's ID in your Before Eval if you're just going through strings of functions and variables to go back to the actor in this code. Just store the target actor in the first place.

Code:
<Before Eval>
$gameVariables.setValue(21, target);
</Before Eval>

Then you simply do $gameVariables.value(21)._paramPlus etc.

But, aside from that...do you have some reason to believe that the actor is going to have a paramPlus value for HP? In most games you usually don't, unless you have, like, an accessory that's giving extra HP.
"<Custom Requirement>
if $gameSwitches.setValue(2, true) {
value = false;
} else {
value = true;
}
</Custom Requirement>"

Just letting you know that this if statement will not execute because of how it is written. It needs to be:
JavaScript:
<Custom Requirement>
  if ($gameSwitches.value(2)) {
    value = false;
  } else {
    value = true;
  }
</Custom Requirement>

As for the rest of it, I'll have to take a better look when I get a chance to sit down and check things through.
That's a big off on my part. I copied the code from other skills that do the same thing, and it is written correctly there and everywhere else so I must have messed it up while trying to get the rest of it working. Thanks for pointing it out!

Scratch that, even bigger oof. That skill shouldn't have a conditional in the first place. And I didn't even realize it while testing because it wasn't working in the first place.

@ATT_Turan
This isn't wrong, but there's also no reason to declare a variable you only use once. It's half as many lines and less typing to simply say

Code:

$gameVariables.setValue(21, target.actorId());

That is initially how I wrote it, but I wasn't sure if that syntax was correct so when the skill didn't work, it was one of the first things I changed just to make sure because I knew doing it via variables would work for sure. Good to know I can definitely do it the other way around as well!

But, aside from that...do you have some reason to believe that the actor is going to have a paramPlus value for HP? In most games you usually don't, unless you have, like, an accessory that's giving extra HP.

The "script calls" excel spreadsheet that is available on the forums says that ._paramPlus() will get me the param bonus that is added by .addParam and I have certain skills that add maxHP through that and I'm using those skills each time before testing the stat transfer skills in this thread, so the target should have a _paramPlus value to be stored.

This reads as unnecessarily convoluted; I don't understand why you're storing the target's ID in your Before Eval if you're just going through strings of functions and variables to go back to the actor in this code. Just store the target actor in the first place.

I didn't know you could store an actor in a variable. Would the solution then be something like:

JavaScript:
var paramValue = $gameVariables.value(21)._paramPlus(0);
$gameVariables.setvalue(5, paramValue);
$gameVariables.value(21).addParam(0, -paramValue );
$gameVariables.value(21).gainHp(-paramValue );

Edit: This isn't working either. Nothing gets stored in v[5]

I'll try storing bonus maxhp another way to see if that's the issue.
Edit: This isn't working either. Nothing gets stored in v[5]
I'll try storing bonus maxhp another way to see if that's the issue.
You have the wrong syntax for getting the parameter. It's actor.paramPlus(0) (which is more correct) or actor._paramPlus[0] but you're combining the two, so that code is erroring out.

Get rid of the underscore.
You have the wrong syntax for getting the parameter. It's actor.paramPlus(0) (which is more correct) or actor._paramPlus[0] but you're combining the two, so that code is erroring out.

Get rid of the underscore.
You're right, it's quite strange that all of the other param functions listed in the excel take parenthesis while this one takes brackets.

Still, I've tried both .paramPlus(0) and ._paramPlus[0] just now and, it's still not storing anything into the variable.
just to hint out. .paramPlus(0) and .paramPlus[0] are different
as well for .paramPlus[0] and ._paramPlus[0] are different variables.

so make sure you write the paramPlus in the correct way for whatever
plugin you use, there should be explanation on how to call them correctly.
You're right, it's quite strange that all of the other param functions listed in the excel take parenthesis while this one takes brackets.
No - all functions take parentheses.

So do this:
Code:
<Before Eval>
console.log("Plus is", target.paramPlus(0));
</Before Eval>

Hit F8, go to the Console tab, use the skill and see what it says.
No - all functions take parentheses.

So do this:
Code:
<Before Eval>
console.log("Plus is", target.paramPlus(0));
</Before Eval>

Hit F8, go to the Console tab, use the skill and see what it says.
I'm a bit confused about the brackets thing. If all functions take parentheses, then _paramPlus[0] is not a function?

I've checked out the console and it displays paramPlus value correctly as 6, but I'm seeing an error from another plugin. Although I don't know why that plugin would even be relevant here.

Spoiler: Here's the full log
Plus is 6
YEP_AbsorptionBarrier.js:1466 SCRIPT CALL ERROR
YEP_AbsorptionBarrier.js:1467 var paramValue = $gameVariables.value(21).paramPlus(0);
$gameVariables.setvalue(5, paramValue);
$gameVariables.value(21).addParam(0, -paramValue );
$gameVariables.value(21).gainHp(-paramValue );

YEP_AbsorptionBarrier.js:1468 TypeError: $gameVariables.value(...).paramPlus is not a function
at eval (eval at Game_Interpreter.command355 (YEP_CoreEngine.js:1852), <anonymous>:1:43)
at Game_Interpreter.command355 (YEP_CoreEngine.js:1852)
at Game_Interpreter.executeCommand (rpg_objects.js:8930)
at Game_Interpreter.update (rpg_objects.js:8838)
at Game_Troop.updateInterpreter (rpg_objects.js:5226)
at Function.BattleManager.updateEventMain (rpg_managers.js:2281)
at Function.BattleManager.updateEvent (YEP_BattleEngineCore.js:1962)
at Function.BattleManager.update (YEP_BattleEngineCore.js:1920)
at Scene_Battle.updateBattleProcess (rpg_scenes.js:2265)
at Scene_Battle.update (rpg_scenes.js:2257)
I'm a bit confused about the brackets thing. If all functions take parentheses, then _paramPlus[0] is not a function?
Correct. _paramPlus is a property of Game_BattlerBase which is an array, and you access elements of an array with brackets.

I've checked out the console and it displays paramPlus value correctly as 6, but I'm seeing an error from another plugin. Although I don't know why that plugin would even be relevant here.
So my suggestion about storing the target backfired - just undo that change. Go back to

Code:
$gameVariables.setValue(21, target.actorId())
in your Before Eval, then your script that you had in method 1 for going from there.
I'm a bit confused about the brackets thing. If all functions take parentheses, then _paramPlus[0] is not a function?

I've checked out the console and it displays paramPlus value correctly as 6, but I'm seeing an error from another plugin. Although I don't know why that plugin would even be relevant here.

Spoiler: Here's the full log
Plus is 6
YEP_AbsorptionBarrier.js:1466 SCRIPT CALL ERROR
YEP_AbsorptionBarrier.js:1467 var paramValue = $gameVariables.value(21).paramPlus(0);
$gameVariables.setvalue(5, paramValue);
$gameVariables.value(21).addParam(0, -paramValue );
$gameVariables.value(21).gainHp(-paramValue );

YEP_AbsorptionBarrier.js:1468 TypeError: $gameVariables.value(...).paramPlus is not a function
at eval (eval at Game_Interpreter.command355 (YEP_CoreEngine.js:1852), <anonymous>:1:43)
at Game_Interpreter.command355 (YEP_CoreEngine.js:1852)
at Game_Interpreter.executeCommand (rpg_objects.js:8930)
at Game_Interpreter.update (rpg_objects.js:8838)
at Game_Troop.updateInterpreter (rpg_objects.js:5226)
at Function.BattleManager.updateEventMain (rpg_managers.js:2281)
at Function.BattleManager.updateEvent (YEP_BattleEngineCore.js:1962)
at Function.BattleManager.update (YEP_BattleEngineCore.js:1920)
at Scene_Battle.updateBattleProcess (rpg_scenes.js:2265)
at Scene_Battle.update (rpg_scenes.js:2257)
Just to expand on what ATT_Turan said, this ambiguity is the very reason some variables have an underscore at the beginning of their name; they're meant to denote a private property that shouldn't be modified/accessed in code unless strictly necessary, and also shows that they're separate from functions.

_paramPlus is the array that holds the data; paramPlus(x) is the function that returns a value from it.
Correct. _paramPlus is a property of Game_BattlerBase which is an array, and you access elements of an array with brackets.


So my suggestion about storing the target backfired - just undo that change. Go back to

Code:
$gameVariables.setValue(21, target.actorId())
in your Before Eval, then your script that you had in method 1 for going from there.
Unfortunately still getting the same console message. I've also tried putting the code in the CE directly into the notetag while forgoing the show choice element and still nothing is being assigned to v[5].
Unfortunately still getting the same console message. I've also tried putting the code in the CE directly into the notetag while forgoing the show choice element and still nothing is being assigned to v[5].
Okay, but we need to see what that code actually is, currently. You've had several changes suggested to you.

If you did what I suggested, it would be impossible to be seeing the same error you just posted because that syntax wouldn't exist in your code.
Okay, but we need to see what that code actually is, currently. You've had several changes suggested to you.

If you did what I suggested, it would be impossible to be seeing the same error you just posted because that syntax wouldn't exist in your code.
My bad, here's the last version:

Notetag on the skill:

JavaScript:
<Before Eval>
$gameVariables.setValue(21, target.actorId());
</Before Eval>

And the script on the CE:

JavaScript:
var paramValue = $gameVariables.value(21).paramPlus(0);
$gameVariables.setvalue(5, paramValue);
$gameVariables.value(21).addParam(0, -paramValue );
$gameVariables.value(21).gainHp(-paramValue );

Or did you mean I should go back to assigning actorID to a variable?


Okay, going back to my method of assigning those to variables actually worked.

JavaScript:
var actorId = $gameVariables.value(21);
var paramValue = $gameActors.actor(actorId).paramPlus(0);
$gameVariables.setValue(5, paramValue);
var actor = $gameActors.actor(actorId);
actor.addParam(0, -paramValue );
actor.gainHp(-paramValue );

Above is the code that ended up working without issue. But why?

JavaScript:
var paramValue = $gameVariables.value(21).paramPlus(0);

$gameVariables.setvalue(5, paramValue);

$gameVariables.value(21).addParam(0, -paramValue );

$gameVariables.value(21).gainHp(-paramValue );

Why didn't this one work?
Or did you mean I should go back to assigning actorID to a variable?
Right, that's why I mentioned your Method 1 you had original displayed.

JavaScript:
var actorId = $gameVariables.value(21);
var paramValue = $gameActors.actor(actorId).paramPlus(0);
$gameVariables.setValue(5, paramValue);
var actor = $gameActors.actor(actorId);
actor.addParam(0, -paramValue );
actor.gainHp(-paramValue );
Let me suggest some de-convoluting of that.

Code:
var actor = $gameActors.actor($gameVariables.value(21));
var paramValue = actor.paramPlus(0);
$gameVariables.setValue(5, paramValue);
actor.addParam(0, -paramValue);
actor.gainHp(-paramValue);

I suggest that making extra variables that are only used once makes your code harder to read through.

Why didn't this one work?
I'm not sure, off the top of my head. Probably something in value() or setValue() didn't like setting the variable to an actor object.

What I don't understand is, since that's the original code you had in the first place, what wasn't working when you first posted this thread? You never actually said what the problem was.
@ATT_Turan

Okay, I figured it out. I'm just dumb. I had a capitalization error. I wrote setvalue instead of setValue. Storing the actor in the variable works after correcting that mistake. However, I'm still a bit confused.

After fixing the error, I tried it both ways and:

JavaScript:
$gameVariables.setValue(21, target);

Storing the actor this way allows this code to work:

JavaScript:
var paramValue = $gameVariables.value(21).paramPlus(0);

$gameVariables.setValue(5, paramValue);

$gameVariables.value(21).addParam(0, -paramValue );

$gameVariables.value(21).gainHp(-paramValue );

But if I use my previous method of storing the ActorID by doing this:

JavaScript:
$gameVariables.setValue(21, target.actorId());

then the above code doesn't work and I have to use my original method of assigning it to variables. This method:

JavaScript:
var actor = $gameActors.actor($gameVariables.value(21));
var paramValue = actor.paramPlus(0);
$gameVariables.setValue(5, paramValue);
actor.addParam(0, -paramValue);
actor.gainHp(-paramValue);
@ATT_Turan

Okay, I figured it out. I'm just dumb. I had a capitalization error. I wrote setvalue instead of setValue. Storing the actor in the variable works after correcting that mistake. However, I'm still a bit confused.

After fixing the error, I tried it both ways and:

JavaScript:
$gameVariables.setValue(21, target);

Storing the actor this way allows this code to work:

JavaScript:
var paramValue = $gameVariables.value(21).paramPlus(0);

$gameVariables.setValue(5, paramValue);

$gameVariables.value(21).addParam(0, -paramValue );

$gameVariables.value(21).gainHp(-paramValue );

But if I use my previous method of storing the ActorID by doing this:

JavaScript:
$gameVariables.setValue(21, target.actorId());

then the above code doesn't work and I have to use my original method of assigning it to variables.
The reason for this is that in the first case you're using an actor object, and in the second you're using an ID. An actor ID doesn't have a paramPlus function.


My bad, here's the last version:

Notetag on the skill:

JavaScript:
<Before Eval>
$gameVariables.setValue(21, target.actorId());
</Before Eval>

And the script on the CE:

JavaScript:
var paramValue = $gameVariables.value(21).paramPlus(0);
$gameVariables.setvalue(5, paramValue);
$gameVariables.value(21).addParam(0, -paramValue );
$gameVariables.value(21).gainHp(-paramValue );

Or did you mean I should go back to assigning actorID to a variable?


Okay, going back to my method of assigning those to variables actually worked.

JavaScript:
var actorId = $gameVariables.value(21);
var paramValue = $gameActors.actor(actorId).paramPlus(0);
$gameVariables.setValue(5, paramValue);
var actor = $gameActors.actor(actorId);
actor.addParam(0, -paramValue );
actor.gainHp(-paramValue );

Above is the code that ended up working without issue. But why?

JavaScript:
var paramValue = $gameVariables.value(21).paramPlus(0);

$gameVariables.setvalue(5, paramValue);

$gameVariables.value(21).addParam(0, -paramValue );

$gameVariables.value(21).gainHp(-paramValue );

Why didn't this one work?
In your last code, variable 21 only has the id and not the actor. The value has no properties at all.

For your first code, you reference variable actor as $gameActors.actor(actorId), in which case is variable 21 is a number.

Edit: I think you just posted as I was writing this haha and Trihan right before.

So, would this be a dual ninja'd or double ninja'd case?



In your last code, variable 21 only has the id and not the actor. The value has no properties at all.

For your first code, you reference variable actor as $gameActors.actor(actorId), in which case is variable 21 is a number.

Edit: I think you just posted as I was writing this haha and Trihan right before.

So, would this be a dual ninja'd or double ninja'd case?
Just ninjas all over the shop, really.
Storing the actor this way allows this code to work:
But if I use my previous method of storing the ActorID by doing this...then the above code doesn't work
Of course it doesn't. Do you not get the difference between the actor and the actor's ID?

So the actor is all of the information needed for the game to display, reference, use, an actor.

The ID is just one part of that.

That's like saying "I can open the window of my house when I go to the house, but I can't open the window when I tug on the street number nailed to my mailbox."

Even without understanding the code part of it, logically if you know you're storing two different things you shouldn't expect to be able to treat them the same way 😉

Original thread: https://forums.rpgmakerweb.com/threads/what-am-i-doing-wrong-here.167603/