MV - HELP | How set a Wait using JS

● ARCHIVED · READ-ONLY
Started by STARFALL 15 posts View original ↗
  1. first look at this piece of code:

    $gameScreen.showPicture(1,'test1(9x12)', 1, 1366, 700,200,200,0,0);
    $gameScreen.movePicture(1,1, 1166, 700, 200, 200, 255,0,20);
    $gameScreen.picture(1).setSpritesheetFrame(2);
    ◆Wait:1
    $gameScreen.picture(1).setSpritesheetFrame(3);
    ◆Wait:1
    $gameScreen.picture(1).setSpritesheetFrame(4);
    etc

    You see, I am looking for a way to make an image be shown during the selection of skills, until there is everything is on the right track although not working at all. but to complement this I want the image to change for another from time to time. But I don't know how I can make it wait before switching to the next image.

    I change the images using the command within Yep Sprite Sheet images. In general, the image that I load is a spriteSheet and I make it change from time to time. Outside of battle it works with common event, but when I try to call it inside it does not work, I call it when the skills are being selected. So I opted to do it using js. now the image is displayed but I don't know how to make it wait before showing the next frame
  2. JavaScript:
    this.wait(frames)
    Only one wait will work in a script call. It's because a script call runs everything at once within that block. The only way to work around with it is having a custom method or set a timeout.

    Reference:
    RMMV Script Calls
  3. And that must be a headache right? I think I will need more help than I thought.
  4. some stuff needs to be in a seperated code action chain..
    stuff like "wait" or "call common events"..
    i guess thats because the system reads everything within 1 frame..

    therefor i used stuff like export code parts in common events or using switches with an update-function., but i am a noob in JS myself so i probably cant give the best advice..
  5. I'm sorry, but what is the need to put a timer in the middle of the code?
    If you are creating a "plugin" and really need some of the code to take longer to run, use this native function:
    setTimeout(function(){ alert("Hello World"); }, 3000); //3000ms = 3 Seconds

    Example with 3-second intervals at each run.
    JavaScript:
    setTimeout(function(){
       alert("Hello World");
    }, 3000);
    
    setTimeout(function(){
       alert("Hello Moon");
    }, 6000);
    
    setTimeout(function(){
       alert("Hello Mars");
    }, 9000);
    Do not use this within events of Rpg Maker.
  6. Dopan said:
    some stuff needs to be in a seperated code action chain..
    stuff like "wait" or "call common events"..
    i guess thats because the system reads everything within 1 frame..

    therefor i used stuff like export code parts in common events or using switches with an update-function., but i am a noob in JS myself so i probably cant give the best advice..
    I was reviewing and I found a post of yours where Caethyril and Andar helped you create several commands in time within a single Scrip call, it does not look easy I admit but I will try to try it seems to be a good option.

    Dev_With_Coffee said:
    I'm sorry, but what is the need to put a timer in the middle of the code?
    If you are creating a "plugin" and really need some of the code to take longer to run, use this native function:
    setTimeout(function(){ alert("Hello World"); }, 3000); //3000ms = 3 Seconds

    Example with 3-second intervals at each run.
    JavaScript:
    setTimeout(function(){
       alert("Hello World");
    }, 3000);
    
    setTimeout(function(){
       alert("Hello Moon");
    }, 6000);
    
    setTimeout(function(){
       alert("Hello Mars");
    }, 9000);
    Do not use this within events of Rpg Maker.
    Yes, you are right, right now I am reading a method that should work but it will take a while, it will be a matter of trial and error.
  7. All Javascript commands are executed almost at the same time, so I made this example which is very intuitive.

    I particularly prefer to create customized systems for events, such as menus, effects, calculations.
    I only use Javascript to access functions that events cannot.
  8. well I will leave a link to the post to which I refer in case someone wants to help me, I hope
    Dopan Post

    I am not a great user of js, so any help is good for me, mine has always been the visual section
    First I will get to understand how splice () works. then I will see what magic is necessary to achieve the rest
  9. STARFALL said:
    well I will leave a link to the post to which I refer in case someone wants to help me, I hope
    Dopan Post

    I am not a great user of js, so any help is good for me, mine has always been the visual section
    First I will get to understand how splice () works. then I will see what magic is necessary to achieve the rest
    the post you are refferng to, shows a solution that works only within a "game interpreter prototype"-function

    i guess what you need are plugin switches that are connected with some update-functions..

    so that some stuff only happens when the update function knows that the switch has changed
    (instead of let everything happening within 1 frame)

    sry i cant give a proper example..

    or you could call a common event which is attached to the plugins parameter.. and let "the show img stuff" and "wait stuff" happen in that common event,where the "wait event command" will work correctly..


    -> but i think the best would be to explain more detailed what exactly you want to archieve and hope for a pro.JS_user
    to help you out with a simpler solution
  10. Dev_With_Coffee said:
    Array splice() Method:
    W3Schools online HTML editor
    Thanks for the link, I'll try it in the morning; I'm already a bit of a zombie for that

    @Dopan You are absolutely right, I will detail it below:

    I want to achieve a bust image, but not the classic image that appears and that's what I'm using Yep SpriteSheet Image for. The one that allows you to read a SpriteSheet and make the image change between its frames using this command: $gameScreen.picture(1).setSpritesheetFrame(2);
    this causes image one that is read as frames thanks to this plugin to go to frame 2.
    I made a common event in parallel process that is triggered when switch 6 is activated. Which shows an animated image of about 50 Frames, pausing a frame between each command
    Example:
    $gameScreen.picture(1).setSpritesheetFrame(1);
    Wait: 1
    $gameScreen.picture(1).setSpritesheetFrame(2);
    Wait: 1
    $gameScreen.picture(1).setSpritesheetFrame(3);
    Wait: 1
    ....Until 50...
    But it does not show when it is the actor's turn to choose his abilities using the common event method. So I decided to convert it to js, and here if it is shown and hidden when I order it, with the required fade.
    So far, the problem is that I do not know how to make it wait a while before going to the next frame, without interrupting the progress of the game. So I thought that a parallel event would be the best.
    The case is that as they explained to me, everything is executed at once and only the last dictated frame appears. For the second there is the problem of making this image change according to the current actor, but I think that for later.
    It is good to say that the image must be in Picture and have this structure
    imageName (HxV)
    H = number of frames Horizontal
    V = number of Vertical frames.

    Anyway I am looking to use this Yep Plugin to create a BustPlugin or Function, showing real animation bust.

    I hope I have explained myself well

    s a record of the sprites, in battle, I don't know if it helps but at least it shows what should be displayed. when actor X is selected skills. Of course it does not appear where it should. It only weighs kilobytes
  11. Strange that Yanfly's plugin doesn't seem to offer a way to automatically animate a picture! Since you mentioned battle and Parallel events: by default Parallel/Autorun events only run on the map scene, not in battle. So you might need a plugin specifically for this.

    The command codes for Wait and Script are 230 and 355; both commands take 1 parameter each: wait time and script as string, respectively. I found this by searching rpg_objects.js for // Wait and // Script.

    You could use a loop to generate the appropriate commands and insert those into the interpreter, e.g.
    JavaScript:
    var i = this._indent;
    var p = '$gameScreen.picture(1).setSpritesheetFrame(%1);';
    var list = [{ code: 355, indent: i, parameters: [p.format(1)] }];  // set frame 1
    for (var n = 2; n <= 10; n++) {  // loop n = 2 to 10
      list.push({ code: 230, indent: i, parameters: [1] });            // wait 1 frame
      list.push({ code: 355, indent: i, parameters: [p.format(n)] });  // set frame n
    }
    // avoid mutation of original command list!
    var next = this._index + 1;
    var a = this._list.slice(0, next);
    var b = this._list.slice(next);
    this._list = a.concat(list, b); // before -> new -> after
    Note that this approach makes a copy (slice) of the before and after commands, then connects them (concat) with the new commands and reassigns the entire command list. This is because inserting the new commands in directly (splice) is unsafe: it will alter the event commands for the rest of the play session! :kaoback:

    Edit: the above example assumes it's running in the appropriate Game_Interpreter context; if not, you'll need to replace this with a reference to such an object for it to work.

    If you're writing a plugin and you want a delay, you can define a frame counter and update it and the associated effects via an appropriate update method, e.g.
    Code suggestion
    JavaScript:
    (function(alias) {
      Game_Screen.prototype.updatePictures = function() {
        alias.apply(this, arguments);  // default behaviour
        // then your own code
        [1,2,3].forEach(function(pictureId) {  // for picture IDs 1, 2, and 3...
          var pic = $gameScreen.picture(pictureId);  // get picture
          pic._animationCount = pic._animationCount || 0;  // 0 if not already defined
          if (++pic._animationCount >= 20) {  // every 20 game frames...
            pic._animationCount = 0;  // reset counter
            pic.setSpritesheetFrame((pic.spritesheetFrame() + 1).mod(12));  // next picture frame
          }
        }
      };
    })(Game_Screen.prototype.updatePictures);
    This is just an example, there may be bugs (hopefully not) and you'll probably want to edit it for your own purposes anyway~
  12. Yes, it is something strange that Yep has not put the auto animation option, in it, I will try to see if there is any extension for that plugin. it's a good idea, and thanks again.
    Edit-------
    Search without results apparently if we can do this this would be the only extension . So I have to do it.
    Headaches Welcome be !!
  13. sorry the double post was accidental, I try to remove it but it was not possible. There is no option for the user to delete a comment of their own?
  14. @STARFALL , please avoid double posting, as it is against the forum rules. You can use the "Edit" function on your posts to add additional information you've forgotten or respond to multiple people. You can review our forum rules here. Thank you.


    Please just edit your last post to add new information, unless it's been 72 hours.