JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 10 of 171 View original ↗
  1. Thanks for helping me with my last question, :)   is there a script that an event could even move diagonally towards the player? I use Smart Path but the event is sadly not using the shortest way all the time. So is there a small line of code which makes it possible for events, if they are moving towards the player, that they even could even use diagonal movement? 
  2. [EDIT] Nvm, I messed up the tested event. I got it all gravy now. 
  3. if($gameVariables.Value(67,1) {$gameVariables.setValue(68, "Just Another Fetch Quest"); }elseif($gameVariables.Value(67,2) {$gameVariables.setValue(68, "Revenge"); }else{if($gameVariables.Value(67,3) {$gameVariables.setValue(68, "Out of Control"); }else{if($gameVariables.Value(67,4) {$gameVariables.setValue(68, "Leave Me Alone"); }In this code I'm trying to assign a quest name to a variable depending in another variable that is defined before the script call is made. This newly defined variable would then be printed in a text box.

    The only problem is I keep getting an error. 

    Back in RPG Maker VX Ace I made a similar conditional branch that looked like this

    $game_variables[68] = case $game_variables[67] when 1 "Just Another Fetch Quest" when 2 "Revenge" when 3 "Out of Control" when 4 "Leave Me Alone" when 5 "Flowers for Mom" when 6 "Healing Burns" when 7 "Epic Lootz" when 8 "Scavenger Hunt" when 9 "Finding a Tenant" when 10 "Dessert in the Desert" endIs there a way to duplicate this in Javascript for RPG Maker MV?
  4. ragnorak6608 said:
    if($gameVariables.Value(67,1) {$gameVariables.setValue(68, "Just Another Fetch Quest"); }elseif($gameVariables.Value(67,2) {$gameVariables.setValue(68, "Revenge"); }else{if($gameVariables.Value(67,3) {$gameVariables.setValue(68, "Out of Control"); }else{if($gameVariables.Value(67,4) {$gameVariables.setValue(68, "Leave Me Alone"); }In this code I'm trying to assign a quest name to a variable depending in another variable that is defined before the script call is made. This newly defined variable would then be printed in a text box.

    The only problem is I keep getting an error. 

    Back in RPG Maker VX Ace I made a similar conditional branch that looked like this

    $game_variables[68] = case $game_variables[67] when 1 "Just Another Fetch Quest" when 2 "Revenge" when 3 "Out of Control" when 4 "Leave Me Alone" when 5 "Flowers for Mom" when 6 "Healing Burns" when 7 "Epic Lootz" when 8 "Scavenger Hunt" when 9 "Finding a Tenant" when 10 "Dessert in the Desert" endIs there a way to duplicate this in Javascript for RPG Maker MV?
    If you get errors, it would help to know which errors you're getting ;)

    About your if/else syntax:

    If that is exactly what you've in your code, then there are errors in the syntax.

    For example you're missing a closing parenthesis after every  $gameVariables.value(67,X).

    And you have two opening brackets right before the last two "if"s.

    What's more, how you check the conditions is wrong, too

    It should be

    if($gameVariables.Value(67) === 1) {$gameVariables.setValue(68, "Just Another Fetch Quest"); }else if($gameVariables.Value(67) === 2) {$gameVariables.setValue(68, "Revenge"); }else if($gameVariables.Value(67) === 3) {$gameVariables.setValue(68, "Out of Control"); }else if($gameVariables.Value(67) === 4) {$gameVariables.setValue(68, "Leave Me Alone"); }But there is a switch statement in javascript like the one you postet.

    Code:
    switch($gameVariables.Value(67)) {    case 1:        $gameVariables.setValue(68, "Just Another Fetch Quest");        break;    case 2:        $gameVariables.setValue(68, "Revenge");        break;    case 3:        $gameVariables.setValue(68, "Out of Control");        break;    case 4:        $gameVariables.setValue(68, "Leave Me Alone");        break;        }
  5. Hi there!

    I'm trying to read the value entered in the "Note" field for an event. I tried finding it in the source, but couldn't. Would anyone be so kind to point me in the right direction?
  6. ragnorak6608

    You also have two more ways to do it.

    1) With ?: operator 

    $gameVariables.setValue(68, $gameVariables.value(67) === 1 ? "Just Another Fetch Quest" : $gameVariables.value(67) === 2 ? "Revenge" : $gameVariables.value(67) === 3 ? "Out Of Control" : $gameVariables.value(67) === 4 ? "Leave Me Alone" : "");What ?: operator actually does is evaluates a condition before ? sign, and if it's true executes the expression between ? and : sign, and if it's not evaluates the expression after : sign, so

    console.log(1 > 2 ? 100 : 200)will log 200 to console, because 1 is not greater than 2.

    2) With array :

    var myArray = [null, "Just Another Fetch Quest", "Revenge", "Out Of Control", "Leave Me Alone"];$gameVariables.setValue(68, myArray[$gameVariables.value(67)]);Note that in this code you'll set Variable #0068 to null if #0067 is not 1, 2, 3 or 4.

    I prefer doing it this way.

    Also, about if/else if/else syntax, it goes like this :

    if(condition1) thisIsAnExpressionInOneRow;else if(condition2){    // Those are expressions in more than one row, and will only be executed if condition1 is false and condition 2 is true    someMethod();    someOtherMethod();}else{    // This will be executed if condition1 and condition2 are both false.}Sulsay

    Usually, you would access all events on a map with $gameMap.events(), and if you want to to read event's note you would do :

    nope, this is wrong, check @Iavra's post belowWhy do you need it?
  7. This should do it:

    Code:
    $gameMap.event(your_event_id).event().note;
    /edit: Or directly from $dataMap via:
    Code:
    $dataMap.events[your_event_id].note
  8. I want to do more alias identifier, but it gives me an error. For example:

    var Milena = Milena || {};Milena.StateCrush = { structAliases: { Game_Battler: { removeState: Game_Battler.prototype.removeState } // when I place new stuff here, such as: // Game_Actor: {setup}..... }};As given in the comments, I placed Game_Actor so I can alias it with it but then it says there's an unexpected identifier. I also tried going out inside struct aliases to create another one structAliases but it says it can't be done. Am I doing anything wrong?
  9. @Milena

    Code:
    Game_Battler: {removeState: Game_Battler.prototype.removeState}, // <-- add a comma hereGame_Actor: {}
  10. @Ramiro, thanks a lot! I have a question about states. So I made a snippet that changes my SV battlers when they have a certain state within them:

    Sprite_Actor.prototype.update = function() { Sprite_Battler.prototype.update.call(this); this.updateShadow(); if (this._actor) { this.updateMotion(); var name = this._actor.battlerName(); if (this._actor._states.contains(12)){ this._mainSprite.bitmap = ImageManager.loadSvActor(name+"2"); } } };I want to check the overall states of that current actor, but instead of having it contain a certain state, I want to check all the states of the actor if they have the tag <change> in them. How would I go along doing that? The for loop doesn't seem to work in my case.
  11. Sprite_Actor.prototype.checkChangeState = function(){    for(var i = 1; i < this._actor.states().length; ++i)    {        var state = this._actor.states();        if(state.note.contains("<change>"))return true;    }    return false;}Then replace the this._actor._states.contains(12with this.checkChangeState()I think something like that would work
  12. Tried doing this:

    Sprite_Actor.prototype.update = function() { Sprite_Battler.prototype.update.call(this); this.updateShadow(); if (this._actor) { this.updateMotion(); var name = this._actor.battlerName(); if (this.checkChangeState()){ this._mainSprite.bitmap = ImageManager.loadSvActor(name+"2"); } } };Sprite_Actor.prototype.checkChangeState = function(){ for(var i = 1; i < this._actor.states().length; ++i) { var state = this._actor.states(); if(state.note.contains("<change>"))return true; } return false;}No errors but the battler does not change.
  13. (About reading the event note)

    KockaAdmiralac said:
    Usually, you would access all events on a map with $gameMap.events(), and if you want to to read event's note you would do :

    nope, this is wrong, check @Iavra's post belowWhy do you need it?
    Iavra said:
    This should do it:

    $gameMap.event(your_event_id).event().note;/edit: Or directly from $dataMap via:
    Code:
    $dataMap.events[your_event_id].note
    Thanks, this works! Turns out I forgot to call event() on the results of $gameMap.eventsXy(). But it works now, cool!

    KockaAdmiralac, I'm using the note to assign specific behavior to events for a jump-plugin that I'm working on. Some events can be jumped over, others cannot. This can be controlled with a keyword in the event note.

    Edit: I'm talking about this plugin :)
  14. gonna try asking this here because I haven't had any luck in other threads, I changed my font size to be larger and now some of the long letters get cut off at the bottom such as g and y, i need to somehow move all the text up on the y axis slightly , how would i go about doing that? im using YEP_message core but i dont see any options to change the position of the text 
  15. I suppose here is as good of a place as any to ask this question, since if I want to make *better* games with RPG Maker MV, I'm going to need to learn how to manipulate them.

    I've put in roughly the whole pack of Yanfly plugins into a dump project just to see how they work.

    I'm pretty sure that I'm going to screw this completely up and have no guidance for it whatsoever, which may end up discouraging me from ever using plugins from expanding on game features ever again.

    Once the plugin is "installed" and loaded into the project, does it just work right out of the box, or am I supposed to start using JS to build my project instead of the normal database?  I'm so super confused about where to even start.
  16. Prizm Daystar said:
    Once the plugin is "installed" and loaded into the project, does it just work right out of the box, or am I supposed to start using JS to build my project instead of the normal database?  I'm so super confused about where to even start.
    You don't need to do anything special.

    Just follow the instructions on how to use the plugins.

    For Yanflys plugins there is a lot of text in the help section of every plugin.
  17. kiriseo said:
    You don't need to do anything special.

    Just follow the instructions on how to use the plugins.

    For Yanflys plugins there is a lot of text in the help section of every plugin.
    Ooh,  I didn't see the big shiny help button in the menu after choosing to edit the listed plugin.  Thanks!  Gonna copy all these help files to text for faster personal reference.
  18. How do you properly define the class of an actor in Game Battler? I want to check the current class of the actor if he has a note tag, like this:

    Game_Battler.prototype.useItem = function(item) { milenaalias(this); if (this instanceof Game_Actor || $dataClasses[this._class._classId].note.match(/<\s*danger\s*>/im)) { this._danger= true; } };my $dataClasses[this._class._classId] does not work.
  19. Game_Battler is the superclass of Game_Actor and Game_Enemy. Only the former one actually can have classes, so the code won't work for enemies.

    Regarding classes, you can get the current one via Game_Actor.currentClass:

    Code:
    Game_Actor.prototype.currentClass = function() {    return $dataClasses[this._classId];};