EDIT: Sorry everyone, it was a simple typo. I need sleep.
I'm trying to write a simple plugin which will contain a bunch of common functions I use all over the place, to save some time.
However, when I try calling any of these functions from a script call in a map, I get an error.
The plugin's pretty short - here:
Then, in-game I'm running this:
The error I'm getting looks like this:
Best to ignore the reference to MoveRouteCore; I don't think that's relevant. It's more the last bit - "EFox is not defined".
I'm pretty new to the idea of writing a plugin; have I missed something very obvious?
I'm trying to write a simple plugin which will contain a bunch of common functions I use all over the place, to save some time.
However, when I try calling any of these functions from a script call in a map, I get an error.
The plugin's pretty short - here:
JavaScript:
//=============================================================================
// FOX_CommonFunctions.js
//=============================================================================
// Copyright (c) 2023 Ethan Fox for Tanuki-sama Studios
// Released under the MIT license
// http://opensource.org/licenses/mit-license.php
//=============================================================================
/*:
* @plugindesc A plugin containing a range of useful functions
* @author Ethan Fox - www.tanukisama.com
* @version 2.0.0 2023/02/14
*
* @help
* Call EFox.FOXCOM.areEventsColliding(EventID 1, EventID 2)
* You can supply a -1 to Event1 for the player
*
* Call EFox.FOXCOM.clampedLerp(min, max, t)
* Perform a simple lerp between 2 values over a 0-1 range
*
* Call EFox.FOXCOM.randomIntGivenInterval(min, max)
* Gives a random int from min to max (includes min and max as possible values)
*
*/
var Imported = Imported || {};
Imported.FOX_CommonFunctions = true;
var EFox = EFox || {}; // Efox's main object
EFox.FOXCOM = EFox.FOXCOM || {}; // Efox's plugin stuff
(function() {
EFox.FOXCOM.areEventsColliding = function(eventID1,eventID2,distance) {
// Checks if eventID1 and eventID2 are < distance apart.
// If < distance, they are touching (TRUE), if > distance they're not touching (FALSE)
if (eventID1 == -1) {
//eventID1 is the player
var x1 = ($gamePlayer.scrolledX() + 0.5)*48;
var y1 = ($gamePlayer.scrolledY() + 0.5)*48;
} else {
//eventID1 is a map event
var x1 = ($gameMap.event(eventID1).scrolledX() + 0.5) * 48;
var y1 = ($gameMap.event(eventID1).scrolledY() + 0.5) * 48;
}
var x2 = ($gameMap.event(eventID2).scrolledX() + 0.5) * 48;
var y2 = ($gameMap.event(eventID2).scrolledY() + 0.5) * 48;
var actualDistance = Math.sqrt( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) );
//console.log("x1,y1: %d,%d || x2,y2: %d,%d || Distance: %d",x1,y1,x2,y2,actualDistance);
if (actualDistance <= distance) {
return true;
} else {
return false;
}
}
EFox.FOXCOM.clampedLerp = function(min,max,t) {
// Simple lerp between min and max by factor t, clamping within that range.
if (t > 1.0) { t = 1.0; };
if (t < 0.0) { t = 0.0; };
return (1 - t) * min + t * max;
}
EFox.FOXCOM.randomIntGivenInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min);
}
})();
Then, in-game I'm running this:
JavaScript:
EFox.FOXCOM.clampedLerp(50,100,0.75);
The error I'm getting looks like this:
Code:
CONTROL VARIABLE SCRIPT ERROR
YEP_MoveRouteCore.js:1072 EFox.FOXCOM.clampedLerp(50,100,0.75);
YEP_MoveRouteCore.js:1073 ReferenceError: EFox is not defined
Best to ignore the reference to MoveRouteCore; I don't think that's relevant. It's more the last bit - "EFox is not defined".
I'm pretty new to the idea of writing a plugin; have I missed something very obvious?