Meteor 2 Scripting Functions
Math
int randomInt(int lower, int upper, bool useSeed=false, uint seed=0)
Generate a int between lower and upper (both inclusive).
print(randomInt(1, 10));
float randomFloat(float lower, float upper, bool useSeed=false, uint seed=0)
Generate a random float between lower and upper (both inclusive).
print(randomFloat(0, 1));
float randomDir(bool useSeed=false, uint seed=0)
Generate a random direction/angle.
print(randomDir());
Same as calling randomFloat(0, 360);
float randomSeed()
Generate a random seed value.
print(randomSeed());
int/string randomArray(array inputArray, bool useSeed=false, uint seed=0)
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 getPerlinSample(vector2 pos, uint seed)
Generate a value based on a 2D vector and a seed using perlin noise.
float value = getPerlinSample(vector2(0.5,0.5), getWorldSeed());
print(value);
vector2 getRotatedSize(vector2 size)
Get the bounds size of a rectangle rotated in degrees.
print(getRotatedSize(vector2(5,10), 90)); // 10, 5
vector2 rotatePoint(vector2 point, angle float, vector2 centrePivot)
Rotate a point around a pivot.
vector2 result = rotatePoint(vector2(0, 50), 270, vector2(50, 50));
print(result); // 50, 100
float pixelsToMetres(float pixels)
Convert pixels to metres.
print(pixelsToMetres(256)); // 16
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(16)); // 256
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(PLAYER_OBJECT), 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(PLAYER_OBJECT), getDir(PLAYER_OBJECT), metresToPixels(10));
setPos(PLAYER_OBJECT, newPlayerPos);
vector2 rotateTowards(float angle, float targetAngle, float step)
Rotate angle towards target angle.
print(rotateTowards(20, 90, 10)); // 30
All values are in degrees (0 to 360).
float getDistance(vector2 pos1, vector2 pos2)
Get the distance between 2 points in pixels.
print("Distance to top left of map is: " + getDistance(getPos(PLAYER_OBJECT), 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(PLAYER_OBJECT), 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
float min(float a, float b)
Return the smallest of two values.
print(min(1, 10)); // 1
float max(float a, float b)
Return the largest of two values.
print(max(1, 10)); // 10
float lerp(float a, float b, float t)
Linear interpolate a value between a and b by the normalised fraction t.
print(lerp(1.0, 2.0, 0.5)); // 1.5
float fmodf(float a, float b)
Return the fraction remainder of x/y.
Same as fmodf() in C.
uint createStringHash(string stringValue)
Generate a hash value from a string (string is case sensitive).
unsigned hash = createStringHash("Hello World!");
print(hash);
uint createStringHashLowerCase(string stringValue)
Generate a lower case hash value from a string (string is automatically converted to lower case).
unsigned hash1 = createStringHashLowerCase("Hello World!");
print(hash1);
unsigned hash2 = createStringHashLowerCase("hELLO wORLD!");
print(hash2);
Index