Scripting Basics
Mokoi Games are written in the Pawn Language (Features).
- Syntax
- Functions?
- Variables
- Error Codes
- Operators and Expressions
- Statements?
- Subroutines
- Entities
- Managed Entities?
Internal Types
List of Functions
Please note that some of these functions are in development versions and may not be available in current release.
Main Functions
These are define in the mokoi.inc header, so to use these functions, #include <mokoi> must be include at the top of the script.
Engine Functions
GameState(newstate)
- Get/Set Global State.
GameFrame()
- Return the length of last frame in milliseconds.
Fixed:GameFrame2()
- Return the length of last frame in milliseconds as a fixed point number.
KeyboardWatch?( able )
- Send Keyboard input to KeyboardInput? function in the current entity.
Logging Functions
DebugText( text[], ... )
- Prints formatted text to the debug console.
GameLog?( text[], ... )
- Prints formatted text to a text file.
Save Functions
GameSave(slot, detail[64])
- Save Current Game.
GameLoad(slot)
- Load Game from Slot.
GameSetDetails(slot, array[64])
- Set Save Game Details.
GameGetDetails(slot, array[64])
- Get Save Game Details.
GameDetails(gameid, slot, array[64])
- Get another game save details.
Input Functions
InputButton(input, player)
- Returns Button value for Player
InputAxis(axis, player)
- Returns Axis value for Player
InputPointer(axis, player)
- Returns Pointer value for Player
InputButtonSet(input, value, player)
- Set Button value for the Player
InputAxisSet(axis, value, player)
- Set Axis value for the Player
InputPointerSet(axis, value, player)
- Set Pointer value for the Player
Misc Functions
MiscGetWidth(id[])
- Get Width of Map, Screen or Sprite
MiscGetHeight(id[])
- Get Height of Map, Screen or Sprite
Mask Functions
MaskRefresh()
- Updates Mask from current Map Objects
MaskGetValue(x, y, layer)
- Gets Mask value
MaskFill(x, y, w, h, value)
- Fills area of mask
Map Functions
Maps can be defined 3 ways, Map Name, ID and grid location.
MapGetOffset(axis)
- Get the Offset from the Top-left of map
MapSetOffset(Fixed:x, Fixed:y)
- Set the Offset from the Top-left of map
MapGridValid(x, y)
- Check to see if map exist on grid location.
MapGetGrid(&x, &y)
- Gets current Grid location.
MapGetFromGrid(x, y)
- Get Map ID from Grid position
MapSetFromGrid(x, y)
- Set Map from Grid position
MapGetID(map[])
- Get Current Map ID
MapSet(map[])
- Set Map by ID
Language Functions
LanguageString(line, returnstring[])
- Get String from Language File
LanguageSet(lang[])
- Set Language
Dialog Functions
DialogShow(line)
- Shows Dialog box
DialogGetString(line, returnstring[])
- Get String from Dialog File
DialogPlayAudio(line)
-Play Dialog
Audio Functions
AudioVolume(_AUDIO:device, level)
- Sets Audio device volume.
AudioPlaySound(file[], x, y)
- Play Sound Effect.
AudioPlayMusic(file[], loop, fadeLength)
- Play Music.
Config Functions
ConfigGetStringconfig[], value[])
- Get Engine config as a string.
ConfigGetNumber(config[])
- Get Engine config as a number.
ConfigSetStringconfig[], value[])
- Update Engine config.
File Functions
FileGetList(strings[][], directory[])
- List File in a directory.
Graphics Functions
These are define in the graphics.inc header, so to use these functions, #include <graphics> must be include at the top of the script.
Available Graphics Types
Colour arguments are a RGBA hex value such as 0xFF33BBAA, FF is red value, 33 is green, BB is blue and AA would be the alpha.
Display Objects
These function add and modify display object. Display Object are added to the entity parent map, and in case of a global entity, display object are added to the global scope.
object:ObjectCreate(string[], [Scripting;Graphics Types|_GRAPHICSTYPES]:type, x, y, z, w, h, colour)
- Creates a new Display Objects. 'string' can be a sprite name or some text.
ObjectReplace(object:id, string[], [Scripting;Graphics Types|_GRAPHICSTYPES]:type);
- Convert Display Objects to new type.
ObjectPosition(object:id, x, y, z, w, h, pos = POSITION_MAP)
- Give the Display Objects a new position and dimension.
ObjectEffect(object:id, colour, rotate, scale_w, scale_h , flip, [Scripting;Display Styles|_DISPLAYSTYLES]:style, colour2);
- Change Display Objects effects
ObjectFlag(object:id, key, value)
-
ObjectDelete(object:id)
- Delete a Display Objects.
Display/Camera Options
CameraSetScroll(bool:scroll)
- Enable Smooth scrolling.
LayerSetRotation(layer, roll, pitch, yaw);
- Change the rotation of the layer.
LayerSetOffset(layer, Fixed:x, Fixed:y);
- Change the Offset of the layer.
LayerColour(layer, colour);
- Change the base color of the layer.
Misc Functions
GraphicsType()
- Returns the type of graphic display. Can be used to enable some effects.
GraphicsDraw(string[], GraphicType?:type, x, y, z, w, h, colour)
- Draw a Display Objects for the current frame.
Animation
AnimationGetLength(string[])
- Returns length of animation in milliseconds.
'''[wiki:Scripting;Pawn;Tagged#Fixed Fixed:AnimationGetLength?2](string[])
- Returns length of animation in milliseconds as a fixed number value.
Future Function AnimationCreate(string[], length)
- Creates new animation.
Future Function AnimationAddFrame(string[], sprite[]);
- Adds a frame to an animation.
Text
TextSprites?(able, sheet[])
- Ables the use of Sprites for text instead of the internal bitmap font.
Polygon
Future Function PolygonCreate(string[])
- Create a polygon.
Future Function PolygonAddPoint(string[], x, y)
- Add a point to existing polygon.
Entity Functions
These are define in the entity.inc header, so to use these functions, #include <entities> must be include at the top of the script.
Collision Functions
CollisionFromObject?( obj, type = 0 );
- Set Collision rectangles from the sprite or animation data.
CollisionCheck(id1[], id2[], rect1, rect2)
- Check to see if Entity is colliding with another entity.
CollisionSet(id[], rect, type, x, y, w, h)
- Set a collision for the entity.
CollisionCalculate(id[], rect, type)
- Generate a list of entities it's colliding with.
CollisionGetCurrent(id[], current[], &angle, &dist, &rect, &type)
- Retrieves current collision from generated list.
Position Functions
EntitySetPosition?(Fixed:x, Fixed:y, Fixed:z,id[])
- Set Entities position on current map.
EntityGetPosition?(&Fixed:x, &Fixed:y, &Fixed:z, id[])
- Get Entity position on current map.
Entity Management Functions
EntitiesList?(map = CURRENT_MAP)
- Generate a list of entities for required map.
EntitiesNext?(string[], map_id = CURRENT_MAP)
- Retrieves current entity name from generated list.
EntityFunction?(function);
- Calls a local function by id. funcidx? can get id from name;
EntityPublicFunction?(id[], function[], args[]="", ...)
- Calls a function from another entity.
EntityCreate?(parententity[], id[], Fixed:x, Fixed:y, Fixed:z, map_id = CURRENT_MAP)
- Creates a new entity.
EntityDelete?(id[]);
- Deletes a entity.
EntityGetSetting?(key[], string[], id[]);
- Get stored setting for entity.
EntityGetNumber?(key[], , id[]);
- Returns stored setting for entity.
String Functions
These are define in the string.inc header, so to use these functions, #include <string> must be include at the top of the script.
About Strings?
strlen?(string[]);
- Return length for string.
strpack?(dest[], source[]);
- Pack the strings
strunpack?(dest[], source[]);
- Unpack the strings
strcopy?(dest[], source[]);
- Copy String.
strcat?(dest[], source[]);
- Append string to another string.
strmid?(dest[], source[], start, end);
- Copy a substring.
bool:strins?(string[], substr[], index);
- Insert Text into a string
bool:strdel?(string[], start, end);
- Remove Text from a string
strcmp?(string1[], string2[], bool:ignorecase);
- Compares Two Strings.
strfind?(string[], sub[], bool:ignorecase);
- Search for a sub-string in a string
strval?(const string[], index=0);
- Converts String to Number.
valstr?(dest[], value, pack);
- Converts Number to String.
bool:ispacked?(string[]);
- Checks to see if the string is packed
strformat?(dest[], _, packed = 0, format[], ...);
- Convert values to a string;
Core Functions
These are define in the core.inc header, so to use these functions, #include <core> must be include at the top of the script.
heapspace?heapspace();
- Return free heap space.
funcidx?funcidx(const name[]);
- Returns the id for the function, which can used with EntityFunction?
Argument Function
When a function has the argument '...' it allows multiple arguments to be giving to the function.
tolower?numargs()
- Return the number of arguments giving for the function.
tolower?getarg(arg, index=0);
- return the value of argument, if the argument is an array use index arg to [br]]
tolower?setarg(arg, index=0, value)
- Set the value of the arg.
Character Function
tolower?(c);
- Changes ASCII letter to the lower case
toupper?toupper(c);
- Changes ASCII letter to the capital case
swapchars?swapchars(c);
- Switches the ASCII letter case.
Misc Math Function
random?random(max);
- Get a random number.
min?min(value1, value2);
- returns the smaller value
max?max(value1, value2);
- returns the higher value
clamp?clamp(value, min, max);
- Clamps a value between min and max
Time Functions
These are define in the time.inc header, so to use these functions, #include <time> must be include at the top of the script.
Time?(&hour=0, &minute=0, &second=0);
- Get Current time
Date?Date(&year=0, &month=0, &day=0);
- Get Current Date
TimestampCurrent?TimestampCurrent?();
- Get the seconds from 1970. Also known as Unix Time
TimestampDetails?(seconds1970, &year=0, &month=0, &day=0, &hour=0, &minute=0, &second=0);
- Converts Unix Time to a time and date.
Network Functions
These are define in the network.inc header, so to use these functions, #include <network> must be include at the top of the script.
Future Function EntityNetworkSync?(id[], bool:able);[[br]]
- Ables networking syncing for entity.
Future Function EntityActive?();
- Checks to see if networked entity is active.
Future Function NetworkConnect?NetworkConnect?( name[], pass[], email[] )
- Connect to Server.
Future Function NetworkDisconnect?NetworkDisconnect?();
- Disconnect from Server.
Future Function NetworkMessage?NetworkMessage?( reliable, serveronly, message[], length )
- Sends a message to entity with the same unique id.
Future Function NetworkPlayerName?NetworkPlayerName?(player, name[]);
- Gets network player name .
OnlineData?OnlineData?(callback[32], url[128], post[] = "")
- Downloads URL to the callback function. If data is supported media, it will be loaded, and details pass to callback function.
Future Function OnlineUpdate?OnlineUpdate?();
- Downloads latest game patches.
Future Function OnlineSubmitScore?OnlineSubmitScore?(data[4]);
- Sumbit score to online scoreboard
Future Function OnlineSave?OnlineSave?( data[64] );
- Online save.
== Player Functions
PlayerGetName?( player, str[] )
- Get the name for player.
PlayerSetName?( player, str[] )
- Get the name for player.
Future Function PlayerSetEntity?PlayerSetEntity?( player, entity[] )
- Set Entity for player. Useful for setting computer AI
Future Function PlayerAdd?PlayerAdd?()
- Adds new player.
Future Function PlayerRemove?( player )
- Removes player.
Future Function PlayerCount?()
- Get current number of players.
Future Function PlayerMaxCount?()
- Get max number of players.
Rational Number Support
Fixed point numbers are the supported rational number system and allows for 3 decimal places. Floating point numbers are also support.
Fixed Functions
These are define in the fixed.inc header, so to use these functions, #include <fixed> must be include at the top of the script.
Fixed:fixed?(value)
- Converts whole number to a Fixed point one.
Fixed:strfixed?( string[] )
- Converts a string to a Fixed point number.
fround?( Fixed:value, round_method:method=round_normal)[[br]]
- Rounds Fixed point number to a whole number
Fixed:fpower?(Fixed:value, exponent)
- Raise a fixed point number to a power.
Fixed:fsqroot?(Fixed:value)
- Return the square root of a value.
Fixed:fabs?(Fixed:value)
- Returns the absolute value.
Fixed:flog?(Fixed:value, Fixed:base=10.0)
- Returns the logarithm of a value.
Fixed:fsin?(Fixed:value, anglemode:mode=radian)[[br]]
- Returns the sine of the angle.
Fixed:fcos?(Fixed:value, anglemode:mode=radian)[[br]]
- Returns the cosine of the angle.
Fixed:ftan?(Fixed:value, anglemode:mode=radian)[[br]]
- Returns the tangent of the angle.
Fixed:fatan2?(Fixed:y, Fixed:x, anglemode:mode=radian )
- Returns the arc tangent of x/y.