JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 25 of 171 View original ↗
  1. ramza said:
    I'm trying to correct a stupid problem in an action sequence, and to do it, I need to know if the target of an action is an enemy or an ally.


    Does anyone know what function to call to check this in a true/false way?


    target.isAlly() and target.isFriendly() are all I can come up with right now, and neither of them work.


    thanks in advance.

    Target.isActor() || target.isEnemy()
  2. 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.
  3. Songsmith said:
    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.
    Code:
    if ($gameSwitches.value(16)) {
    }
  4. 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?
  5. DreamX said:
    if ($gameSwitches.value(16)) {
    }

    Thank you!!
  6. So to check if a switch is on I use 


    if ($gameSwitches.value(16)) {
    }


    How do I check if it's off?
  7. Songsmith said:
    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)) {
    }


    @Milena

    Milena said:
    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?


    Code:
    Window_ItemList.prototype.select = function(index) {
        Window_Selectable.prototype.select.call(this, index);
        if (index >= 0) {
           console.log(this._data[index].id);     
        }
    };
  8. Milena said:
    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?

    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.
  9. 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?
     
  10. Songsmith said:
    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?
     

    var string = $gameVariables.value(1) + " my addition";
    $gameVariables.setValue(1, string);


    Replacing 1 with variable id.
  11. 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?
  12. Songsmith said:
    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?



    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);
  13. ramza said:
    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.



    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);
  14. 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
  15. 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);
  16. Ninkoro said:
    How do I call the self event in a script call?


    For example:


    $gameMap.event(id).requestBalloon(4);


    what do I put in the id space if I want it to call itself. I remember "event_id" worked in Ace, however it doesn't seem to be the same name in mv.


    Thanks for your time.

    Bump
  17. 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?
  18. 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.
  19. Shaz said:
    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.



    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.