I have a quick question regarding || (or). How come something like this:
if (target.battleSkills().contains($dataSkills[19] || target.battleSkills().contains($dataSkills[20])
That's incorrect syntax, because it's missing a closed parentheses, but that's not the point at the moment
:wink:
...can't be written as:
if (target.battleSkills().contains($dataSkills[19] || $dataSkills[20])
Because || is boolean OR. All it does is return the first side of the operation that has a non-falsy value. It doesn't get passed as an expression into a function to somehow change what that function does, any more than you'd see any difference between
$dataSkills[2+2] or
$dataSkills[4].
In this example, you're asking "Which of these database entries exists? Pass that one into contains()" which is pointless. They both exist, because you have skills 19 and 20 in your database, so it will always be skill 19. And if you
didn't have both, there's no reason to check for it in your code, you know as the developer that you didn't make skill 19.
...or:
if (target.battleSkills().contains($dataSkills[19 || 20])
?
Again, OR is going to return the first operand that has value. Since both 19 and 20 are non-zero values, it will always return 19, which gets referenced by the array. Then, the element returned by the array gets passed as the argument into the function.
You're trying to think about it linguistically, like you'd say in a sentence "Do you have this or this?" but it's a mathematical operation.
Edit: Also, I noticed that both user.battleSkills().contains($dataSkills[15]) and user._battleSkills.contains(15) return the same result. So is there a reason I should use the longer version over the shorter one?
That can't be correct, unless that result is
false. Where is this battleSkills coming from? It must be a plugin, as it doesn't exist in the base code.
$dataSkills[15] returns an object of type SKILL, with all of the member variables and functions inherent to that. If your battleSkills array is also of type SKILL, it would be impossible for you to get a
true result when comparing one of those objects to the integer value 15.
Similarly, if battleSkills is an array of numbers representing skill IDs, it would be impossible to pass in a SKILL object and get a
true comparison to any element. See my example below:
I want to display a message window in combat without hiding battle UI. How can I do that?
Are you in the right forum/thread? You're asking about JavaScript, but your profile says you're using VX Ace, which is based on Ruby.
If you
are in the right place, then it depends whether you're using MV or MZ. For MV, Yanfly has message plugins that control where on the screen the message window is displayed (as does Galv, I believe). You could try one of those - but this is really a question for a plugin thread, not JavaScript as there's not a single JS command that would accomplish this, as far as I know.