Target.isActor() || target.isEnemy()
JavaScript questions that don't deserve their own thread
Javascript/Plugin SupportTarget.isActor() || target.isEnemy()
That works perfectly, thanks.
How can I check if a switch is on using javascript? I tried using this:
if($gameSwitches[0016]){
}
But it doesn't seem to be working.
if($gameSwitches[0016]){
}
But it doesn't seem to be working.
Code:
if ($gameSwitches.value(16)) {
}
A question:
How can I determine what is the id of the item currently being selected when I am in the Items Menu? For example, I went to the menu, selected Item, and there I have three items, Potion, Ether and Antidote. If my cursor is in Ether, how would I determine the id of Ether?
How can I determine what is the id of the item currently being selected when I am in the Items Menu? For example, I went to the menu, selected Item, and there I have three items, Potion, Ether and Antidote. If my cursor is in Ether, how would I determine the id of Ether?
Thank you!!
So to check if a switch is on I use
if ($gameSwitches.value(16)) {
}
How do I check if it's off?
if ($gameSwitches.value(16)) {
}
How do I check if it's off?
if (!$gameSwitches.value(16)) {
}
@Milena
Code:
Window_ItemList.prototype.select = function(index) {
Window_Selectable.prototype.select.call(this, index);
if (index >= 0) {
console.log(this._data[index].id);
}
};
The id of the last item used by the party is always stored in this:
$gameParty._lastItem._itemId
I've found it particularily useful when making common events, now I have a single one for all my items and I just check which one was used, it saves space and no fear of common event limit now.
Edit: Ah it seems i've misread the question... I'm still leaving this here in case someone has use for it, but sadly I have no idea on how to read the current cursor position.
Huge thanks to all who have helped me so far in this thread. I'm sloooowly relearning how to code, haha.
How can I concatenate (add) text to an in-game variable?
I know to set a variable I do
$gameVariables.setValue(var, value);
But how do I add a (text) value to one?
How can I concatenate (add) text to an in-game variable?
I know to set a variable I do
$gameVariables.setValue(var, value);
But how do I add a (text) value to one?
var string = $gameVariables.value(1) + " my addition";
$gameVariables.setValue(1, string);
Replacing 1 with variable id.
Thanks so much for the help, again. I have a slightly more difficult one this time.
var song = "Z";
if(Input.keyTriggered("M")) {song +="M"; $gameVariables.setValue(15, song);}
}
if(Input.keyTriggered("K")) song +="K"; $gameVariables.setValue(15, song);}
This is running in a parallel common event. I want it to add the text value of the key pressed to the variable with ID 15. So if the user presses MKMK, then the variable with ID 15 should be "ZMKMK".
The problem is the variable ID 15 keeps getting set to "ZM" or "ZK". If the user presses a key it just overwrites the last one instead of adding to the end.
I have a suspicion that because I am setting the temporary var song in this parallel event, it just keeps resetting itself to "Z" over and over. Is this right? How could I fix that?
var song = "Z";
if(Input.keyTriggered("M")) {song +="M"; $gameVariables.setValue(15, song);}
}
if(Input.keyTriggered("K")) song +="K"; $gameVariables.setValue(15, song);}
This is running in a parallel common event. I want it to add the text value of the key pressed to the variable with ID 15. So if the user presses MKMK, then the variable with ID 15 should be "ZMKMK".
The problem is the variable ID 15 keeps getting set to "ZM" or "ZK". If the user presses a key it just overwrites the last one instead of adding to the end.
I have a suspicion that because I am setting the temporary var song in this parallel event, it just keeps resetting itself to "Z" over and over. Is this right? How could I fix that?
You could use a loop to stop it from resetting the variables every couple of frames, and set a self switch in the event to turn it off after it gets as many letters as you're looking for.
Code:
var song = 'Z'
var i = 0
do {
if(Input.keyTriggered("M")) {
{song +="M";
$gameVariables.setValue(15, song);}
i++;
}else if(Input.keyTriggered("K")) {
song +="K";
$gameVariables.setValue(15, song);
i++;
}
}
while (i < 6);
I think I understand this concept, so I tried it.
Now whenever I press the button to activate the common event this is in, the game freezes (like, super freezes. Have to use task manager to close it)
Here's the new code:
var song = "Z";
var songIndex = 0;
do{
if(Input.keyTriggered("M")){
song +="A"; $gameVariables.setValue(15, song); songIndex++;
}
if(Input.keyTriggered("K")){
song +="G"; $gameVariables.setValue(15, song); songIndex++;
}
}
while(songIndex < 10);
Hard freezing is a sign of a loop that never ends. Although I can't see why that'd happen in your case here. I'm not so good with the coding, I try to help where I can XD
Could it be because this is running in a parallel event? Here's my actual, unedited code.
var song = "Z";
var songIndex = 0;
do{
if(Input.keyTriggered("M")){
if(Input.keyPressed("B")){ song +="F"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("V")){ song +="E"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("C")){ song +="D"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("X")){ song +="C"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("Z")){ song +="B"; $gameVariables.setValue(15, song); songIndex++;}
else{song +="A"; $gameVariables.setValue(15, song); songIndex++;}
}
if(Input.keyTriggered("K")){
if(Input.keyPressed("G")){ song +="L"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("F")){ song +="K"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("D")){ song +="J"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("S")){ song +="I"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("A")){ song +="H"; $gameVariables.setValue(15, song); songIndex++;}
else{song +="G"; $gameVariables.setValue(15, song); songIndex++;}
}
}
while(songIndex < 10);
var song = "Z";
var songIndex = 0;
do{
if(Input.keyTriggered("M")){
if(Input.keyPressed("B")){ song +="F"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("V")){ song +="E"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("C")){ song +="D"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("X")){ song +="C"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("Z")){ song +="B"; $gameVariables.setValue(15, song); songIndex++;}
else{song +="A"; $gameVariables.setValue(15, song); songIndex++;}
}
if(Input.keyTriggered("K")){
if(Input.keyPressed("G")){ song +="L"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("F")){ song +="K"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("D")){ song +="J"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("S")){ song +="I"; $gameVariables.setValue(15, song); songIndex++;}
else if(Input.keyPressed("A")){ song +="H"; $gameVariables.setValue(15, song); songIndex++;}
else{song +="G"; $gameVariables.setValue(15, song); songIndex++;}
}
}
while(songIndex < 10);
I'm prett sure I could fix all of this if there was a way to concatenate the letter to the actual variable directly. The temporary variable "song" is getting set to zero every frame because this is a parallel event, So instead of making the temporary variable, concatenating the letter pressed to it, and then setting the main variable, if I could just concatenate it to the main variable, I think it would fix my problem.
is there a way to do this?
is there a way to do this?
Control Variables: (select variable) > Set > Script > $gameVariables.value(variable_id) + "letter"
You can't use the Add/+ operator because it tries to do a mathematical operation and will fail. But you can set it to a combination of itself plus a string using the Script option.
Of course, if this is a parallel event, you'll have to be careful because you could end up adding an extra letter to the end in an infinite loop.
You can't use the Add/+ operator because it tries to do a mathematical operation and will fail. But you can set it to a combination of itself plus a string using the Script option.
Of course, if this is a parallel event, you'll have to be careful because you could end up adding an extra letter to the end in an infinite loop.
Thank you! I'm not using point and click events for this, just script, but I tried plugging it in anyway. So this is what it looks like now.
if(Input.keyTriggered("M")){
$gameVariables.value(15) + "A";}
In a parallel event that is called when the player presses "1". When I look at the variables while testing it though, it doesn't seem to change.
Did I type it in wrong?
Edit:never mind, you are a genius. Instead of trying to do it all in one script I just had the script call a common event to add the letter the way you said. Works perfectly! Thanks a million.
Original thread: https://forums.rpgmakerweb.com/threads/javascript-questions-that-dont-deserve-their-own-thread.46341/