Issue with scope + a few questions

Hey y'all, so I've been testing out a few new abilities and stumbled upon an issue. The skill in particular has the following code:


JavaScript:
<Before Eval>
 function lifeBloom(actor) {
    if ( actor.isStateAffected(35))
       actor.gainHp(10);
       actor.removeState(35);
}

    $gameParty.members().forEach(element => lifeBloom(element));
</Before Eval>

After trying out a few different versions of the code, I got the ability to work. But when I choose the "none" option on the scope menu, the ability stops working. However, it works with any other scope, including when setting the scope to the enemy. Now, I guess this isn't a big problem as I can easily just use another scope but I'm not sure what's the cause of this. I'm thinking maybe the "none" scope has some unique properties but I couldn't find any explanation about it through Google. Does anyone know why this is the case?

Aside from this, I have two more questions:

1)

JavaScript:
$gameParty.members().forEach(element => element.lifeBloom(element));

This was the initial way that I tried, but I got the error element.lifeBloom is not a function.

JavaScript:
$gameParty.members().forEach(actor => actor.removeState(35));

Above example is something I use elsewhere, and it works. So, my question is why does one work and the other doesn't? My guess is that a dot function has to be defined as a property of an object and the function I defined is global? I may be completely making this up, so I'd appreciate some clarification.

2)

My second question is, am I overcomplicating this? Do I even need to define a function, or can I do what the function does inside the forEach method? Is there a way easier method to do what I'm trying to do?
My second question is, am I overcomplicating this?
Yes.

Do I even need to define a function
No. I have no idea why you are 😛

can I do what the function does inside the forEach method?
Yes. And it takes up fewer lines and less keystrokes that way. 😉

Code:
<Before Eval>
$gameParty.members().forEach(actor =>
{
    if (actor && actor.isStateAffected(35))
    {
        actor.gainHp(10);
        actor.removeState(35);
    }
});
</Before Eval>

You might not need the if (actor) portion, but some of the $game arrays are null-terminated, i forget which ones, and it costs almost nothing to include that vs. me taking time to look it up 😛

Edit: I missed the actual first question. A scope of None means the skill has no target, in which case the engine skips Game_Action.apply() which is where the Before Eval notetag is executed.
@ATT_Turan

Once again thank you for the concise and informative explanations!

I had a feeling I was overcomplicating this. The reason I went the function route is that while I've done a lot of reading since the last time I posted on the forums, I'm still not confident about using the arrow function and I couldn't for the life of me figure out the correct syntax with both that and adding an if statement in there.

Now, while your version is exactly what I wanted to do in the first place, is there anything really bad about doing it via a function like I did, except for the efficiency?

The bit about the scope of None is also interesting. I suppose it may be possible to use that scope if I put the code in a different notetag, but just using a different scope seems safer and easier.
Now, while your version is exactly what I wanted to do in the first place, is there anything really bad about doing it via a function like I did, except for the efficiency?
There's nothing really evil about it, but it's bad pratice. Theoretically, you could separate out every code statement line by line into its own function and then have endless lines of function calls 😛

The point of functions is to store code you're going to execute in repeated places throughout your program. There's no reason to write a function that only gets used in one place.
@ATT_Turan

I didn't realize it yesterday because I didn't have time to test it, but you are missing a parenthesis after members.

For anyone who might have use for a similar code, the correct version is this:

JavaScript:
<Before Eval>
$gameParty.members().forEach(actor =>
{
    if (actor && actor.isStateAffected(35))
    {
        actor.gainHp(10);
        actor.removeState(35);
    }
});
</Before Eval>

Other than that, it works perfectly. Thank you once again for helping me refine my code. At this rate, I'm going to have to dedicate a whole page to you in my credits if I actually manage to get my project finished. 😀

Original thread: https://forums.rpgmakerweb.com/threads/issue-with-scope-a-few-questions.169669/