JavaScript questions that don't deserve their own thread

Discussion in 'Javascript/Plugin Support' started by Shaz, Oct 23, 2015.

  1. MrPurpleDreadlocks

    MrPurpleDreadlocks Veteran Veteran

    Messages:
    159
    Likes Received:
    19
    First Language:
    English
    Target.isActor() || target.isEnemy()
     
    ramza likes this.
  2. ramza

    ramza Lunatic Coder Veteran

    Messages:
    540
    Likes Received:
    295
    Location:
    Nova Scotia, Canada
    First Language:
    English
    Primarily Uses:
    RMMV
    That works perfectly, thanks.
     
  3. Songsmith

    Songsmith Veteran Veteran

    Messages:
    64
    Likes Received:
    3
    First Language:
    English
    Primarily Uses:
    N/A
    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.
     
  4. DreamX

    DreamX Veteran Veteran

    Messages:
    816
    Likes Received:
    813
    First Language:
    English
    Code:
    if ($gameSwitches.value(16)) {
    }
     
    Songsmith likes this.
  5. Milena

    Milena The woman of many questions Veteran

    Messages:
    1,282
    Likes Received:
    106
    Location:
    Ireland
    First Language:
    Irish
    Primarily Uses:
    N/A
    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?
     
  6. Songsmith

    Songsmith Veteran Veteran

    Messages:
    64
    Likes Received:
    3
    First Language:
    English
    Primarily Uses:
    N/A
    Thank you!!
     
  7. Songsmith

    Songsmith Veteran Veteran

    Messages:
    64
    Likes Received:
    3
    First Language:
    English
    Primarily Uses:
    N/A
    So to check if a switch is on I use 


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


    How do I check if it's off?
     
  8. DreamX

    DreamX Veteran Veteran

    Messages:
    816
    Likes Received:
    813
    First Language:
    English
    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);     
        }
    };
     
    Last edited by a moderator: Jun 19, 2016
    Milena and Songsmith like this.
  9. Astfgl66

    Astfgl66 Veteran Veteran

    Messages:
    659
    Likes Received:
    503
    First Language:
    French
    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.
     
    Last edited by a moderator: Jun 19, 2016
  10. Songsmith

    Songsmith Veteran Veteran

    Messages:
    64
    Likes Received:
    3
    First Language:
    English
    Primarily Uses:
    N/A
    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?
     
     
  11. DreamX

    DreamX Veteran Veteran

    Messages:
    816
    Likes Received:
    813
    First Language:
    English
    var string = $gameVariables.value(1) + " my addition";
    $gameVariables.setValue(1, string);


    Replacing 1 with variable id.
     
    Songsmith likes this.
  12. Songsmith

    Songsmith Veteran Veteran

    Messages:
    64
    Likes Received:
    3
    First Language:
    English
    Primarily Uses:
    N/A
    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?
     
    Last edited by a moderator: Jun 19, 2016
  13. ramza

    ramza Lunatic Coder Veteran

    Messages:
    540
    Likes Received:
    295
    Location:
    Nova Scotia, Canada
    First Language:
    English
    Primarily Uses:
    RMMV


    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);
     
    Last edited by a moderator: Jun 19, 2016
  14. Songsmith

    Songsmith Veteran Veteran

    Messages:
    64
    Likes Received:
    3
    First Language:
    English
    Primarily Uses:
    N/A


    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);
     
    Last edited by a moderator: Jun 20, 2016
  15. ramza

    ramza Lunatic Coder Veteran

    Messages:
    540
    Likes Received:
    295
    Location:
    Nova Scotia, Canada
    First Language:
    English
    Primarily Uses:
    RMMV
    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
     
  16. Songsmith

    Songsmith Veteran Veteran

    Messages:
    64
    Likes Received:
    3
    First Language:
    English
    Primarily Uses:
    N/A
    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);
     
  17. Ninkoro

    Ninkoro Veteran Veteran

    Messages:
    36
    Likes Received:
    1
    Bump
     
  18. Songsmith

    Songsmith Veteran Veteran

    Messages:
    64
    Likes Received:
    3
    First Language:
    English
    Primarily Uses:
    N/A
    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?
     
  19. Shaz

    Shaz Veteran Veteran

    Messages:
    37,706
    Likes Received:
    11,411
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    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.
     
    Last edited by a moderator: Jun 20, 2016
    Songsmith likes this.
  20. Songsmith

    Songsmith Veteran Veteran

    Messages:
    64
    Likes Received:
    3
    First Language:
    English
    Primarily Uses:
    N/A


    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.
     
    Last edited by a moderator: Jun 20, 2016

Share This Page