Meteor Scripting Functions
Math
int randomInt(int lower, int upper)
Generate a int between lower and upper (both inclusive).
print(randomInt(1, 10));
float randomFloat(float lower, float upper)
Generate a random float between lower and upper (both inclusive).
print(randomFloat(0, 1));
float randomDir()
Generate a random direction/angle.
print(randomDir());
Same as calling randomFloat(0, 360);
int/string randomArray(array inputArray)
Pick a random element from an array.
array<int> numbersArray = {1,1,1,2,3,4};
print(randomArray(numbersArray)); // 1 is most likely result
array<float> floatsArray = {1.0,1.1,1.2,1.3,1.4,1.5};
print(randomArray(floatsArray));
array<bool> boolsArray = {true,true,true,false}; // true is most likely
print(randomArray(boolsArray));
array<string> fruitArray = {"Apple", "Banana", "Orange", "Orange", "Orange"};
print(randomArray(fruitArray)); // orange is most likely result
array<vector2> vector2sArray = {vector2(1,1),vector2(1,2),vector2(1,3)};
print(randomArray(vector2sArray));
Supports int, float, bool, string and vector2 arrays.
float pixelsToMetres(float pixels)
Convert pixels to metres.
print(pixelsToMetres(240)); // 15
16 pixels is 1 metre.
The alternate spelling "pixelsToMeters" can also be used.
A global constant PIXELS_PER_METRE (or PIXELS_PER_METER) is also available e.g. float met = pix / PIXELS_PER_METER;
float metresToPixels(float metres)
Convert metres to pixels.
print(metresToPixels(15)); // 240
16 pixels is 1 metre.
The alternate spelling "metersToPixels" can also be used.
A global constant PIXELS_PER_METRE (or PIXELS_PER_METER) is also available e.g. float pix = met * PIXELS_PER_METER;
float getBearingTo(vector2 fromPos, vector2 destPos)
Get the bearing from fromPos to toPos in the range 0-360.
float bear = getBearingTo(getPos(getPlayer()), vector2(0,0));
print("Bearing to top left of map is: " + bear);
vector2 moveForwardOnBearing(vector2 pos, float bearing, float dist)
Move a position along bearing and return the result.
vector2 newPlayerPos = moveForwardOnBearing(getPos(getPlayer()), getDir(getPlayer()), metresToPixels(10));
setPos(getPlayer(), newPlayerPos);
float getDistance(vector2 pos1, vector2 pos2)
Get the distance between 2 points in pixels.
print("Distance to top left of map is: " + getDistance(getPos(getPlayer()), vector2(0,0)) + " pixels");
float getDistanceMetres(vector2 pos1, vector2 pos2)
Get the distance between 2 points in metres.
print("Distance to top left of map is: " + getDistanceMetres(getPos(getPlayer()), vector2(0,0)) + "M");
The alternate spelling "getDistanceMeters" can also be used.
float clamp(float value, float minValue, float maxValue)
Clamp a number between two values.
print(clamp(-9999, 0, 100)); // 0
print(clamp(9999, 0, 100)); // 100
print(clamp(50, 0, 100)); // 50
Index
Generated on the 15 May 2024 at 09:00:40 (UK Time)