Random wait time script in autonomous movement?

Hi there! I'm trying to make an enemy move randomly around the map in its own little region. However, because I'm using some script calls, I have to use custom autonomous movement rather than just setting it to random.

I'd like the time between its random movements to be somewhat random, but I'm not sure how to do that in a script call. I've tried using:

Code:
this.wait(rand(300));

But this appears to have no effect, the wait time between movements is the same every time. Here's a picture to show specifically what I'm trying to do.

yAjyrZE.png
Here, i got you. I'll show you one way you can do this without scripts at all

Edit: This is a VERY simple version of what your looking for, but it works. I'd suggest a proximity script to make it so other things can happen, and putting these commands in the else branch were it's not close to the player
Randopm movement.png
It's not rand, rand is C++. Javascript is Math.floor(Math.random() * 300).
Moving this over to Learning Javascript.

I think @Poryg's recommendation will get you what you need. rand(300) is how you'd do it in Ruby (XP, VX, Ace). If that doesn't work (I'd be surprised), make sure your parentheses are matched correctly, or try removing this. at the beginning, or the semicolon at the end.
Game_Character (move route context) has no wait method, so if you want a script approach you'll need to adjust the character's _waitCount property manually, e.g.
Code:
this._waitCount = 50 + Math.randomInt(251);
This'll make them wait for 50~300 frames (inclusive). 🙂
Code:
this._waitCount = 50 + Math.randomInt(251);
I'm not sure if it will work for me. But I will just try it out! 🙂

I think the problem is that maybe there is an error in the script, I mean.
Like for example. Try checking the script again and then fix some errors.
I'm not sure if it will work for me. But I will just try it out! 🙂
Did you post in the wrong thread by mistake? It's a very simple script call and I tested it before posting. 😅
Did you post in the wrong thread by mistake? It's a very simple script call and I tested it before posting. 😅
Oh come on ;< I'm just trying it out 😊
Game_Character (move route context) has no wait method, so if you want a script approach you'll need to adjust the character's _waitCount property manually, e.g.
Code:
this._waitCount = 50 + Math.randomInt(251);
This'll make them wait for 50~300 frames (inclusive). 🙂

Where do I put this script in the event?
Where do I put this script in the event?
In a Script command inside the move route, like in your initial screenshot. E.g. replace "this.wait(rand(300))" with "this._waitCount = 50 + Math.randomInt(251)" (obviously you can change the numbers to suit your situation). 🙂
That worked perfectly! Now I just gotta fiddle with the numbers til the movements look natural.

Thanks so much for your help!
Great! Happy RPG Making! 😂
In a Script command inside the move route, like in your initial screenshot. E.g. replace "this.wait(rand(300))" with "this._waitCount = 50 + Math.randomInt(251)" (obviously you can change the numbers to suit your situation). 🙂
Thanks, Guy! The random movement of several events at the same time is working perfectly here.
aleatorio.png
Great! Try to avoid bumping old threads like this, though.

@DerniBorges, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Happy RPG Making~ 👋

Original thread: https://forums.rpgmakerweb.com/threads/random-wait-time-script-in-autonomous-movement.113931/