I spent six good hours on trying to spawning one monster on a nearby FREE tile RANDOMLY!

Hi there!
First, you have to replace this "chestId" with the ID of the event. I write "chestId" as an example for you. But this arg must be a valid event id.

I have copied this code to the plugin, but the game told me the function is not defined, let me give you some screenshots, wait
Clipboard01.png


Clipboard02.png


Clipboard03.png



Clipboard04.png


SOS!!
Hi!
It is because of that:
1614344107796.png


Your function is inside another function (IIFE) because of that it is not on the global scope.
You can either add it without the IIFE (red circled)
Or put the function in the game map class for example

Game_Map.prototype.getFreeTileToSpawnEvent = function (px, py, range, eventId){
.....
}
Sou you call it with $gameMap.getFreeTileToSpawnEvent(...args)
1614345295383.png


1614345598831.png


I have tried both way but not work(not defined again), maybe there is some grammar error so the game ignore the whole js file then this function is never defined?

have you tried it for yourself? if so, can you send me your js file here or dropbox, many thanks!
With your help, my problem is now fixed!
thanks!
now this topic can be closed

Original thread: https://forums.rpgmakerweb.com/threads/i-spent-six-good-hours-on-trying-to-spawning-one-monster-on-a-nearby-free-tile-randomly.133781/