RPGToolkit 3 — Online Help [ home, back, forward ]

RPGCode — Function Reference

Contents

[ Collapse All | Expand All ]

Sprites

Game

Multimedia and Drawing

Program Structure

Data

System


NAME: Blank line
FORMAT: @

This places a blank line in the Message window. Since 'real' blank lines are ignored by the computer, you should use this when spacing two lines of text in the message window.
mwin("This is one line.")
@
mwin("This is another line.")
[ top ]

NAME: Comment
FORMAT: //

Two slashes tells the computer to ignore the rest of the line. This is used for adding comments to your code. Comments are used as ways of explaining what some parts of a program do. Comments can appear on the same line as a command as long as the comment is to the right side of the command.
// This is a comment. It gets ignored
// by the computer.

mwin("Comments!")
a! = 10 // This is another comment.
[ top ]

NAME: Force Local Variables
FORMAT: #autolocal

This is the preprocessor equivalent of the Autolocal() command. It forces all implicitly declared variables to be of local scope. Global variables can still be declared with the global() command.
#autolocal

x! = 5 // Local variable
[ top ]

NAME: Declare global
FORMAT: #global handle value

This is a preprocessor command that creates a global variable, or instance of a class. If it's an object, value should be the constructor of the class.
- handle is the variable or object name.
- value is the value of the variable or object.
#global var! 7
#global var$ "Hello, world!"

show(var!)
show(var$)
[ top ]

NAME: Include file
FORMAT: #include filename

This is a preprocessor command that includes a file. If you include a file, you will be able to use the methods from inside that file. This is extremely useful for making method libraries and importing them wherever you need them.
- filename is the name of the file.
#include "system.prg"

mwin("Hello!")
pause()
[ top ]

NAME: Strict
FORMAT: #strict

This is a preprocessor command that forces the "proper" use of things like the assignment and comparison operators.
#strict

a! = 0
if (a! = 0)
{
	// Instead of comparing a! to 0, the above
	// statement will assign 0 to a!. Without
	// the use of #strict, it will just compare
	// the values.

	mwin("This block of code is skipped!")
	wait()
	mwincls()
}
[ top ]

NAME: Add Player
FORMAT: addPlayer(player_filename$)

This command adds a player to the current party, or team. There is a maximum of 5 players allowed on one team at any time. When the player is added to the team, their stats (HP/SMP/etc.) are set to the initial values specified in the character editor.
- player_filename$ is the filename of the player to add to the team.

addPlayer("Tano.tem")
mwin("Tano joined your team!")
wait()
mwinCls()
[ top ]

NAME: Artificial Intelligence
FORMAT: AI(level!)

This command causes an enemy to use it's artificial intelligence routine in battle. The AI command can only be used from inside of an enemy AI program (see Enemy Editor - Tactics).
- level! is a numerical value between 0 and 3. 0 being the lowest, 3 being the highest.
// Enemy AI program
move!++
switch (move!)
{
	case (1)
	{
		AI(0)
	}
	case (2)
	{
		AI(3)
	}
	case (3)
	{
		mwin("Aren't you getting tired of me?")
		move! = 0
	}
}
[ top ]

NAME: Run Animation
FORMAT: hAnm! = animation(file$, x!, y![, loop!])

Plays an animation file created in the animation editor.
- file$ is the filename of the animation.
- x!,y! are the x and y coordinates to place the animation.
- loop! is an optional parameter only for threads. It causes the animation to loop until the thread is killed, or endAnimation() is used.
- hAnm! is the returned handle of the animation. Use this when ending an animation.
hAnm! = animation("explosion.anm", 10, 10)
[ top ]

NAME: Apply Status Effect
FORMAT: ApplyStatus(handle$, file$)

This command applies a status effect created in the status effect editor to a player or enemy. This command accepts the 'target' and 'source' handles for applying the effect to the currently selected player or enemy.
- handle$ is the handle of the player or enemy. 'target' and 'source' are valid handles.
- file$ is the filename of the status effect to apply.
// Apply "fast" on the source, and
// "slow" on the target.
applyStatus("source", "fast.ste")
applyStatus("target", "slow.ste")
[ top ]

NAME: Application Path
FORMAT: dest$ = AppPath()

This command retrieves the file path of the RPGToolkit3 and returns it to dest$.
- dest$ is the returned path.
// Show the application path...
show(appPath())
[ top ]

NAME: ASCII
FORMAT: dest! = Asc(char$)

Asc() converts characters to and from ASCII characters.
- char$ is the character(s) to replace with an ASCII character(s).
- dest! is the returned ASCII.
asc! = asc(char$)
[ top ]

NAME: Attack All
FORMAT: AttackAll(fp!)

This command will attack all of the players or enemies in battle. When used with a special move, this will damage the group of enemies or players depending on which was targeted with the special move.
- fp! is the amount of FP to put into the attack.
// Attack a group with an FP of 100...
attackAll(100)
[ top ]

NAME: Auto Local
FORMAT: Autolocal()

This command automatically sets all implicitly declared variables to local scope. This means that all variables created after the use of this command will be local, unless they are created with the global() command.
autolocal()
[ top ]

NAME: Bitmap
FORMAT: bitmap(file$[, hCnv!])

This displays a bitmap image on the screen. Supported file formats include .bmp, .gif, .jpg, .png, .mng, .ico, and many more. All images shown with the bitmap command must be placed in the bitmap folder to work correctly.
- file$ is the filename of the image.
- hCnv! is an optional parameter for drawing the image to a canvas.
// Put the title image on the screen...
bitmap("title.bmp")
[ top ]

NAME: Bold
FORMAT: Bold(on_off$)

This command turns the bold attribute on all text on or off.
- on_off$ is a literal value that can either be "on" or "off".
bold("off")
mwin("Boring regular text...")
wait()
bold("on")
mwin("Bold text!")
[ top ]

NAME: Branch to Label
FORMAT: Branch(:label_name)

This command is used to branch (or skip) to another part of the program. If you use this command, you must create a label. Labels are case sensitive, which means the label in the Branch command must be identical to the label in the program. Labels must not be indented. They must also begin with a colon (':'). Using branch() is considered very bad programming practice and was kept for backwards compatability. You can achieve the same effect that branching gives you by using a while loop.
- :label_name is the name of the label to branch to. It must be identical to the label in the program.
mwin("Line 1")
mwin("Line 2")
branch(:next_line)
mwin("Line 3")
:next_line
mwin("Line 4")

// Because we branched to :next_line,
// the Mwin command that said "Line 3"
// was skipped.
[ top ]

NAME: Call Player Swap
FORMAT: CallPlayerSwap()

This command opens the player swap menu. It allows you to add and remove players to your party. The players available for adding to your party are the ones that were removed with the removePlayer() command. They won't show up if they were removed with destroyPlayer().
// Time to swap some players!
CallPlayerSwap()
[ top ]

NAME: Call Shop
FORMAT: CallShop(item1$[, item2$, etc.])

This command opens the shop menu. Players can buy and sell items here. The prices of items are defined in the item editor.
- itemX$ is the filename of the items to sell. Shops can hold as many items as you wish.
callShop("sword", "book", "pizza")
// Opens a shop selling three items.
[ top ]

NAME: Cast to integer
FORMAT: dest! = CastInt(source!)

This command takes a floating point number and disguards the decimal, casting it to a whole number (an integer).
- source! is the source number to cast to int.
- dest! is the returned value.
int! = castInt(10.482) // Result: puts 10 in int!
char$ = castLit(int!)  // Result: puts "10" in char$
num! = castNum(char$)  // Result: puts 10 in num!
[ top ]

NAME: Cast numerical values to literal
FORMAT: dest$ = CastLit(source!)

This command converts a numeric value to a literal value.
- source! is the source number to cast to literal.
- dest$ is the returned value.
int! = castInt(10.482) // Result: puts 10 in int!
char$ = castLit(int!)  // Result: puts "10" in char$
num! = castNum(char$)  // Result: puts 10 in num!
[ top ]

NAME: Cast literal values to numerical
FORMAT: dest! = CastNum(source$)

This command converts a literal value to a numerical value.
- source$ is the source literal to cast to numeric.
- dest! is the returned value.
int! = castInt(10.482) // Result: puts 10 in int!
char$ = castLit(int!)  // Result: puts "10" in char$
num! = castNum(char$)  // Result: puts 10 in num!
[ top ]

NAME: Change Program
FORMAT: Change(file$)

This command changes the program filename of the currently running program. The program will continue to it's end, but when the player steps on the tile where the program is again, it will run the new program that was set with Change(). If the player leaves the board then returns, the tile will run the original program that was set there.
- file$ is the filename of the new program to run when the player steps on the tile again.
// An example of using the Change command...
mwin("I'm gonna change the program!")
wait()
change("another.prg")
mwin("Alright, it's changed. But we have to wait")
mwin("for this program to end!")
[ top ]

NAME: Character At
FORMAT: dest$ = CharAt(string$, pos!)

This command allows you to splice apart a string by getting one character at a time. A 'string' is a term that means 'string of characters', or 'text'.
- string$ is the string of characters to get a character from.
- pos! is the character position in the string.
- dest$ is the returned character.
// Get a string, reverse it, and return it to string$

// Call the reverse() method
string$ = reverse("hello")

// Create the 'reverse' method...
method reverse(string$)
{
	for (n! = length(string$); n! > 0; n!--)
	{
		dest$ += charAt(string$, n!)
	}
	returnMethod(dest$)
	kill(n!, dest$)
}
[ top ]

NAME: Check if a Button was pressed
FORMAT: buttonNum! = CheckButton(x!, y!)

This command checks if a button set with the SetButton command was pressed.
- x!,y! are the x and y coordinates of the last mouse click on the screen.
- buttonNum! is the returned value. If no buttons were pressed, buttonNum! is set to requal -1. Otherwise, it is set to the number of that button.
// Set the button...
setButton("button1.jpg", 0, 10, 10, 100, 100)

// Loop through while done! is equal
// to it's inital value...
done! = false
while (!done!)
{
	mouseClick(mx!, my!)
	dest! = CheckButton(mx!, my!)

	// Check if a button was pressed
	if (dest! == 0)
	{
		mwin("You pressed a button!")
		wait()
		mwinCls()
		done! = true // Break out of the loop
	}
}
clearButtons()
[ top ]

NAME: Character
FORMAT: char$ = Chr(char!)

This command returns a character to char$ from an ASCII character(s).
- char! is the key number to detect.
spc$ = chr(8) // Detects the backspace key.
tab$ = chr(9) // Detects the tab key.
[ top ]

NAME: Create a Class
FORMAT: class ClassName { code }

This command creates a new class. Classes are used for structuring and organizing your code. They can contain data such as variables and methods that you can call at any time, by creating an object for the class (also called 'instancing' the class). You can define methods and variables in a class as private, so you can have data that can't be used or changed unless you access the data from inside a method, or the public command, where you can define data/methods that can be changed/used freely. Data and methods are accessed through a class by using the accessor operator (->).
- ClassName is the name of the class.
- code is the public/private data to go into the class.
// Example of a class.

// Define the 'Cat' class...
class Cat
{
public:
	// Public data. This can be
	// changed or used just by
	// accessing it.

	method setName(name$) { m_name$ = name$ }
	method meow()
	{
		mwin("Meow!")
		wait()
		mwincls()
	}

private:
	// Private data. This cannot be
	// changed directly. You need
	// to access this through a
	// method.

	m_name$ // the name of the cat
}

// Create an object for the class ('instance' the class)...
kitten = new(Cat)

// Make the kitten meow...
kitten->Meow()

// Kill the data...
kitten->Release()
[ top ]

NAME: Clear
FORMAT: Clear([hCnv!])

The Clear command clears the screen entirely, leaving it black. When the program ends, the screen will be restored unless the program was ended with the Done command. Clear is useful for setting up menus or story sequences throughout the game.
- hCnv! is an optional parameter that allows you to clear the contents of a canvas.
// Clear the screen...
clear()

// Now, show a board
viewBrd("another.brd")
[ top ]

NAME: Clear Keyboard Buffer
FORMAT: clearBuffer()

This command clears the keyboard buffer. Sometimes the keyboard buffer gets full and continues 'typing' even after the player has finished pressing any buttons. This command clears the buffer to prevent this from happening.
// Clear the keyboard buffer...
clearBuffer()
mwin("Hello!")
wait()
[ top ]

NAME: Clear Buttons
FORMAT: clearButtons()

This command clears all the buttons from memory that were set with the SetButton command. It's always a good idea to clear buttons after you're done with them, as having too many in memory slows down your game.
// Set the button...
setButton("button1.jpg", 0, 10, 10, 100, 100)

// Loop through while done! is equal
// to it's inital value...
done! = false
while (!done!)
{
	mouseClick(mx!, my!)
	dest! = CheckButton(mx!, my!)

	// Check if a button was pressed
	if (dest! == 0)
	{
		mwin("You pressed a button!")
		wait()
		mwinCls()
		done! = true // Break out of the loop
	}
}
clearButtons()
[ top ]

NAME: Close a file
FORMAT: closeFile(file$)

Closes an open file opened in either append, input, output, or binary mode.
- file$ is the file to close.
openFileInput("start.brd","Boards") // Opens a file in 'input mode'
closeFile("start.brd") // Close the file
[ top ]

NAME: Change RGB Color
FORMAT: colorRGB(red!, green!, blue!)

This command changes the color of the text that is displayed in the message window, the text displayed with the Text command, and the fade color of the Fade command.
- red!,green!,blue! are numerical values from 0 to 255 which specify the concentration of red, green, and blue pigment in the color.
colorRGB(0, 0, 0) // Set the color to black
mwin("Black text!")
colorRGB(255, 255, 255) // Set the color to white
mwin("White text!")
colorRGB(255, 0, 0) // Set the color to red
mwin("Red text!")
[ top ]

NAME: Cosine
FORMAT: dest! = Cos(angle!)

Calculates the cosine of an angle and returns the value to dest!.
- angle! is the angle (in degrees) to calculate.
- dest! is the returned value.
c! = cos(90)
s! = sin(90)
t! = tan(90)
[ top ]

NAME: Create Canvas
FORMAT: hCnv! = createCanvas(sizex!, sizey!)

Creates a canvas of sizex! and sizey! (in pixels), and returns the handle so you can refer to it later.
- sizex!, sizey! are the width (x) and height (y) of the canvas.
- hCnv! is the handle of the canvas.
cnv! = createCanvas(64, 64)    // Create a new canvas
bitmap("title.bmp", cnvTitle!) // Put an image in the canvas.
drawCanvas(cnv!, 0, 100)       // Draw the canvas on screen.
killCanvas(cnv!)               // Now, kill the canvas once I'm done with it.
[ top ]

NAME:Create Cursor Map
FORMAT: hMap! = createCursorMap()

This command creates a new cursor map, and returns it's handle. A Cursor Map is a mini-menu that the user can create. It allows the user to specify a spot on the screen where a pointer image will appear, letting them scroll through options with the keyboard.
- hMap! is the handle of the cursor map.
pixeltext(300, 180, "New Game")
pixeltext(300, 210, "Load Game")
pixeltext(300, 230, "Quit")

done! = false
while (!done!)
{
	// Create a cursor map with the id cMap!
	// Set where the cursor can go to...
	cMap! = createCursorMap()
	cursorMapAdd(295, 180, cMap!)
	cursorMapAdd(295, 210, cMap!)
	cursorMapAdd(295, 230, cMap!)
	res! = cursorMaprun(cMap!)
	killCursorMap(cMap!)
}

switch (res!)
{
	case (0)
	{
		// New game
	}
	case (1)
	{
		// Load game
	}
	case (2)
	{
		// Quit
	}
}
[ top ]

NAME: Create Item
FORMAT: createItem(filename$, num!)

This command loads an item into memory. This is a very useful command for creating story sequences with players and NPC's, as the can move the items that you created around the board and make them interact with things.
- filename$ is the filename of the item.
- num! is the returned item slot. When an item is created in memory, it is given a slot. That value is returned to num!, so you can refer to it with other item related commands.
createItem("soldier.itm", pos!) // Load the item into a slot
putItem(pos!, 3, 2, 1)          // Put the item on the board
pushItem(pos!, "E,E,E")         // Push the item east three times
mwin("Hi! Bye!")
wait()
eraseItem(pos!)   // Erase the item from the board
destroyItem(pos!) // Remove the item from memory
[ top ]

NAME: Cursor Map Add
FORMAT: cursorMapAdd(x!, y!, hMap!)

Adds a new cursor map position. Use this to specify where the pointer image can go on the screen. When the user presses an arrow key on the keyboard, the cursor will 'jump' to the next/previous map (if one exists).
- x!, y! are the x and y coordinates (in pixels) to place the cursor.
- hMap! is the handle of the cursor map.
pixeltext(300, 180, "New Game")
pixeltext(300, 210, "Load Game")
pixeltext(300, 230, "Quit")

done! = false
while (!done!)
{
	// Create a cursor map with the id cMap!
	// Set where the cursor can go to...
	cMap! = createCursorMap()
	cursorMapAdd(295, 180, cMap!)
	cursorMapAdd(295, 210, cMap!)
	cursorMapAdd(295, 230, cMap!)
	res! = cursorMaprun(cMap!)
	killCursorMap(cMap!)
}

switch (res!)
{
	case (0)
	{
		// New game
	}
	case (1)
	{
		// Load game
	}
	case (2)
	{
		// Quit
	}
}
[ top ]

NAME: Change Cursor Map Hand
FORMAT: cursorMapHand(file$[, stretchYN!])

Changes the hand image used on the menu, cursor maps, etc. to the specified file. Optionally, you can stretch it to 32x32 pixels. To change the hand to the original image, type "Default" instead of a filename.
- file$ is the filename of the image to use.
- stretchYN! is an optional parameter used to stretch the image (1 - yes, 0 - no).
cursorMapHand("hand.bmp") // Set a new cursormap hand
[ top ]

NAME: Cursor Map Run
FORMAT: dest! = cursorMaprun(hMap!)

This command runs the currently selected cursor map position, and returns the index of the selected cursor map position. The returned value starts at 0 (if the first option was selected), and goes up from there.
- hMap! is the handle of the cursor map.
- dest! is the selected cursor map.
pixeltext(300, 180, "New Game")
pixeltext(300, 210, "Load Game")
pixeltext(300, 230, "Quit")

done! = false
while (!done!)
{
	// Create a cursor map with the id cMap!
	// Set where the cursor can go to...
	cMap! = createCursorMap()
	cursorMapAdd(295, 180, cMap!)
	cursorMapAdd(295, 210, cMap!)
	cursorMapAdd(295, 230, cMap!)
	res! = cursorMaprun(cMap!)
	killCursorMap(cMap!)
}

switch (res!)
{
	case (0)
	{
		// New game
	}
	case (1)
	{
		// Load game
	}
	case (2)
	{
		// Quit
	}
}
[ top ]

NAME: Turn Debugging on/off
FORMAT: debug(on_off$)

This command allows you to enable or disable debugging in your programs. If debugging is enabled and you run into an error in a program, the RPGCode debug window will pop up with an error. You can stop this by turning it off.
- on_off$ is a literal value which can be "on" or "off".
debug("on") // Turn debugging on
sadfd() // This will cause an error

debug("off")

// This is another error, however, it
// will not bring up the debug window.
another error()
[ top ]

NAME: Debugger Message
FORMAT: debugger(text$)

Calls the debug window with a message inside of it. A very useful command for error handling. To use the debug window, debugging must be enabled.
- text$ is the message to be placed inside of the debug window.

debugger("There was an error!")
[ top ]

NAME: Delay
FORMAT: delay(seconds!)

This command causes the computer to pause for a specified number of seconds.
- seconds! is the number of seconds to delay the program for.
mwin("Delaying...")
delay(4)
mwin("Delayed for 4 seconds!")
[ top ]

NAME: Destroy Item
FORMAT: destroyItem(num!)

This command removes an item from memory, freeing up space so another item can be loaded to it's slot.
- num! is the item slot number to destroy.
createItem("soldier.itm", pos!) // Load the item into a slot
putItem(pos!, 3, 2, 1) // Put the item on the board
pushItem(pos!, "E,E,E") // Push the item east three times
mwin("Hi! Bye!")
wait()
eraseItem(pos!) // Erase the item from the board
destroyItem(pos!) // Remove the item from memory
[ top ]

NAME: Destroy Player
FORMAT: destroyPlayer(handle$)

This command removes a player from the party. Unlike removePlayer(), however, it destroys the players stats so you won't be able to bring back the character with restorePlayer().
- handle$ is the handle, or name, of the player.
addPlayer("Frap.tem")
destroyPlayer("Frap")
[ top ]

NAME: Directory of saved games
FORMAT: dest$ = dirSav()

Opens a window showing a list of all the saved games (with the *.sav extension) in the \Saved\ directory. When you save your progress during a game, a new .sav file is made in that directory.
- dest$ is the returned value of the saved games directory window. The DirSav command returns "CANCEL" is the user selected the cancel option.
// This will load a saved game.
file$ = dirSav()
// Show the saved games and store the selected
// file in file$
if (file$ ~= "CANCEL")
{
	load(file$)
}
// If a file was selected, load the file.
[ top ]

NAME: Done with program
FORMAT: done()

This command ends execution of a program, but does not restore the screen to what it was before the program began. If there were graphics put on the board, they will still be there when the program ends. The same goes for text in the message window, and other things.
// Set some graphics...
layerPut(2, 5, 1, "terrain.gph")
layerPut(2, 6, 1, "terrain.gph")
// Now, end the program, but keep
// the graphics on the board...
done()
[ top ]

NAME: Drain All
FORMAT: drainAll(smp!)

This command will drain all SMP of the players or enemies in battle. When used with a special move, this will take the smp of the group of enemies or players depending on which was targeted with the special move.
- smp! is the amount of SMP to drain.
// Drain a group of 100 SMP...
drainAll(100)
[ top ]

NAME: Draw Canvas
FORMAT: drawCanvas(hCnv!, x!, y![, sizex!, sizey!, hCnvDest!])

Draws a canvas to the screen or to another canvas.
- hCnv! is the handle of the canvas to draw.
- x!, y! are the x and y coordinates to draw the canvas to.
- sizex!, sizey! (if specified) are the width and height (in pixels) to scale the canvas to.
- hCnvDest! (if specified) is the canvas to draw hCnv! to.
cnvTitle! = createCanvas(64, 64)
// Create a new canvas...
bitmap("title.bmp", cnvTitle!) // Put an image in the canvas. drawCanvas(cnvTitle!, 0, 100) // Draw the canvas on screen. killCanvas(cnvTitle!) // Now, kill the canvas once I'm done with it.
[ top ]

NAME: Draw Canvas Transparently
FORMAT: drawCanvasTransparent(hCnv!,x!,y!,r!,g!,b![,width!,height!,hCnvDest!])

This command draws a canvas to the screen using transparency.
- hCnv! is the handle of the canvas.
- x!, y! are the x and y coordinates to draw the canvas to.
- r!, g!, b! are the RGB values for the transparent color.
- width!, height! are optional parameters for the width and height.
- hCnvDest! (if specified) is the canvas to draw hCnv! to.
hCnv! = createCanvas(640, 480)
setImageTransparent("layout.gif", 0, 0, 640, 480, 0, 0, 0)
drawCanvasTransparent(hCnv!, 0, 0, 0, 0, 0)
[ top ]

NAME: Draw a Circle
FORMAT: drawCircle(x!, y!, radius![, sAngle!, eAngle!])

This command draws a circle with it's center at x! and y! and a radius of specified by radius!.
- x!,y! are the x and y coordinates of the center of the circle.
- radius! is the radius of the circle.
- sAngle!,eAngle! are optional parameters that allow you to specify start and end angles for an arc.
// Draw a bunch of circles extending from the origin...
for (x! = 0; x! < 80; x! += 5)
{
	for (y! = 0; y! < 80; y! += 5)
	{
		colorRGB(x!, x!, x!)
		drawCircle(x!, y!, 10)
	}
}
[ top ]

NAME: Draw a Line
FORMAT: drawLine(x1!, y1!, x2!, y2![, cnvID!])

This command draws a line from x1!,y1! to x2!,y2!. The color of the line is specified with the ColorRGB command.
- x1!,y1! are the starting x and y coordinates of the line.
- x2!,y2! are the ending x and y coordinates of the line.
- cnvID! is an optional parameter for drawing to a canvas.
// Draw a line extending from the origin...
for (x! = 0; x! < 80; x! += 5)
{
	for (y! = 0; y! < 80; y! += 5)
	{
		colorRGB(x!, x!, x!)
		drawLine(10, 10, x!, y!)
	}
}
[ top ]

NAME: Draw Rectangle
FORMAT: drawRect(x1!, y1!, x2!, y2![, cnvID!])

This command draws a rectangle with the corner coordinates at x1!,y1! and x2!,y2!. The color of the rectangle is specified with the ColorRGB command.
- x1!,y1! are the top corner coordinates of the rectangle.
- x2!,y2! are the bottom corner coordinates of the rectangle.
- cnvID! is an optional parameter for drawing to a canvas.
// Draw a bunch of random rectangles...
for (count! = 0; count! <= 15; count!++)
{
	color! = random(255)
	colorRGB(color!, color!, color!)
	x1! = random(608)
	y1! = random(352)
	x2! = random(608)
	y2! = random(352)
	drawRect(x1!, y1!, x2!, y2!)
}
[ top ]

NAME: Earthquake
FORMAT: earthquake(intensity!)

This command causes the screen to shake for an earthquake-like effect.
- intensity! is a numerical value which defines the strength and duration of the earthquake.
// Let's shake the earth!
earthquake(10)
[ top ]

NAME: Else
FORMAT: else

The Else command executes a block of code inside its opening and closing braces as long as the preceding If statement and/or elseIf statement is false. If the if, elseIf, or else statements are used and one of the conditions are true, the other statements are ignored.
if (x! == 12)
{
	mwin("x! is 12")
}
elseIf (x! < 12)
{
	mwin("x! is less than 12")
}
else
{
	mwin("x! is higher than 12")
}
[ top ]

NAME: Else If
FORMAT: elseIf (condition)

The elseIf command executes a block of code inside it's opening and closing braces as long as it's condition is true. However, it will not execute if the preceding If statements condition's are true. If you have more than one elseIf statement, only one will run.
if (x! == 12)
{
	mwin("x! was 12")
}
elseIf (x! == 15)
{
	mwin("x! was 15")
}
else
{
	mwin("x! was neither 12 nor 15!")
}
[ top ]

NAME: empty all variables
FORMAT: empty()

This command clears all variables in your game of their values. Be very careful when using this command! It could mess up some parts of your game if you don't use it sparingly!
// Kill all variables...
empty()
[ top ]

NAME: End execution
FORMAT: end()

This command is used to stop flow of the program. Most people used it to end execution of a program in TK2, but it is now preferred to use stop() for that. The end() command can be used to end a method at a certain point, or various other things relating to program flow.
method Something()
{
	done! = false
	while (!done!)
	{
		key$ = wait()
		mwin("Press A to end the method, or B to continue.")
		if (key$ == "A")
		{
			done! = true
			end() // End the method
		}
		if (key$ == "B")
		{
			done! = true
			mwin("You wanted to continue!")
			mwin("Sadly, we have to end now...")
			wait()
		}
	}
}
[ top ]

NAME: End Animation
FORMAT: endAnimation(hAnim!)

Ends execution of an animation started with the Animation() or sizedAnimation() commands.
- hAnim! is the handle of the animation to end.
hAnim! = endAnimation(anmID!)
[ top ]

NAME: Equip item
FORMAT: equip(handle$, location!, item$)

This command equips an item on a player. The item must already be in the players inventory and must be equipable to that player. Otherwise, it will not work.
- handle$ is the handle of the player. "target" is an acceptable value.
- location! is a numerical value between 1 and 16. It specifies where to equip the item to. Legal positions are:
1 - Head
2 - Neck accessory
3 - Right hand
4 - Left hand
5 - Body
6 - Legs
7 to 16 - accessories 1 through 10.
- item$ is the filename of the item to equip.
// Give the player an item and equip it
giveItem("sword.itm")
equip("Frap", 3, "sword.itm")
[ top ]

NAME: Erase Item
FORMAT: eraseItem(item_num!)

This command removes an item from the screen. The item will still be in memory, but it won't be on the screen. You can recall the item using the PutItem command.
- item_num! is the memory slot of the item to erase.

createItem("soldier.itm", pos!) // Load the item into a slot
putItem(pos!, 3, 2, 1)          // Put the item on the board
pushItem(pos!, "E,E,E")         // Push the item east three times
mwin("Hi! Bye!")
wait()
eraseItem(pos!)   // Erase the item from the board
destroyItem(pos!) // Remove the item from memory
[ top ]

NAME: Erase Player
FORMAT: erasePlayer(handle$)

This command erases a player from the board. This is very useful for characters entering and leaving story sequences.
- handle$ is the name of the player to erase.
// Short story sequence in which Frap and Tano interact.
// Frap is the main character and is already on the board.
// Let's say he's at 5,5. We'll have Tano emerge from
// this location.

putPlayer("Tano", 5, 5, 1)
push("E,E,W", "Tano")
mwin("Tano: Well, here we are in some strange RPGCode story sequence.")
wait()
mwinCls()
mwin("Frap: Watch this!")
wait()
mwinCls()
push("N,E,E,S", "Frap")
mwin("Tano: Wow, that's really great. You can walk. Now I'm going")
mwin("to walk toward you and vanish into your chest somehow.")
wait()
mwinCls()
mwin("Frap: Cool.")
wait()
mwinCls()
push("E", "Tano")
erasePlayer("Tano")
[ top ]

NAME: Fade
FORMAT: fade(fade_type!)

fade() is used to "fade out" the screen. The color of the fade is specified by the ColorRGB command.
- fade_type! is a numerical value from 0 to 4. Each number represents a different type of "fade". The fading types are as follows (note that leaving out the fade_type! parameter defaults it to 0):
0 - A growing and shrinking box that blots out the screen.
1 - Better fading type that blots out the screen with vertical lines.
2 - "True fade"; fades the screen from white to black.
3 - A fading line sweeps across the screen.
4 - A black circle swoops down and swallows the player.
colorRGB(0, 0, 255) // Set the color to blue.
fade(1) // Fade the screen with vertical lines.
colorRGB(255, 255, 255)
[ top ]

NAME: Fight
FORMAT: fight(skill_level!, background$)

This command initiates a fight between the player and an enemy from a program. This command ends execution of a program, so everything after this command will not be run. To have code run after the fight is over, simple place a continuation of the program in the "program to run upon defeating enemy" slot in the enemy editor. This command is useful for initiating fighting sequences with bosses, because your fighting program can be attached to a tile, or an NPC of the boss.
- skill_level! is the skill level of the enemy. If a few enemies to set to, let's say, level 37, and you specify that you want to fight a level 37 enemy, the toolkit will randomly select an enemy of that level for you to fight. If you want to fight a specific enemy, put that enemy on a level of it's own which no other enemy has, or, use the FightEnemy command to specify exactly which enemy to fight.
- background$ is the background image to fight against. This is the same background as the ones you set for the board when a battle starts.
// Demonstration of using the Fight command.
// Let's have some evil guy attack you with
// his random bunch of minions.

mwin("Ha! Now I will have random minions fight you!")
wait()
mwin("Get him!")
wait()
mwinCls()
fight(10, "background.bkg")
// Fight an enemy of level 10
// on the "background.bkg" background.
[ top ]

NAME: Fight Enemy
FORMAT: FightEnemey(enemy1$[, enemy2$, etc.], background$)

This command initiates a fight between the player and the specified enemy(s). This command is slightly better to use than the Fight command in the case of boss fights, as the can specify which enemies you want to fight directly.
- enemyX$ are the filenames of the enemies to fight. You can have any number of enemies from 1 to 4.
- background$ is the background image to fight on.
fightEnemy("mole.ene", "badguy.ene", "background.bkg")
// Fight two enemies on the "background.bkg" background.
[ top ]

NAME: Change Fight Menu Graphic
FORMAT: fightmenuGraphic(graphic$)

By default, the menu for the battle system is black. You can place a background image on the menu using this command.
- graphic$ is the graphic file to change the background to.
// Change the fight menu graphic...
fightMenuGraphic("fight.jpg")
[ top ]

NAME: End of File
FORMAT: dest! = fileEOF(file$)

Checks to see if the end of an open file has been reached. If so, it returns 1. If not, it returns 0. The supported mode for this command is "input mode" or "output mode".
- file$ is the file to check.
- dest! is the returned value.
openFileInput("mymethods.prg","Prg") // Opens a file in input mode
dest! = fileEOF("mymethods.prg")     // Has the end of the file been reached?
closeFile("mymethods.prg")           // Close the file when done
[ top ]

NAME: File Get
FORMAT: dest! = fileGet(file$)

Gets binary data from a file. The supported mode for this command is "binary mode".
- file$ is the file to check.
- dest! is the returned data.
openFileBinary("mymethods.prg","Prg") // Opens a file in binary mode
dest! = fileGet("mymethods.prg")      // Get some data from the program!
closeFile("mymethods.prg")            // Close the file when done
[ top ]

NAME: File Input
FORMAT: dest$ = fileInput(file$)

Returns a line from an open file. Once the line from the file is returned, it positions itself at the next line in the file. The supported mode for this command is "input mode".
- file$ is the file to get input from.
- dest$ is the returned value.
openFileInput("mymethods.prg","Prg") // Opens a file in input mode
dest$ = fileInput("mymethods.prg") // Return data
closeFile("mymethods.prg") // Close the file when done
[ top ]

NAME: File Print
FORMAT: filePrint(file$, data$)

Prints data into a file. The supported mode for this command is "append mode".
- file$ is the file to append to.
- data$ is the data to append to the file.
openFileAppend("mymethods.prg","Prg") // Opens a file in append mode
filePrint("mymethods.prg", "yay") // Print this data to the file
closeFile("mymethods.prg") // Close the file when done
[ top ]

NAME: File Put
FORMAT: filePut(file$, data$)

Puts binary data into a file. The supported mode for this command is "binary mode".
- file$ is the file to put binary data in.
- data$ is the data to put into the file.
openFileBinary("mymethods.prg","Prg") // Opens a file in input mode
filePut("mymethods.prg",binarydata$) // Put this binary data in the file
closeFile("mymethods.prg") // Close the file when done
[ top ]

NAME: Fill Circle
FORMAT: fillCircle(x!, y!, radius![, cnvID!])

This command draws a filled circle on the screen. The color of the circle is specified with the ColorRGB command.
- x!,y! are the x and y coordinates of the center of the circle.
- radius! is the radius of the circle.
- cnvID! is an optional parameter for drawing to a canvas.
// Draw a bunch of circles extending from the origin
for (x! = 0; x! < 80; x! += 5)
{
	for (y! = 0; y! < 80; y! += 5)
	{
		colorRGB(x!, x!, x!)
		fillCircle(x!, y!, 10)
	}
}
[ top ]

NAME: Fill Rectangle
FORMAT: fillRect(x1!, y1!, x2!, y2![, cnvID!])

This command draws a filled rectangle on the screen with corners at x1,y1 and x2,y2. The color of the rectangle is specified with the colorRGB command.
- x1!,y1! are the top corner x and y coordinates for the rectangle.
- x2!,y2! are the bottom corner x and y coordinates for the rectangle.
- cnvID! is an optional parameter for drawing to a canvas.
// Draw a bunch of random rectangles...
for (count! = 0; count! <= 15; count!++)
{
	colorRGB(random(255), random(255), random(255))
	fillRect(random(600), random(400), random(600), random(400))
}
[ top ]

NAME: Change Font
FORMAT: font(new_font$)

This command changes the font of the game from the default. The font must be in the font folder for it to work correctly. Remember to use the fonts actual name when specifying which you want to use.
- new_font$ is the new font to change the current font to.
mwin("Default font...")
wait()
mwinCls()
font("verdana")
mwin("New font!")
[ top ]

NAME: Change Font Size
FORMAT: fontSize(size!)

This command allows you to change the size of the font. By default, this is set to 16.
- size! represents the size of the font in pixels.
fontSize(8)
mwin("Small font.")
wait()
mwinCls()
fontSize(16)
mwin("Big font.")
wait()
mwinCls()
[ top ]

NAME: For-Loop
FORMAT: for (initial; condition; increment)

The For command allows you to initiate a For-loop. For-loops in RPGCode have the same syntax as C++. A For-loop is a set of commands (called a "block of code") that gets executed over and over again until a certain condition is false. This is much more convinient than writing 100 lines of repetitive code. The For-loop goes through four stages. First, it initiates a variable (intial;). Next, it checks if a condition is true (condition;). If it is, then it will run the block of code inside of the braces (the { and }). Once it's done, it will go through the incrementation process, where you can increment or decrement the variable. It then goes back to the second stage, checking if the condition is still true, and goes from there. It does this until the condition is false.
// This is a demonstration of the For-loop.
// This will run a statement over and over again
// until a certain condition is false.

for (count! = 1; count! < 5; count!++)
{
	show(count!) // Show the contents of 'count!'
}
[ top ]

NAME: Force Redraw
FORMAT: forceRedraw()

This command forces the board to redraw itself. If you have put any graphics on the board, they will disappear. This command is very useful when changing the ambient color values of the board.
// Fade out...
for (x! = 0; x! > -255; x! -= 10) { ambientred! = x! ambientgreen! = x! ambientblue! = x! forceRedraw() }
[ top ]

NAME: Game Speed
FORMAT: gameSpeed(speed!)

The GameSpeed command controls the overall speed of the game; individual speeds are set for each player and item.
- speed! is a value between -4 and +4, where negative numbers decrease (-10%) and positive increase (+10%) the overall game speed.
gameSpeed(0) // Sets the speed of the game to normal.
[ top ]

NAME: Get
FORMAT: a$ = get()

The Get command works like the Wait command, except it doesn't freeze the computer until the user presses a button. It returns the current keyboard buffer (what the user pressed) to a variable, while still executing the program.
- a$ is the variable that holds the returned value.
a$ = get()
[ top ]

NAME: Get Board Name
FORMAT: dest$ = getBoardName()

This command gets the board name and stores it in dest$ for later use.
boardName$ = getBoardName()
[ top ]

NAME: Get Board Tile Name
FORMAT: dest$ = getBoardTile(x!, y!, layer!)

This command saves the filename of a tile on the board at x,y,layer into dest.
- x!,y! are the x and y coordinates of the tile.
- layer! is the layer on the board that the tile is on.
- dest$ is the returned name of the tile.
tile$ = getBoardTile(3, 10, 1)
show(tile$)
wait()
[ top ]

NAME: Get Board Tile Type
FORMAT: dest$ = getBoardTileType(x!, y!, layer!)

This command gets the tile-type of a tile at x,y,layer and returns the type to dest$.
- x!,y! are the x and y coordinates of the tile.
- layer! is the layer on the board that the tile is on.
- dest$ is the returned type. Valid types are "NORMAL", "SOLID", "UNDER", "NS", "EW", and "STAIRSx", where 'x' is a number between 1 and 8 for the 8 layers you can have.
type$ = getBoardTileType(5, 5, 1)
show(type$)
wait()
[ top ]

NAME: Get Color
FORMAT: getColor(r!, g!, b!)

This command gets the current color set by the ColorRGB command and returns the red, green, and blue values of the color to r!,g!,b!.
getColor(r!,g!,b!)
mwin("The color value is: <r!>,<g!>,<b!>")
wait()
mwin("Let's switch them around!")
temp! = r!
r! = g!
g! = b!
b! = temp!
colorRGB(r!, g!, b!)
[ top ]

NAME: Get Corner
FORMAT: getCorner(topx!, topy!)

This command gets the top x and y coordinates that the board is currently scrolled to.
- topx!,topy! are the returned top x and y coordinates.
getCorner(top_x!, top_y!)
mwin("The board is scrolled to: <top_x!>, <top_y!>")
wait()
[ top ]

NAME: Get DP
FORMAT: dest! = getDP(handle$)

This command gets the DP of a player or enemy.
- handle$ is the player/enemy handle. "target" and "source" are valid handles.
- dest! is the returned DP of the player or enemy.
dp! = getDP("Frap") // Get Frap's DP
targDP! = getDP("target") // Get the targets DP
[ top ]

NAME: Get Font Size
FORMAT: dest! = getFontSize()

This command gets the current font size.
- dest! is the returned font size value.
size! = getFontSize()
mwin("The font size is: <size!>")
[ top ]

NAME: Get FP
FORMAT: dest! = getFP(handle$)

This command gets the FP of a player or enemy.
- handle$ is the player/enemy handle. "target" and "source" are valid handles.
- dest! is the returned FP of the player or enemy.
fp! = getFP("Frap") // Get Frap's FP
targFP! = getFP("target") // Get the targets FP
[ top ]

NAME: Get GP
FORMAT: gp! = getGP()

This command gets your GP value.
- gp! is the returned gp.
gp! = getGP()
if (gp < 50)
{
	mwin("Hey, you don't have enough gp!")
}
[ top ]

NAME: Get HP
FORMAT: dest! = getHP(handle$)

This command gets the HP of a player or enemy.
- handle$ is the player/enemy handle. "target" and "source" are valid handles.
- dest! is the returned HP of the player or enemy.
hp! = getHP("Frap") // Get Frap's HP
targHP! = getHP("target") // Get the targets HP
[ top ]

NAME: Get Item Cost
FORMAT: dest! = getItemCost(filename$)

Gets the buying price of an item and returns it to dest!.
- filename$ is the filename of the item.
- dest! is the returned value.
dest! = getItemCost("my_item.itm")
mwin("This item costs <dest!>.")
wait()
mwinCls()
[ top ]

NAME: Get Item Description
FORMAT: dest$ = getItemDesc(filename$)

Gets the description of an item and returns it to dest$.
- filename$ is the filename of the item.
- dest$ is the returned value.
dest$ = getItemDesc("my_item.itm")
mwin("Item <dest$>")
wait()
mwinCls()
[ top ]

NAME: Get Item Name
FORMAT: dest$ = getItemName(filename$)

Gets the handle (name) of an item and returns it to dest$.
- filename$ is the filename of the item.
- dest$ is the returned value.
dest$ = getItemName("my_item.itm")
mwin("You have recieved <dest$>!")
wait()
mwinCls()
[ top ]

NAME: Get Item Selling Price
FORMAT: dest! = getItemSellPrice(filename$)

Gets the selling price of an item and returns it to dest!.
- filename$ is the filename of the item.
- dest! is the returned value.
dest! = getItemSellPrice("my_item.itm")
mwin("You may sell this item for <dest!>.")
wait()
mwinCls()
[ top ]

NAME: Get SMP
FORMAT: dest! = getSMP(handle$)

This command gets the SMP of a player or enemy.
- handle$ is the player/enemy handle. "target" and "source" are valid handles.
- dest! is the returned SMP of the player or enemy.
smp! = getSMP("Frap") // Get Frap's SMP
targSMP! = getSMP("target") // Get the targets SMP
[ top ]

NAME: Get Level
FORMAT: dest! = getLevel(handle$)

This command gets the level of a player.
- handle$ is the player handle. "target" and "source" are valid handles.
- dest! is the returned level of the player.
level! = getLevel("Frap") // Get Frap's level
targLevel! = getLevel("target") // Get the targets level
[ top ]

NAME: Get Max HP
FORMAT: dest! = getmaxHP(handle$)

This command gets the max HP of a player.
- handle$ is the player handle. "target" and "source" are valid handles.
- dest! is the returned max HP of the player.
maxhp! = getmaxHP("Frap") // Get Frap's max hp
targMaxHP! = getmaxHP("target") // Get the targets max hp
[ top ]

NAME: Get Max SMP
FORMAT: dest! = getmaxSMP(handle$)

This command gets the max SMP of a player.
- handle$ is the player handle. "target" and "source" are valid handles.
- dest! is the returned max SMP of the player.
maxsmp! = getmaxSMP("Frap") // Get Frap's max smp

targMaxSMP! = getmaxSMP("target") // Get the targets max smp
[ top ]

NAME: Get Pixel
FORMAT: getPixel(x!, y!, r!, g!, b!, cnv!)

This command returns the RGB value of a pixel at x,y.
- x!,y! are the x and y coordinates of the pixel.
- r!,g!,b! are the returned red, green, and blue color values of the pixel.
- cnv! is an optional parameter for getting the pixel from a canvas.
getPixel(10, 30, r!, g!, b!)
[ top ]

NAME: Get Resolution
FORMAT: getRes(x!, y!)

This command gets the current game resolution (the resolution the game is set to in the main file editor).
- x!,y! are the width and height of the game screen.

getRes(width!, height!)
mwin("The games resolution is: <width!>,<height!>")
[ top ]

NAME: Get Text Height
FORMAT: height! = getTextHeight(string$)

This command returns the height of a string of text in pixels, relative to the current font size.
- string$ is the text to get the height of.
- height! is the returned number of pixels.
height! = getTextHeight("Hiya")
[ top ]

NAME: Get Text Width
FORMAT: width! = getTextWidth(string$)

This command returns the width of a string of text in pixels, relative to the current font size.
- string$ is the text to get the width of.
- width! is the returned number of pixels.
width! = getTextWidth("Hiya")
[ top ]

NAME: Get Thread ID
FORMAT: hThread! = getThreadID()

Gets the thread handle of the currently running multitask program. This is useful when you want to kill a thread. Note that it's supposed to be used inside a thread to get the handle.
- hThread! is the handle of the thread to return.
hThread! = thread("mythread.prg", 0) // Run the thread "mythread.prg"

killthread(hThread!) // Kill the thread when done
[ top ]

NAME: Give Experience Points
FORMAT: giveEXP(handle$, amount!)

Gives the player a set amount of experience points. It will automatically give the player a level up if needed.
- handle$ is the handle of the player to give experience to.
- amount! is the amount of exp to give.
giveEXP("Frap", 500)
[ top ]

NAME: Give GP
FORMAT: giveGP(amount!)

Gives the player a set amount of GP.
- amount! is the amount of GP to give.
giveGP(100)
[ top ]

NAME: Give HP
FORMAT: giveHP(handle$, amount!)

Gives the player or enemy a certain amount of hp.
- handle$ is the handle of the player to give hp to. "target" and "source" are valid handles.
- amount! is the amount of hp to give.
HP("Frap", 100)     // Give Frap 100 HP
giveHP("Frap", 20)  // Give Frap 120 HP
giveHP("Frap", -90) // Take away 90 HP
[ top ]

NAME: Give Item
FORMAT: giveItem(item_name$)

This command gives an item to the player.
- item_name$ is the filename of the item to give.
giveItem("sword.itm")
mwin("You've obtained a sword!")
wait()
mwinCls()
[ top ]

NAME: Give SMP
FORMAT: giveSMP(handle$, amount!)

Gives the player or enemy a certain amount of smp.
- handle$ is the handle of the player to give smp to. "target" and "source" are valid handles.
- amount! is the amount of smp to give.
SMP("Frap", 20) // Give Frap 20 SMP
giveSMP("Frap", 20) // Give Frap 40 SMP
giveSMP("Frap", -10) // Take away 10 SMP
[ top ]

NAME: Create Global Variable
FORMAT: global(varName[, value])

By default, the Toolkit sets all variables to Global scope. Global variables can be read from anywhere in your game unless you kill() them. If you create a variable with the local() command and you meant to create it globally, you can use the global() command to re-declare it as global.
- varName is the name of the variable.
- value is the value to assign to the variable.
Autolocal()
// Since I've specified that all implicitly delcared variables
// are automatically 'local', I'll need to use global() to make
// a global variable.
global(x!) // Declare the x! as global
[ top ]

NAME: Gone
FORMAT: gone()

This command ends execution of a program and removes the program from the board. So if the player steps on the tile again, there will be no program that runs. This is only in effect, however, until the player leaves and reenters the board.
mwin("Farewell, cruel world!")
// Now, end the program and remove it...
gone()
[ top ]

NAME: HP
FORMAT: HP(handle$, new_HP!)

Gives the player or enemy a set amount of hp.
- handle$ is the handle of the player to give hp to. "target" and "source" are valid handles.
- new_HP! is the amount of hp to give.
HP("Frap", 100) // Give Frap 100 HP
giveHP("Frap", 20) // Give Frap 120 HP
giveHP("Frap", -90) // Take away 90 HP
[ top ]

NAME: If...
FORMAT: if (condition) { code to run }

This command lets you check if a variable has a certain value or not. The condition is some condition that you are testing. It can test if two values are equal to, not equal to, less than or greater than each other. If the condition is true, a block of code will be executed.
The If command has six basic conditions it can test. They are as follows: Equal to (==), Not equal to (~=), Greater than (>), Less than (<), Greater than or equal to (>=), Less than or equal to (<=).
The If command also supports inline commands, equasions, and logical operators. For more about these more advanced If features, please read the RPGCode Primer.
Between the brackets (the { and }, which are also called 'curly braces), you can put a block of code. This block of code will, again, only be executed if the condition in the If command is true. All of this together is called an 'If statement'.
// Here's an example showing the six basic
// if statement conditions...

var! = 1
if (var! == 1) { // This block of code will only get executed // if 'var!' is equal to 1. mwin("Hello!") wait() var!++ } if (var! ~= 1) { // This block of code will only get executed // if 'var!' is NOT 1. mwin("How are you?") wait() } if (var! < 10) { // This block of code will only get executed // if 'var!' is less than 10. mwin("Nice day, isn't it?") wait() mwinCls() var! = 10 } if (var! <= 10) { // This block of code will only get executed // if 'var!' is less than or equal to 10. mwin("I'm running out of things to say!") wait() mwinCls() var!++ } if (var! => 11) { // This block of code will only get executed // if 'var!' is greater than or equal to 11. mwin("Read any good books lately?") wait() mwinCls() var! += 3 } if (var! > 12) { // This block of code will only get executed // if 'var!' is greater than 12. mwin("Time to go. Bye bye!") wait() mwinCls() }
[ top ]

NAME: Iif Statement
FORMAT: ret = iif(condition, true, false)

This statement resembles an advanced version of the If statement. It checks the condition you specify, and returns the value of true or false depending on if the condition is true or false.
- condition is the condition to check.
- true is the value to return if the condition is true. This can be either a literal or numerical value.
- false is the value to return if the condition is false. This can be either a literal or numerical value.
- ret is the returned value. It can be either literal or numerical.

x! = prompt("Enter a number")
y! = prompt("Enter another number")
ret$ = iif(x! == y!, "Yay!", "Boo!")
show(ret$)
[ top ]

NAME: Include File
FORMAT: include(filename$)

This commands includes an RPGCode program into the currently running program. If you include a file, you will be able to use the methods from inside of that file. This is extremely useful for making method libraries and importing them wherever you need them.
- filename$ is the filename of the RPGCode program to include.
// Include the "system" library.
Inlcude("system.prg")

// Now, I can use methods from inside of that
// program. For example, 'Pause()'.
mwin("Try pressing the arrow keys!")
Pause()
[ top ]

NAME: Restore HP/SMP
FORMAT: inn()

This command refills the HP and SMP of all players on your team.
inn()
[ top ]

NAME: Pop up internal menu
FORMAT: internalMenu(menu_number!)

This command pops up one of the internal menus.
- menu_number! is a numerical value between 0 and 4. Here are the corresponding pop up menus:
0 - Main menu
1 - Items
2 - Equip
3 - Abilities
internalMenu(0)
// Pop up the main menu.
[ top ]

NAME: In String
FORMAT: dest! = inStr(string1$, string2$)

Checks to see if there is an occurance of one part of a string inside of another and returns either 1 or 0 to dest!.
- string1$ is the first string.
- string2$ is the string to compare string1$ to.
- dest! is the outcome. Returns 1 if there is an occurance of string1$ in string2$. Returns 0 if there isn't.
dest! = inStr("Hello world!", "Hello")
// Finds out if there is any similarities in sometext1$
// and sometext2$. If there is, it returns 1. If not, it
// returns 0.
mwin("Look at that, sometext1$ and sometext2$ both have the word")
mwin("Hello in them. That means InStr will return 1!")
mwin("I'll prove it: <dest!>. See?!")
wait()
mwinCls()
[ top ]

NAME: Turn italics on/off
FORMAT: italics(on_off$)

This command turns the italics effect on or off on your text.
- on_off$ is a literal value that can be "on" or "off".
italics("off")
mwin("Boring regular text...")
wait()
mwinCls()
italics("on")
mwin("Italic text!")
[ top ]

NAME: Item count
FORMAT: dest! = itemCount(item_name$)

This command counts how many of any particular item the player is carrying.
- item_name$ is the name of the item to count.
- dest! is the returned number.
nCure! = itemCount("cure")
mwin("You have <nCure!> cures.")
wait()
[ top ]

NAME: Item Location
FORMAT: itemLocation(item_num!, x!, y!, layer!)

This command locates a specific item on the board.
- item_num! is a numerical value for which item you wish to find.
- x!,y!,layer! are the x, y, and layer coordinates returned as the location.
createItem("man.itm", itmMan!)
putItem(itmMan!, 3, 3, 1)
itemLocation(itmMan!, itmx!, itmy!, itmLayer!)
[ top ]

NAME: Set Item Speed
FORMAT: itemSpeed(num!, speed!)

This command allows you to set the walk speed of a specific item on the board.
- num! is the number of the item.
- speed! is the delay, in seconds, between steps (recommended 0.05 to 0.2).
createItem("man.itm", pos!)
putItem(pos!, 3, 5)
itemSpeed(pos!, 0.1)
[ top ]

NAME: Item Stance
FORMAT: itemstance(slot!, stance$)

This command allows you to put an item in any stance. Their stances are the custom postures and animations set in the item editor.
- slot! is the item slot.
- stance$ is the stance to use.
// Put the item in a 'sleeping' position
itemstance(0, "sleeping")
[ top ]

NAME: Item Step
FORMAT: itemStep(item_num!, x!, y!)

This command causes the specified item to walk one step toward x and y.
- item_num! is the item number.
- x!,y! are the x and y coordinates of where the item should go.
// This causes an item to step toward
// the player...
createItem("item.itm", item!)
putItem(item!, 5, 5, 1)
itemStep(item!, playerX[0]!, playerY[0]!)
[ top ]

NAME: Kill
FORMAT: kill(var1, var2, etc...)

This command deletes variables from memory, thus freeing up space and allowing you to create more variables. It's always a good idea to kill variables that you aren't going to use in the long run, as they'll only clutter things.
- var1, var2, etc. are the variables to delete from memory. You can delete as many variables at one time as you wish.
var1! = 18
var2$ = "Bob"
show(var1!) // Output: 18
show(var2$) // Output: Bob
kill(var1!, var2$)
show(var1!) // Output: 0
show(var2$) // Output: 
[ top ]

NAME: Kill All Redirects
FORMAT: killAllRedirects()

This command nullifies all of the redirects in use.
killAllRedirects()
[ top ]

NAME: Kill Canvas
FORMAT: killCanvas(hCnv!)

Kills a canvas. Remember that you should always kill a canvas when you're done with it, because canvases take up and can easily slow your game down.
- hCnv! is the handle of the canvas.
hCnv! = createCanvas(64, 64)   // Create a new canvas...
bitmap("title.bmp", cnvTitle!) // Put an image in the canvas.
drawCanvas(hCnv!, 0, 100)      // Draw the canvas on screen.
killCanvas(hCnv!)              // Now, kill the canvas.
[ top ]

NAME: Kill Cursor Map
FORMAT: killCursorMap(hMap!)

Kills a cursor map specified by hMap!. Use this when you're done with your cursor map.
- hMap! is the handle of the cursor map to kill.

pixeltext(300, 180, "New Game")
pixeltext(300, 210, "Load Game")
pixeltext(300, 230, "Quit")

done! = false
while (!done!)
{
	// Create a cursor map with the id cMap!
	// Set where the cursor can go to...
	cMap! = createCursorMap()
	cursorMapAdd(295, 180, cMap!)
	cursorMapAdd(295, 210, cMap!)
	cursorMapAdd(295, 230, cMap!)
	res! = cursorMaprun(cMap!)
	killCursorMap(cMap!)
}

switch (res!)
{
	case (0)
	{
		// New game
	}
	case (1)
	{
		// Load game
	}
	case (2)
	{
		// Quit
	}
}
[ top ]

NAME: Kill a Redirect
FORMAT: killredirect(methodName$)

This command deletes a redirection that had been created with redirect().
- methodName$ is the redirect to kill.
killredirect()
[ top ]

NAME: Kill Thread
FORMAT: killthread(hThread!)

Stop execution of a multitask program (thread).
- hThread! is the handle of the thread to kill.
hThread! = thread("mythread.prg", 0) // Run the thread "mythread.prg"
killthread(hThread!) // Kill the thread when done
[ top ]

NAME: Layer Put
FORMAT: layerPut(x!, y!, layer!, graphic$)

This command places a tile graphic on the board at the specified location. The graphic will only remain on the board for the duration of time that the player is on the board.
- x!,y!,layer! are the x, y, and layer coordinates to place the graphic.
- graphic$ is the tile graphic to place on the board. The graphic file must be a valid .gph or .tst file.
layerPut(4, 6, 1, "graphic1.gph")
layerPut(3, 2, 1, "terrain.tst1")
[ top ]

NAME: Lower Case
FORMAT: dest$ = lCase(string$)

Casts a string of characters to all lower-case characters and returns it to dest$.
- string$ is the string of characters to cast to lower-case.
- dest$ is the returned string.
string$ = prompt("What's your name?")
name$ = lCase(string$)
mwin("Hello, <name$>")
[ top ]

NAME: Left
FORMAT: dest$ = left(text$, amount!)

This command takes characters from the left side of a string, and returns it to dest$.
- text$ is the text to take characters from.
- amount! is the number of characters to take from the left side of text$.
- dest$ is the returned sub-string.
show( left("I love you!", 4) + "athe" + right("I love you!", 5) )
// Result: "I loathe you!"
wait()
[ top ]

NAME: Length
FORMAT: dest! = length(string$)

Gets the length of a string and returns the value to dest!.
- string$ is the text to get the length of.
- dest! is the number of characters in the string.
dest! = length("Hello!")
// Finds out how many characters are in the string
// "Hello!". A string is just a fancy way to say
// text.
mwin("There are <dest!> characters in the string 'hello!'")
wait()
mwinCls()
[ top ]

NAME: Load Game
FORMAT: load(filename$)

Throughout your game, you have the choice to save your progress using programs that have the Save command. In order to play these saved games, there must be a program that loads the saved files. You can do this with the Load command. When the game loads, the currently running program and game end and you are taken to the board where you last saved. All of the previously used variables are reassigned their values.
- filename$ is the name of the file to load.
// This will load a saved game.

file$ = dirSav()
// Show the saved games and store the selected
// file in file$

if (file$ ~= "CANCEL")
{
	load(file$)
}
// If a file was selected, load the file.
[ top ]

NAME: Create Local Variable
FORMAT: local(varName[, value])

By default, the Toolkit sets all variables to Global scope. Global variables can be read from anywhere in your game unless you #Kill them. With the #Local command, you can create a local variable which will only be accessible in the program that you declare it in. When the program ends, the variable will be destroyed.
- varName is the name of the variable.
- value is the value to assign to the variable.
local(x!) // Create a local variable x!
[ top ]

NAME: Load main file
FORMAT: mainFile(file$)

This command resets the game and runs the specified main file. This is a good way for showing off unlockable secrets once you beat a game, like playing as the bad guys.
- file$ is the main file to run.
// Example showing some different main files...
done! = false
while (!done!)
{
	mwin("Who would you like to play as?")
	mwin("1 - the good guys")
	mwin("2 - the bad guys")
	a! = wait()
	if (a! == 1)
	{
		// Run the main file for the good guys...
		mainFile("good.gam")
		done! = true
	}
	else if (a! == 2)
	{
		// Run the main file for the bad guys...
		mainFile("bad.gam")
		done! = true
	}
}
[ top ]

NAME: Set Max HP
FORMAT: maxHP(handle$, new_maxhp!)

This command sets the maximum amount of HP that the player can have.
- handle$ is the handle of the player. "target" is also a valid handle.
- new_maxhp! is the new amount of HP that the player can have at max.
old_maxhp! = getmaxHP("Frap")
mwin("Frap's old max HP: <old_maxhp!>")
maxHP("Frap", old_maxhp! + 100)
new_maxhp! = getmaxHP("Frap")
mwin("Frap's new max HP: <new_maxhp!>")
wait()
[ top ]

NAME: Set Max SMP
FORMAT: maxSMP(handle$, new_maxsmp!)

This command sets the maximum amount of SMP that the player can have.
- handle$ is the handle of the player. "target" is also a valid handle.
- new_maxsmp! is the new amount of SMP that the player can have at max.
old_maxsmp! = getmaxSMP("Frap")
mwin("Frap's old max SMP: <old_maxsmp!>")
maxSMP("Frap", old_maxsmp! + 100)
new_maxsmp! = getmaxSMP("Frap")
mwin("Frap's new max SMP: <new_maxsmp!>")
wait()
[ top ]

NAME: Play a media file
FORMAT: mediaPlay(filename$)

This command plays a media file. It supports the file extensions .mid, .mp3, .wav, and more.
- filename$ is the filename of the media file to play.
mediaPlay("Song.mp3")
[ top ]

NAME: Stop a media file
FORMAT: mediastop(filename$)

This command stops a media file played with mediaPlay().
- filename$ is the name of the file to stop.
mediastop("Song.mp3")
[ top ]

NAME: Put a scanned tile on board
FORMAT: mem(x!, y!, mem_position!)

This command places a tile on the board that has been scanned into memory with the scan() command.
- x!,y! are the x and y coordinates to place the tile on. The x and y locations are restricted to what the board is scrolled to, so x! is a value from 1 to 19, and y! is a value from 1 to 11.
- mem_position! is a numeric value between 1 and 10 stating which tile you would like to load from memory.
// Example showing the Scan and Mem commands.

// Save the tile at 3,8 into memory position 1.
scan(3, 8, 1)

// Now, place that tile at 1,1.
mem(1,1,1)
[ top ]

NAME: Change Menu Graphic
FORMAT: menuGraphic(graphic$)

This command allows you to change the background image of the menu.
- graphic$ is the filename of the graphic to change it to.
menuGraphic("wow.jpg")
[ top ]

NAME: Declare a method
FORMAT: method methodName(parameters)

The method command allows you to define a method. Methods, for those who may know Java/C/C++, are similar to functions. For those who aren't familiar with functions, functions are blocks of code that can be executed by typing in one line of code. Using methods, you can extend RPGCode to do even more than it can already by creating your own personalized commands. Commands created with the method command work in the same exact way that normal commands do. That is to say, methods have names, and you type in the name and parameters (if any are needed) the same way you would with a regular command.
- methodName is the name of your method. The name of the method should relate to what the method does. Your method name cannot start with a number, cannot be a variable, and cannot be in quotation marks.
- parameter(s) is the parameter(s) that your method uses. These are just like the parameters of a normal command.
// Example of how to create a method
// that makes a player walk around in circles.

method WalkInCircles(handle$)
{
	// handle$ is our parameter. It's the name of the player
	// to make walk around in circles.

	push("N,NE,E,SE,S,SW,W,NW,N", handle$)
	// Now the player has walked in a circle.
}

// Now, we can call the method like this...
WalkInCircles("Frap")
// This makes "Frap" walk around in a circle.
[ top ]

NAME: Mid
FORMAT: dest$ = mid(string$, start!, length!)

Finds characters in a string starting at start! and ending at length!. It then returns it to dest$.
- string$ is the string of characters to search in.
- start! is the starting character position.
- length! is the ending character position.
- dest$ is the returned string.
newString$ = mid("Awesome", 4, length("Awesome"))
show(newString$)
// Shows: "some" in the message window.
[ top ]

NAME: Wait for mouse click
FORMAT: mouseClick(x!, y![, wait!])

This command waits for the user to click the mouse, storing the location in x,y. This command is like the Wait command, but the player has to click a button set with the SetButton command instead of pressing a key on the keyboard.
- x!,y! are the returned x and y coordinates of where the user clicked.
- wait! is an optional parameter. If it is set to 1, it will not wait for the user.
// Set the button...
setButton("button1.jpg", 0, 10, 10, 100, 100)
done! = false
// Loop through while done! is equal
// to it's inital value...
while (!done!)
{
	mouseClick(mx!, my!)
	dest! = CheckButton(mx!, my!)
	// Check if a button was pressed
	if (dest! == 0)
	{
		mwin("You pressed a button!")
		wait()
		mwinCls()
		done! = true // Break out of the loop
	}
}
clearButtons()
[ top ]

NAME: Change Mouse Cursor
FORMAT: mouseCursor(file$, x!, y!, r!, g!, b!)

This command changes the mouse cursor file.
- file$ is the filename of the image to use.
- x!, y! are the x and y coordinates of the cursors hot-spot.
- r!, g!, b! are the RGB color values to treat as transparent.
mouseCursor("mouse.jpg", 1, 1, 255, 0, 0)
[ top ]

NAME: Wait for mouse move
FORMAT: mousemove(x!, y!)

This command waits for the user to move the mouse and stores the location in x,y.
- x!,y! are the returned x and y coordinates of where the mouse moves.
// Set the button...
setButton("button1.jpg", 0, 10, 10, 100, 100)
done! = false
// Loop through while done! is equal
// to it's inital value...
while (!done!)
{
	mouseClick(mx!, my!)
	dest! = CheckButton(mx!, my!)
	// Check if a button was pressed
	if (dest! == 0)
	{
		mwin("You pressed a button!")
		wait()
		mwinCls()
		done! = true // Break out of the loop
	}
}
clearButtons()
[ top ]

NAME: Move program
FORMAT: move(x!, y![, layer!])

This command continues execution of the currently running program, but moves the program to a new location on the board. The next time the player steps on the tile that had this program, nothing will happen. If, however, the player steps on the tile where the program was newly assigned to, the program will run.
- x!,y! are the coordinates to move the program to. The x and y locations are restricted to what the board is scrolled to, so x! is a value from 1 to 19, and y! is a value from 1 to 11.
- layer! is an optional parameters specifying what layer to put the program on. If it is left out, layer! is assumed to be layer 1.
move(3, 5, 1)
// This program will move to 3,5 on layer 1.
mwin("Program moved!")
wait()
[ top ]

NAME: Message Box
FORMAT: dest! = msgBox(text$[, title$, type!, textColor!, bgColor!, bgPic$])

Pops up a message box with a combination of buttons. It then returns a number depending on which button was pressed.
- text$ is the message to appear in the box.
- type! is the type of button combintation. Check below the example for a list of combinations.
- textColor! is the color of the text.
- bgColor! is the background color of the box.
- bgPic$ is an optional parameter for a background image in the message box.
The different 'types' of message box bottom combinations are as follows:
0 - diplays 'OK' only.
1 - displays 'Yes' and 'No'.
The returned values are as follows (the returned value depends on what the user pressed):
'OK' returns 1.
'Yes' returns 6.
'No' returns 7.
// Shows a message box where you can
// only choose 'ok'. Heh heh...
ret! = msgBox("Aren't these message boxes cool?", "MsgBox", 0)
[ top ]

NAME: Multi-Run
FORMAT: multirun() { commands }

This command runs multiple commands inside it's opening and closing brackets. If used in a thread, it's useful for running a block of code without the thread giving control to another program. It can also be used for various other things, like making NPC's walk simultaneously (the commands aren't executed until Trans3 sees the closing bracket).
- commands is the block of code to run.
// multirun() will execute all commands before
// handing control over to something else.
multirun()
{
	pushItem(0, "N,N,N,N")
	pushItem(1, "S,S,S,S")
}
[ top ]

NAME: Message Window
FORMAT: mwin(text$)

This command displays text in the message window. You can also display the values of variables with Mwin. There are two ways of doing this. The first way is enclosing the variable name in left and right angle brackets (< and >). The second way is closing off your text with a closing quotation mark, putting a plus sign (+) after that, and then the variable name.
- text$ is the text to be placed in the message window. All text must be in quotation marks.
mwin("This is some text.")
wait()
var! = 5
mwin("Now, I'll display a variable: <var!>")
wait()
name$ = prompt("What's your name?")
mwin("Hello, " + name$ + "!")
wait()
[ top ]

NAME: Clear Message Window
FORMAT: mwinCls()

This command clears the message window and it's text from the screen. It's a good idea to use this whenever the message window gets full.
mwin("Hi there.")
wait()
mwinCls()
[ top ]

NAME: Message Window Size
FORMAT: mwinSize(size!)

This command defines the size of the message window.
- size! is a numeric value that specifies the percentage of the screen that the message window will take up horizontally. The default is 95.
mwin("Text before...")
wait()
mwinCls()
mwinSize(70)
mwin("Text after...")
wait()
[ top ]

NAME: Create new instance
FORMAT: object = new(handle)

This command allows you to create an instance of a class or structure. Instancing a class or structure means that you create an "object" that which lets you use the class'/structs variables or methods.
- object is the object to access the class'/structs data.
- handle is the handle (the name) of the class/struct.
// Create an object from a class ('instance' the class)...
pObject = new(CSomeClass)

// Use one of the methods from the class...
pObject->someMethod()

// Kill the data...
pObject->release()
[ top ]

NAME: Change player graphics
FORMAT: newPlyr(filename$)

This command changes the graphics of the player, but doesn't change the stats, or any other traits of the character. This is a good way to have airships, disguise items, and other things.
- filename$ is the filename of the graphics to use. It must be either a .tem, .cha, or .gph file.
mwin("Out with the old...")
wait()
newPlyr("awesome.tem")
mwin("In with the new!!!")
wait()
[ top ]

NAME: Check if player is On Board
FORMAT: dest! = onBoard(pNum!)

This command checks to see if the player is on the board.
- pNum! is the slot of the player (0 - 4) - dest! is the returned value. 1 is returned if the player is on the board, 0 if not.
if (onBoard(0) == 0)
{
	putPlayer(playerHandle[0]$, 3, 5, 1)
}
[ top ]

NAME: On Error Go to Label
FORMAT: on error goto :label_name

Branches to a label when an error occurs. When you branch to an error using the On Error command, do not resume the program normally. Use "resume next" to resume the line of code after the error.
- :label_name is the name of the label to branch to. The labels must be inside of the method and you must not indent the labels.
method FileExists(file$, folder$)
{
	// Declare the variable 'exists!'
	local(exists!)

	// Assume the file exists
	exists! = true

	on error goto :error

	// Try to open the file. If it doesn't exist,
	// it will cause an error.
	openFileInput(file$, folder$)

	// Close the file just incase it was opened, but
	// don't trigger another error.
	on error resume next
	closeFile(file$)

	// Return the result
	returnMethod(exists!)

	// End the method so the error handler isn't run
	end()

:error
// If we get here, there was an error exists! = false resume next } if (FileExists("SomePrg.prg","Prg")) { mwin("There was no error!") } else { debugger("Error opening file!") }
[ top ]

NAME: on error resume next
FORMAT: on error goto :label_name

If you use this command, any errors after this line of code will be "nullified" per se. It will act as if there was no error and resume the next line of code.
method FileExists(file$, folder$)
{
	// Declare the variable 'exists!'
	local(exists!)

	// Assume the file exists
	exists! = true

	on error goto :error

	// Try to open the file. If it doesn't exist,
	// it will cause an error.
	openFileInput(file$, folder$)

	// Close the file just incase it was opened, but
	// don't trigger another error.
	on error resume next
	closeFile(file$)

	// Return the result
	returnMethod(exists!)

	// End the method so the error handler isn't run
	end()

:error
// If we get here, there was an error exists! = false resume next } if (FileExists("SomePrg.prg","Prg")) { mwin("There was no error!") } else { debugger("Error opening file!") }
[ top ]

NAME: Open File in Append mode
FORMAT: openFileAppend(file$, folder$)

Opens a file in append mode. Append mode writes to the end of a file specified by file$. If the file does not exist, it will be created.
- file$ is the file to open.
- folder$ is the game folder to get the file from.
openFileAppend("start.brd","Boards") // Opens a file in 'append mode'
closeFile("start.brd") // Close the file
[ top ]

NAME: Open File in Binary mode
FORMAT: openFileBinary(file$, folder$)

Opens a file in binary mode. Binary mode accesses a file as binary. If the file does not exist, it will be created.
- file$ is the file to open.
- folder$ is the game folder to get the file from.
openFileBinary("start.brd","Boards") // Opens a file in 'binary mode'
closeFile("start.brd") // Close the file
[ top ]

NAME: Open File in Input mode
FORMAT: openFileInput(file$, folder$)

Opens a file in input mode. Input mode reads blocks of code in a program starting from the top and ending at a line break (a space between two blocks of code).
- file$ is the file to open.
- folder$ is the game folder to get the file from.
openFileInput("start.brd","Boards") // Opens a file in 'input mode'
closeFile("start.brd") // Close the file
[ top ]

NAME: Open File in Output mode
FORMAT: openFileOutput(file$, folder$)

Opens a file in output mode. Output mode overwrites any existing data in the file. If the file does not exist, it will be created.
- file$ is the file to open.
- folder$ is the game folder to get the file from.
openFileOutput("start.brd","Boards") // Opens a file in 'output mode'
closeFile("start.brd") // Close the file
[ top ]

NAME: Game Over
FORMAT: over()

This command displays a "game over" message in the message window and waits for the user to press a key, then resets the game back to the main file. If you wish to spruce up the game over, you may want to add your own effects and use reset() to restart the game.
// uh-oh, you lost the game!
over()
// This will show a "game over" message,
// wait for the user to press a key,
// then restart the game.
[ top ]

NAME: Path Find
FORMAT: pathFind(x1!, y1!, x2!, y2![, dest$])

Calculates the shortest path from points x1 and y1 to x2 and y2, then returns the path to dest$ to be used in #Push or #PushItem.
- x1!, y1! are the starting x and y coordinates (tile based).
- x2!, y2! are the ending coordinates, where the player will end up standing.
- dest$ is the returned value. The coordinates are placed in this.
dest$ = pathFind(1,1,5,1) // Returns the string "W,W,W,W" and stores it in dest$
push(dest$,"Frap") // Pushes Frap to coords 5 x and 1 y
[ top ]

NAME: Pixel Movement
FORMAT: pixelMovement(usePixelMovemement$ [, usePixelPush$])

This command turns pixel movement for players and items on and off. usePixelPush$ controls whether Push(), PushItem() etc. push in pixel or tile increments.
- usePixelMovemement$ is a literal value that can be either "ON" or "OFF".
- usePixelPush$$ is a literal value that can be either "ON" or "OFF".
pixelMovement("on", "off")
[ top ]

NAME: Pixel Text
FORMAT: pixeltext(x!, y!, text$[, hCnv!])

This command displays text on the screen the same way the text() command does, except it uses pixel coordinates. The color of the text is defined with the colorRGB() command.
- x!,y! are the x and y coordinates on the screen to place the text.
- text$ is the text to display on the screen.
- hCnv! is an optional parameter to draw the text to a canvas.
pixeltext(100, 100, "This text is at the pixel coordinates: 100, 100")
[ top ]

NAME: Play Avi (full screen) FORMAT: playAvi(filename$)

This command plays a video, stretching it to the size of the window. Supports *.avi, *.mov and *.mpg video formats.
- filename$ is the filename of the .avi file to play, located in the \Media folder.
mediaStop()
playAvi("movie.avi")
[ top ]

NAME: Play Avi (window) FORMAT: playAviSmall(filename$)

This command plays a video, at the default size centred in the screen. Supports *.avi, *.mov and *.mpg video formats.
- filename$ is the filename of the .avi file to play, located in the \Media folder.
mediaStop()
playAviSmall("movie.avi")
[ top ]

NAME: Set Character Speed
FORMAT: playerSpeed(num!, speed!)

This command allows you to set the walk speed of a specific character on the board. The character must be in your party.
- num! is the number of the item.
- speed! is the delay, in seconds, between steps (recommended 0.05 to 0.2).
putPlayer("Frap", 3, 5)
playerSpeed(0, 0.1)
[ top ]

NAME: Player Stance
FORMAT: playerstance(slot!, stance$)

This command allows you to put the player in any stance. Their stances are the custom postures and animations set in the character editor.
- slot! is the player slot (0 for player 1, 1 for player 2, etc.).
- stance$ is the stance to use.
// Put the player in a 'sleeping' position
playerstance(0, "sleeping")
[ top ]

NAME: Player Step
FORMAT: playerStep(handle$, x!, y!)

This command makes the player take a step towards x,y. It automatically calculates the shortest path and steps in that direction.
- handle$ is the handle of the player to move.
- x!,y! are the x and y coordinates to move the player toward.
playerStep("Frap", 4, 4)
[ top ]

NAME: Show custom Posture
FORMAT: posture(posture_num!, handle$)

This command shows a custom posture of the character. In the character editor, you can create your own postures. This command shows them.
- posture_num! is a numeric value between 0 and 10.
- handle$ is an optional parameter. By default, it is the main player, but you may specify differently.
// Cycle through postures 0-3.
for (pos! = 0; pos! <= 3; pos!++)
{
	posture(pos!, "Frap")
}
[ top ]

NAME: Move program
FORMAT: prg(filename$, x!, y![, layer!])

This command moves a program to a new location on the board. The change only remains in effect while the player is on the board.
- filename$ is the filename of the program to move. Alternatively, you may use a numeric value for the item number (specified in the program menu).
- x!,y! are the x and y coordinates to move the program to. The x and y locations are restricted to what the board is scrolled to, so x! is a value from 1 to 19, and y! is a value from 1 to 11.
- layer! is an optional parameter that specifies which layer to move the program to. If you leave it blank, it is assumed to be layer 1.
prg("test.prg", 5, 5, 1)
// Program "test.prg" was moved.
[ top ]

NAME: Prompt the user
FORMAT: dest$ = prompt(question$)

This command brings up the prompt window and asks the user a question. It will stay there until the user types in a response, which will be stored in dest$.
- question$ is the question to prompt the player with.
- dest$ is the returned answer from the player.
// Example showing the prompt command.
// This asks the user for their name, and
// places the answer in name$
name$ = prompt("What's your name?")
mwin("Hello, <name$>!")
wait()
[ top ]

NAME: Push
FORMAT: push(direction$, handle$)

Pushes a player around the screen in the specified directions. For Push to work, the player must be on the board, and they must be in your team at the time. The directions allowed are the following:
- "N", "NORTH", and "1" all push the player north.
- "S", "SOUTH", and "2" all push the player south.
- "E", "EAST", and "3" all push the player east.
- "W", "WEST", and "4" all push the player west.
- "NE", "NORTHEAST", and "5" all push the player north-east.
- "NW", "NORTHWEST", and "6" all push the player north-west.
- "SE", "SOUTHEAST", and "7" all push the player south-east.
- "SW", "SOUTHWEST", and "8" all push the player south-west.
- handle$ is the handle of the player to push.
By default, the value of handle$ is "Target" which is the player you are currently using. This means that if you leave handle$ out, it pushes the player that you see walking around when you play a game.
All directions must be inside quotation marks (" ") and must be separated by a comma (,). Different types of directions are allowed to be mixed. This means that you are allowed to have this as the directions: "N, SOUTH, 3, 1, NE, SW".
putPlayer("Frap",3,5,1)
mwin("Frap: Hey, watch me walk diagonally.")
wait()
mwinCls()
push("NE,NE,SW,SE", "Frap") // Pushes Frap diagonally
mwin("Frap: Now, I'll walk in a circle!")
wait()
mwinCls()
push("S,SE,E,NE,N,NW,W,SW", "Frap")
[ top ]

NAME: Push Item
FORMAT: pushItem(itemNum!, direction$)

Pushes an item around the screen in the specified directions. For PushItem to work, the item must be on the board.
- itemNum! is the number of the item to push.
The directions allowed are the following:
- "N", "NORTH", and "1" all push the item north.
- "S", "SOUTH", and "2" all push the item south.
- "E", "EAST", and "3" all push the item east.
- "W", "WEST", and "4" all push the item west.
- "NE", "NORTHEAST", and "5" all push the item north-east.
- "NW", "NORTHWEST", and "6" all push the item north-west.
- "SE", "SOUTHEAST", and "7" all push the item south-east.
- "SW", "SOUTHWEST", and "8" all push the item south-west.
All directions must be inside quotation marks (" ") and must be separated by a comma (,). Different types of directions are allowed to be mixed. This means that you are allowed to have this as the directions: "N, SOUTH, 3, 1, NE, SW".
createItem("OldMan.itm",pos!)
putItem(pos!,1,1,1)
mwin("Old Man: Watch me walk around!")
wait()
mwinCls()
pushItem(pos!,"SW,SW,1,3,NORTH,SOUTHWEST")
eraseItem(pos!)
destroyItem(pos!)
[ top ]

NAME: Put Item on the Board
FORMAT: putItem(item_num!, x!, y!, layer!)

This command places an item on the board at the specified x,y,layer coordinates. This command in useful in conjuntion with the createItem() command for making NPC's that walk around and talk in story sequences.
- item_num! is the number of the item specified in the board editor, or with the createItem() command.
- x!,y!,layer! are the x, y, and layer coordinates to place the item.
createItem("soldier.itm", pos!) // Load the item into a slot
putItem(pos!, 3, 2, 1) // Put the item on the board
pushItem(pos!, "E,E,E") // Push the item east three times
mwin("Hi! Bye!")
wait()
eraseItem(pos!) // Erase the item from the board
destroyItem(pos!) // Remove the item from memory
[ top ]

NAME: Put Player on the Board
FORMAT: putPlayer(handle$, x!, y!, layer!)

This command place a player on the board at the specified x,y,layer coordinates. When used in conjuntion with the push() and erasePlayer() commands, can make story senquences where characters can enter and leave the scene.
- handle$ is the handle of the player to put on the board. The player must be in your party at the time.
- x!,y!,layer! are the x, y, and layer coordinates to place the character.
// Short story sequence in which Frap and Tano interact.
// Frap is the main character and is already on the board.
// Let's say he's at 5,5. We'll have Tano emerge from
// this location.

putPlayer("Tano", 5, 5, 1)
push("E,E,W", "Tano")
mwin("Tano: Well, here we are in some strange RPGCode story sequence.")
wait()
mwinCls()
mwin("Frap: Watch this!")
wait()
mwinCls()
push("N,E,E,S", "Frap")
mwin("Tano: Wow, that's really great. You can walk. Now I'm going")
mwin("to walk toward you and vanish into your chest somehow.")
wait()
mwinCls()
mwin("Frap: Cool.")
wait()
mwinCls()
push("E", "Tano")
erasePlayer("Tano")
[ top ]

NAME: Generate random number
FORMAT: dest! = random(range!)

This command generates a random number between 1 and the specified range. For example, if range! were 100, then it would be a number between 1 and 100.
- range! is the range of the number.
- dest! is the returned number.
for (num! = 1; num! <= 5; num!++)
{
	// Show a random number...
	show(random(100))
}
[ top ]

NAME: Redirect method
FORMAT: redirect(old_method$, new_method$)

This command creates a redirection from one method to another. When you create a redirection, it will allow you to use new_method$ and new_method$ will do whatever old_method$ did.
- old_method$ is the method or command to redirect.
- new_method$ is the method for old_method$ to be redirected to.
redirect("Mwin", "customMwin")
// Now, all Mwin commands will be

// redirected to customMwin.
[ top ]

NAME: Remove equipment
FORMAT: remove(handle$, body_position!)

This command removes equipment from the player and returns it to the equipment inventory.
- handle$ is the handle of the player to remove equipment from.
- body_position! is a numeric value between 1 and 16. Legal positions are:
1 - Head
2 - Neck accessory
3 - Right hand
4 - Left hand
5 - Body
6 - Legs
7 to 16 - accessories 1 through 10.
// Remove the sword on Frap's right hand
remove("Frap", 4)
[ top ]

NAME: Remove player from team
FORMAT: removePlayer(handle$)

This command removes one player from your party. There is a maximum of five players at one time. Unlike destroyPlayer(), this command allows you to bring the player back in using CallPlayerSwap() or restorePlayer().
- handle$ is the handle of the player to remove.
// Remove Tano from the team
removePlayer("Tano")
[ top ]

NAME: Remove status effect
FORMAT: removeStatus(handle$, file$)

This command removes a status effect from the player or enemy.
- handle$ is the handle of the player or enemy. "target" and "source" are valid handles.
- file$ is the filename of the status effect to remove.
removeStatus("target", "poison.ste")
[ top ]

NAME: Render Screen
FORMAT: renderNow(on/off)

When you start a game with the Toolkit, a canvas is created called 'cnvRenderNow!'. This command will constantly render that canvas, meaning you can constantly render custom HP bars for a real-time effect, and other things. Note that this command only works for the cnvRenderNow! canvas.
- on/off can either be on or off.
renderNow("on")
[ top ]

NAME: Replace
FORMAT: dest$ = replace(expression$, find$, replace$)

The Replace command replaces the specified character(s) in find$ with replace$. It then returns the string to dest$.
- expression$ is the string of text in which to find the characters defined with find$.
- find$ are the characters in expression$ to replace.
- replace$ is what will replace the characters in find$.
- dest$ is the returned string of characters.
var$ = "newVar$"
show(var$) // Shows the value "newVar$" dest$ = replace(var$, "$", "!=1") rpgCode(dest$) show(newVar!) // Shows the value 1 wait()
[ top ]

NAME: Reset to startup
FORMAT: reset()

This command resets your game, losing all unsaved game information and returns to the startup screen.
// Example using reset()

done! = false
while (!done!)
{
	mwin("Reset the game.")
	mwin("Are you sure? [Y/N]")
	yn$ = wait()
	if (yn$ == "y") { reset() }
	if (yn$ == "n")
	{
		done! = true
		// Break out of the loop.
	}
}
[ top ]

NAME: Restore Player
FORMAT: restorePlayer(handle$)

This command brings a player back into your team that has been removed with removePlayer(). The stats and level of the player are the same as they were when the player was removed.
- handle$ is the name of the player to add back to your team.
// Add, remove, and restore a player

addPlayer("Tano.tem")
removePlayer("Tano.tem")
restorePlayer("Tano.tem")
[ top ]

NAME: Restore screen
FORMAT: restoreScreen([x1!, y1!, x2!, y2!, xdest!, ydest!])

Restores the screen to the way it was when you used the saveScreen() command. All parameters are optional. If you leave them out, it will restore the entire screen.
- x1!,y1! are the starting coordinates (from left and from top) on the screen to draw from.
- x2!,y2! are the ending coordinates on the screen to draw from.
- xdest!,ydest! are the top-left coordinates to draw to.
saveScreen()
restoreScreen()
[ top ]

NAME: Restore Screen Array
FORMAT: restoreScreenArray(pos![, x1!, y1!, x2!, y2!, xdest!, ydest!])

Restores a screen from the screen buffer array. All parameters after pos! are optional. If you leave them out, it will restore the entire screen from the buffer position.
- pos! is the array position to restore the screen from.
- x1!,y1! are the starting coordinates (from left and from top) on the screen (in pixels) to draw from.
- x2!,y2! are the ending coordinates on the screen to draw from.
- xdest!,ydest! are the coordinates to draw to.
saveScreen(0) // Save the screen...
push("W,N,N,N") // Now change the screen by pushing the character.
restoreScreenArray(0) // Restore the entire screen.
[ top ]

NAME: resume next Line
FORMAT: resume next

Resumes the next line of code after branching to a label with On Error.
method FileExists(file$, folder$)
{
	// Declare the variable 'exists!'
	local(exists!)

	// Assume the file exists
	exists! = true

	on error goto :error

	// Try to open the file. If it doesn't exist,
	// it will cause an error.
	openFileInput(file$, folder$)

	// Close the file just incase it was opened, but
	// don't trigger another error.
	on error resume next
	closeFile(file$)

	// Return the result
	returnMethod(exists!)

	// End the method so the error handler isn't run
	end()

:error
// If we get here, there was an error exists! = false resume next } if (FileExists("SomePrg.prg","Prg")) { mwin("There was no error!") } else { debugger("Error opening file!") }
[ top ]

NAME: Return the screen to normal
FORMAT: return()

This command returns the screen to what it was before the program started, removing all text and graphics that may have been set during the program. This is often used in conjunction with the clear command.
Clear()
mwin("The screen is cleared.")
mwin("Press a button to return the screen.")
wait()
return()
[ top ]

NAME: Return method data
FORMAT: returnMethod(variable$ or variable!)

This command returns a value from a method to a variable. This is very useful for returning information to the user for specifying what a certain value is, did an action fail or not, and many other things. For more information on returning values, please take a look at the Methods section of the RPGCode Primer.
- variable$ or variable! is a value that can either be literal or numerical.
// Example using returnMethod()
// We'll create a method that adds two numbers
// together and return the value to add_dest!

method Add(add_num!, add_num2!)
{
	returnMethod(add_num! + add_num2!)
}

// Now, we'll call the method and show the result
// in the message window.
num! = Add(4, 1)
mwin("4 + 1 = <num!>")
wait()
[ top ]

NAME: Right
FORMAT: dest$ = right(text$, amount!)

This command takes characters from the right side of a string, and returns it to dest$.
- text$ is the text to take characters from.
- amount! is the number of characters to take from the right side of text$.
- dest$ is the returned sub-string.
show( left("I love you!", 4) + "athe" + right("I love you!", 5) )
// Result: "I loathe you!"
wait()
[ top ]

NAME: RPGCode
FORMAT: rpgCode(data$)

The most versatile of all RPGCode commands, rpgCode() allows you to run an RPGCode command, create complex and advanced functions, and much more.
- data$ is the data to pass in to rpgCode() and run. This must be a literal value.
// Example using rpgCode()
// This will allow the user to create
// a multi-dimensional array using a
// method.

method NewMultiArray(varName$, n!, n2!, value$)
{
	rpgCode(varName$ + "[" + CastLit(n!) + "][" + CastLit(n2!) + "]$ = value$")
}

// Now, call the method...
NewMultiArray("test", 0, 1, "hello")
show(test[0][1]$) // This will show "hello"
[ top ]

NAME: Run program
FORMAT: run(file$)

This command runs an RPGCode program internally from the currently running program. This is useful for breaking up larger programs into smaller pieces.
- file$ is the filename of the RPGCode program to run.
mwin("This is program 1!")
mwin("Press a button to run program 2.")
wait()
run("another.prg")
[ top ]

NAME: Save game
FORMAT: save(file$)

Throughout the game, the player has a chance to save his/her game if they want to resume playing later. This is done through a program that has the save() command. The save() command saves a game to the \saved\ folder.
- file$ is the filename of the game to save.
// This will load a saved game.
file$ = dirSav()
// Show the saved games and store the selected
// file in file$
if (file$ ~= "CANCEL")
{

	save(file$)
}
// If a file was selected, load the file.
[ top ]

NAME: Save Screen
FORMAT: saveScreen([pos!])

This saves a screen into the save screen buffer. In TK2, you could only save one screen. However, you can now save as many screens as you want.
- pos! is the buffer position to save the screen to.
saveScreen(0) // Save the screen...
push("W,N,N,N") // Now change the screen by pushing the character.
restoreScreenArray(0) // Restore the entire screen.
[ top ]

NAME: Scan tile
FORMAT: scan(x!, y!, mem_pos!)

This command scans a tile on the board and saves it into a memory slot. This tile can later be accessed using the mem() command.
- x!,y! are the x and y coordinates of the tile to save.
- mem_pos! is a numeric value from 1 to 10 to save the tile to.
// Example showing the Scan and Mem commands.
scan(3, 8, 1)
// Save the tile at 3,8 into memory position 1.
mem(1,1,1)
// Now, place that tile at 1,1.
[ top ]

NAME: Send player to board
FORMAT: send(board$, x!, y![, layer!])

This command loads a new board and places the character at the specified x and y coordinates. This is a very useful command for making doors to rooms and other such things.
- board$ is the filename of the board to send the player to.
- x!,y! are the x and y coordinates on the board to place the character.
- layer! is an optional parameter specifying which layer to put the player on. If left out, it will assume that the layer is layer 1.
// Send the player to a new board
// when they walk up to a door...
send("house.brd", 6, 8, 1)
[ top ]

NAME: SetButton
FORMAT: setButton(file$, pos!, x!, y!, width!, height!)

This command places a button on the screen. In conjunction with the CheckButton and MouseClick commands, you can make working, clickable buttons for menus, and other things.
- file$ is the filename of the button to set on the screen.
- pos! is the 'slot' position to set the button in.
- x!,y! are the x and y coordinates on the screen to place the button.
- width!,height! are the width and height of button.
// Set the button...
setButton("button1.jpg", 0, 10, 10, 100, 100)
done! = false
// Loop through while done! is equal
// to it's inital value...
while (!done!)
{
	mouseClick(mx!, my!)
	dest! = CheckButton(mx!, my!)
	// Check if a button was pressed
if (dest! == 0) { mwin("You pressed a button!") wait() mwinCls() done! = true // Break out of the loop } } clearButtons()
[ top ]

NAME: Set Constants
FORMAT: setConstants()

Updates the values of the constants in the RPGToolkit. The 'constants' are the reserved variables which are automatically created for you. For a list of the reserved variables, check the RPGCode Primer.
// A useful example of using the setConstants() command.
// Updates the player location and returns it to you.
method GetPlayerCoords(slot!, px!, py!)
{
	setConstants()
	px! = playerx[slot!]!
	py! = playery[slot!]!
	returnMethod(px!)
	returnMethod(py!)
}
[ top ]

NAME: Set Image
FORMAT: setImage(file$, x!, y!, width!, height![, cnv!])

This command sets an image on the screen.
- file$ is the filename of the image.
- x!,y! are the x and y coordinates on the screen to place the image.
- width!,height! are the width and height of the image.
- cnv! is an optional parameter for drawing the image to a canvas.
setImage("Wow.jpg", 0, 0, 600, 300)
[ top ]

NAME: Set Image Additive
FORMAT: setImageAdditive(file$, x!, y!, width!, height!, percent![, cnv!])

This command sets an image on the screen with an additive attribute for translucency.
- file$ is the filename of the image.
- x!,y! are the x and y coordinates on the screen to place the image.
- width!,height! are the width and height of the image.
- percent! is the percent of the additive translucency to use.
- cnv! is an optional parameter for drawing the image to a canvas.
setImageAdditive("Wow.jpg", 0, 0, 600, 300, 50)
[ top ]

NAME: Set Image Translucent
FORMAT: setImageTranslucent(file$, x!, y!, width!, height![, cnv!])

This command sets an image on the screen and blends it in with the background for a translucent effect.
- file$ is the filename of the image.
- x!,y! are the x and y coordinates on the screen to place the image.
- width!,height! are the width and height of the image.
- cnv! is an optional parameter for drawing the image to a canvas.

setImageTranslucent("Wow.jpg", 0, 0, 600, 300)
[ top ]

NAME: Set Image Transparent
FORMAT: setImageTransparent(file$, x!, y!, width!, height!, r!, g!, b![, cnv!])

This command sets an image on the screen with a transparent color.
- file$ is the filename of the image.
- x!,y! are the x and y coordinates on the screen to place the image.
- width!,height! are the width and height of the image.
- r!,g!,b! are the RGB color values to treat as transparent.
- cnv! is an optional parameter for drawing the image to a canvas.
setImageTransparent("Wow.jpg", 0, 0, 600, 300, 255, 255, 255)
[ top ]

NAME: Set Pixel
FORMAT: setPixel(x!, y![, hCnv!])

This command sets a pixel somewhere on the screen. It's color is defined by the ColorRGB command.
- x!,y! are the x and y coordinates on the screen to place the pixel.
- hCnv! is an optional parameter for setting the pixel in a canvas. Use the Canvas handle for this.
// Draws a pixel line from 0,100 to 255,100
for (x! = 0; x! < 255; x!++)
{
	colorRGB(0, 0, x!)
	setPixel(x!, 100)
}
[ top ]

NAME: Change Shop Colors
FORMAT: shopColors(pos!, r!, g!, b!)

This command changes the colors of the shop window.
- pos! is the area to change. 0 for background, 1 for foreground.
- r!,g!,b! are the RGB color values used to change the color of the window.
shopColors(0, 0, 0, 0)
shopColors(1, 255, 255, 255)
CallShop("sword.itm", "potion.itm")
[ top ]

NAME: Show variable contents
FORMAT: show(variable)

This command shows the contents (value) of a variable in the message window on it's own line.
- variable can either be a literal or numerical variable. The contents of that variable are shown in the message window.
var1! = 15
var2$ = "Hello"
show(var!) // This shows "15" in the message window
show(var$) // This shows "Hello" in the message window
[ top ]

NAME: Calculate Sine
FORMAT: dest! = sin(angle!)

This command calculates the sine of an angle and returns the answer to dest!.
c! = Cos(90)
s! = sin(90)
t! = tan(90)
[ top ]

NAME: Play Sized Animation
FORMAT: hAnim! = sizedAnimation(file$, x!, y!, sizex!, sizey![, loop!])

This command plays a sized animation, made with the animation editor, on the screen.
- file$ is the filename of the animation to play.
- x!,y! are the x and y coordinates on the screen to play the animation.
- sizex!,sizey! are the width and height of the animation.
- loop! is an optional parameter only for threads. It causes the animation to loop until the thread is killed, or endAnimation() is used.
- hAnim! is the returned animation handle. Use this when ending an animation.
hAnim! = sizedAnimation("Explosion.anm", 10, 10, 100, 100)
[ top ]

NAME: New SMP
FORMAT: SMP(handle$, new_smp!)

This command changes the current amount of SMP that the specified player or enemy has.
- handle$ is the handle of the player or enemy. "target" and "source" are valid handles.
- new_smp! is the amount of SMP to replace the current SMP that the player or enemy has.
getSMP("Frap", smp!)
SMP("Frap", smp!+smp!)
// Set Frap's smp to double it's original value.
[ top ]

NAME: Source Handle
FORMAT: dest$ = sourceHandle()

This command retrieves the handle of the current "source" handle. The answer is placed in dest$.
handle$ = sourceHandle()
giveHP(handle$, 100)
// Give the 'source' 100 HP
[ top ]

NAME: Get Source Location
FORMAT: sourceLocation(x!, y!)

This command gets the x and y coordinates of the 'source' character or enemy in battle. This is useful for programs that run with special moves because you can put an explosion graphic or something on the enemy or player.
- x!,y! are the returned x and y coordinates of the player or enemy in battle.
sourceLocation(x!, y!)
layerPut(x!, y!, 1, "boom.gph")
mediaPlay("boom.wav")
[ top ]

NAME: Split
FORMAT: split(text$, delimiter$, array[])

Splits a string of text into a new array when it reaches the string delimiter.
- text$ is the text to split.
- delimiter$ is the the point in text$ where it gets split into a new array.
- array[] is the name of the array to use to store the split text.
split("Nice to see you again!", " ", "nice[]$")
// This stores "Nice" in the array 'nice[0]$',
// "to" in the array 'nice[1]$', etc.
// The delimiter is " " (a space), so each word
// is split into a different array.
[ top ]

NAME: Calculate Square root
FORMAT: dest! = sqrt(value!)

This command calculates the square root of a number.
- value! is the number to calculate.
- dest! is the returned value.
dest! = sqrt(9)
[ top ]

NAME: Stance
FORMAT: stance(position![, handle$])

This command gives you access to all of the individual images used for the characters animations.
- position! is a numerical value that accesses the images. The way they are accessed is in this order:
Walking south
Walking east
Walking north
Walking west
Fight graphics
Special move graphics
Defense graphics
Dying graphics
Custom postures
Fight at rest
- handle$ is an optional parameter for specifying which players postures to use. By default, it's the main character on the team.
// Cycle through south walking graphics
for (count! = 1; count! <= 4; count!++)
{
	stance(count!, "Frap")
}
[ top ]

NAME: Start
FORMAT: start(file$)

This command allows you to run almost any file from the RPGToolkit. The file-type extension must be a valid extension. This will not allow you to run files with a .exe, .lnk, .pif, or .com file extension. As long as the extension is included, the Operating System will know what you want to do.
- file$ is the filename of the file to run. You must include the extension or else it will not run.
done! = false
while (!done!)
{
	mwinCls()
	mwin("What would you like to do?")
	mwin("1 - Play AVI file")
	mwin("2 - Visit RPGToolkit Website")
	mwin("3 - Exit the program")
	a! = wait()
	switch (a!)
	{
		Case (1)
		{
			// Play .avi file
			start("movie.avi")
			done! = true
		}
		Case (2)
		{
			// Visit the RPGToolkit Website
			start("http:// www.rpgtoolkit.com/")
			done! = true
		}
		Case (3)
		{
			// Exit the loop/program
			done! = true
		}
	}
}
[ top ]

NAME: Stop program
FORMAT: stop()

This command is used to stop execution of a program.
done! = false
while (!done!)
{
	mwin("Press Q to stop the program!")
	if (wait() == "Q")
	{
		done! = true
		stop() // Stop the program!
	}
}
[ top ]

NAME: Create structure
FORMAT: struct StructName { code }

This command creates a new structure. Structures are used for structuring and organizing your code. They can contain data such as variables and arrays. You can recall the data by creating an object for the structure (or 'instancing' the structure). Data is accessed through a class by using the accessor operator (->).
- StructName is the name of the structure.
- code is the data to go into the structure.
// Example of using a structure

// Define the structure
struct ENEMY
{
	// Enemy data...
	name$
	hp!
	maxhp!
	smp!
	maxsmp!
	att!
	def!
}

// Create an object and assign some values...
Enemy[0] = ENEMY()

Enemy[0]->name$ = "Bob"
Enemy[0]->hp! = 50
Enemy[0]->maxhp! = 50
// etc...
[ top ]

NAME: Switch
FORMAT: switch (var! or var$ or command())

The Switch command makes checking for true conditions even easier than using a bunch of If statements. It uses 'Cases' to check for values.
- var!, var$, or command() is the parameter for checking.
switch (x!)
{
	case (1) {
		// If x! is equal to 1, do this
		// block of code.
		show(x!)
	}
	case (Else) {
		mwin("x! was not 1)
	}
}
[ top ]

NAME: Take GP
FORMAT: takeGP(amount!)

This command takes a certain amount of GP away from the player.
- amount! is the amount of gp to take.
gp! = getGP()
mwin("You have: <gp!>GP")
giveGP(100)
gp! = getGP()
mwin("Now you have: <gp!>GP")
takeGP(100)
gp! = getGP()
mwin("Now you have: <gp!>GP")
wait()
[ top ]

NAME: Take Item
FORMAT: takeItem(item_name$)

This command takes an item away from the player.
- item_name$ is the filename of the item to take away.
// Take away a sword.
takeItem("sword.itm")
mwin("You lost your sword!")
wait()
[ top ]

NAME: Calculate Tangent
FORMAT: dest! = tan(angle!)

This command calculates the tangent of an angle and returns the value to dest!.
c! = Cos(90)
s! = sin(90)
t! = tan(90)
[ top ]

NAME: Target Handle
FORMAT: dest$ = targetHandle()

This command retrieves the current "target" handle. The answer is placed in dest$.
handle$ = targetHandle()
giveHP(handle$, 100)
// Give the 'target' 100 HP
[ top ]

NAME: Get Target Location
FORMAT: targetLocation(x!, y!)

This command gets the x and y coordinates of the 'taret' character or enemy in battle. This is useful for programs that run with special moves because you can put an explosion graphic or something on the enemy or player.
- x!,y! are the returned x and y coordinates of the player or enemy in battle.
targetLocation(x!, y!)
layerPut(x!, y!, 1, "boom.gph")
mediaPlay("boom.wav")
[ top ]

NAME: Tell Thread
FORMAT: return = tellthread(hThread!, command$)

This command lets you run a command or method inside of the currently running multitask program (or "threaded" program) from an outside program.
- hThread! is the handle of the thread.
- command$ is the RPGCode command or method to run.
- return is an optional parameter which can be either literal or numeric that returns a value from the command that was passed into the thread.
// Runs the method "Talk()"
// and returns a value.
ret! = tellthread(hThread!, "talk()")
[ top ]

NAME: Text
FORMAT: text(x!, y!, text$[, cnvID!])

This command very useful. It allows you place text anywhere on the game-screen. You aren't limited to the message window. The range of the x and y coordinates are determined by the font size. You can determine the maximum size for each easily: For x, divide the width of the game screen resolution by the font size. For y, divide the height of the games screen resolution by the font size. The color of the text is defined by the ColorRGB command. Text will stay on the screen only for the duration of time that the program is running.
- x!,y! are the x and y coordinates on the screen to place the text. Note: the x and y are not the same as the board grid, and are not in pixels.
- text$ is the text to show on the screen.
- cnvId! is an optional parameter to draw the text to a canvas.
// This will display text at positions 1,1
text(1, 1, "Hello, player!")

// This will show the contents of a variable
var$ = "Yay"
text(1, 2, var$)

// You can also combine text and variables
name$ = prompt("What's your name?")
text(1, 3, "Hello, " + name$)
[ top ]

NAME: Thread
FORMAT: hThread! = thread(program$, persist!)

This command runs a multitasking program (or "threaded" program), which means the player can still walk around and interact while the program is running.
- program$ is the multitask program to run.
- persist! is a numeric value between 0 and 1. If 0, the thread will stop when the player leaves the board. If 1, the thread will loop and run when the player is on another board too.
- hThread! is the handle of the thread.
hThread! = thread("my_program.prg", 0)
// Sets the multitask program "my_program.prg".
// Only runs while player is on the board.
[ top ]

NAME: Thread Sleep
FORMAT: threadSleep(hThread!, duration!)

This stops a multitask program (thread) for a certain amount of time specified by duration!.
- hThread! is the handle of the thread.
- duration! is the time (in seconds) for the thread to sleep.
hThread! = thread("mythread.prg", 0) // Run the thread "mythread.prg"
threadSleep(hThread!, 60) // Make the thread sleep for 60 seconds

// Oh no, an event came up! Wake up the thread!
threadWake(hThread!)
[ top ]

NAME: Thread Sleep Remaining
FORMAT: remain! = threadSleepRemaining(hThread!)

Gets the time (in seconds) that remains until a sleeping thread wakes up.
- hThread! is the handle of the thread.
- remain! is a returned value that stores the remaining time.
hThread! = thread("mythread.prg", 0) // Run the thread "mythread.prg"
threadSleep(hThread!, 60) // Make the thread sleep for 60 seconds

// Get the remaining time
seconds! = threadSleepRemaining(hThread!)
[ top ]

NAME: Thread Wake
FORMAT: threadWake(hThread!)

Makes a sleeping thread 'wake up' and become active once again.
- hThread! is the handle of the thread.
hThread! = thread("mythread.prg", 0) // Run the thread "mythread.prg"
threadSleep(hThread!, 60) // Make the thread sleep for 60 seconds

// Oh no, an event came up! Wake up the thread!
threadWake(hThread!)
[ top ]

NAME: Trim
FORMAT: dest$ = trim(text$)

Trims tabs and/or spaces off of the sides of a string of text.
- text$ is the text to trim the spaces/tabs off of.
- dest$ is the returned trimmed text.
someText$ = "  La la la. "
someText$ = trim(someText$)
[ top ]

NAME: Change Tile Type
FORMAT: tileType(x!, y!, type$[, layer!])

This command changes the type of a tile at the specified x,y,layer coordinates. - x!,y! are the x and y coordinates on the board to change the type.
- type$ is the type of tile to change it to. Valid types are: "NORMAL", "SOLID", and "UNDER".
- layer! is an optional parameter for specifying the layer. The default is 1.
// Change the tile type at 10,10,1 to SOLID
tileType(10, 10, "SOLID", 1)
[ top ]

NAME: Upper Case
FORMAT: dest$ = uCase(string$)

Casts a string of characters to all upper-case characters and returns it to dest$.
- string$ is the string of characters to cast to upper-case.
- dest$ is the returned string.
string$ = prompt("What's your name?")
dest$ = uCase(string$)
mwin("Hello, <name$>")
[ top ]

NAME: Underline
FORMAT: underline(on_off$)

This command turns on and off the underline effect on your text.
- on_off$ is a literal value that can be "on" or "off".
mwin("Boring regular text...")
wait()
mwinCls()
underline("on")
mwin("Underlined text!")
wait()
[ top ]

NAME: Until
FORMAT: until (condition) { commands }

This command acts almost the same way as a While loop does. It loops through a block of commands until a condition is met.
- condition is the condition to meet to break the loop.
- commands is the block of code to run.
// Example of the Until Loop.
until (done!) { var!++ // Increment var! show(var!) if (var! > 1) { done! = true // Break out of the loop. } }
[ top ]

NAME: View Board
FORMAT: viewBrd(filename$[, topx!, topy!])

This command loads a board and displays it on the screen. Once the program has ended, the board is erased, and the game goes back to the board the program started from.
- filename$ is the filename of the board to view.
- topx!,topy! are optoinal parameters for specifying a top corner to draw to.
viewBrd("another.brd")
[ top ]

NAME: Wait for keypress
FORMAT: dest$ = wait()

This command pauses the program and waits for the user to press a key on the keyboard. If the user presses one of the arrow keys, either "UP", "DOWN", "LEFT", or "RIGHT" is returned. Optionally, you don't have to specify a return variable if you just need to wait for a keypress, and not store it in a variable for use in a block of code.
- dest$ is the returned character that the user pressed.
mwin("Press a key!")
a$ = wait()
// This returns the keypress to a$
mwin("You pressed " + a$)
wait() // This doesn't return a keypress.
[ top ]

NAME: Wander
FORMAT: wander(item[, restrict!])

Makes an item (npc) wander around the board. Use this to create walking npc's, items, or enemies.
- item is the item to make wander. You can use the value "target" here.
You can also restrict the item's walking range by using the restrict! parameter. The allowed restrictions are the following:
- 0 (or left blank) is the default, which only lets the item wander N, S, E, and W on a normal board and NE, NW, SE, and SW on an isometric board.
- 1 always moves the item N, S, E, or W.
- 2 always moves the item NE, NW, SE, or SW.
- 3 allows the item to wander in all directions.
while (true)
{
	wander("target", 0) // Pushes the item in the default directions.
}
[ top ]

NAME: While-loop
FORMAT: while (condition) { code to run }

This command initiates a while loop. While-loops in RPGCode are much like while loops in C/C++. A while-loop is a group of commands that will be executed over and over again until a certain condition is false. The While command tests the condition just like the If and For commands test a condition. If the condition is true (for example, your condition is 'done! == 0', and 'done!' is in fact equal to 0, that is true), the block of code inside the while-loop's brackets will be executed. Once all of the commands are executed, the While command will check to see if the condition is still true. If so, it will loop through again. It keeps doing this until the condition is false.
- condition is the condition to test. If it's true, the block of code inside the brackets of the while command will be executed.
- code to run is the block of code to run while the condition is true.
// Example using a While-loop.
// Let's say we want this loop to run while
// done! is equal to 0.
done! = false
while (!done!)
{
	mwinCls()
	mwin("What do you want to do?")
	mwin("1 - Play the game")
	mwin("2 - Quite")
	a$ = wait()
	if (a$ == "1")
	{
		// The user chose to play the game
		mainFile("game.gam") // Start the game
		done! = true // Break out of the loop
	}
	if (a$ == "2")
	{
		windows()
		done! = true
		// Break out of the loop
	}
}
[ top ]

NAME: Win the game
FORMAT: win()

This command displays a "You won the game" message, waits for the user to press a key, and then resets the game to the startup program. You may want to create a more interesting sequence for winning the game, however, like credits or something of the sort. It adds a bit more class to your game. Once the sequence is complete, you can use the reset() command to reset the game to the startup program, or use the windows() command to quit to Windows.
win() // You won the game!
[ top ]

NAME: Quit to windows
FORMAT: windows()

This command ends execution of the currently running program and quits to Windows. Use this when you want to turn off the game through a program.
done! = false
while (!done!)
{
	mwinCls()
	mwin("What do you want to do?")
	mwin("1 - Play the game")
	mwin("2 - Quite")
	a$ = wait()
	if (a$ == "1")
	{
		// The user chose to play the game
		mainFile("game.gam") // Start the game
		done! = true // Break out of the loop
	}
	if (a$ == "2")
	{
		// This will quit the game and go back to windows.
windows() done! = true // Break out of the loop
} }
[ top ]

NAME: Change Message Window Color
FORMAT: winColorRGB(r!, g!, b!)

By default, the message window has a black background. You can change that by using this command.
- r!,g!,b! are the RGB color values to change the background color to.

mwin("Black background.")
wait()
mwinCls()
winColorRGB(0, 0, 255)
mwin("Blue background.")
wait()
[ top ]

NAME: Change Message Window Graphic
FORMAT: winGraphic(file$)

By default, the message window has no background image. You can put a background in the message window by using this command.
- file$ is the filename of the image to use.
mwin("Black background.")
wait()
mwinCls()
winGraphic("mwin.jpg")
mwin("Now we have a graphic!")
wait()
[ top ]

NAME: Wipe to new graphic
FORMAT: wipe(file$, effect![, speed!])

This command loads a new graphic and 'wipes' that graphic onto the screen.
- file$ is the filename of the image to wipe to.
- effect! is a numeric value between 1 and 12. The valid types are:
1 - Wipe right
2 - Wipe left
3 - Wipe down
4 - Wipe up
5 - Wipe NW to SE
6 - Wipe NE to SW
7 - Wipe SW to NE
8 - Wipe SE to NW
9 - Wipe right 'zelda' style
10 - Wipe left 'zelda' style
11 - Wipe down 'zelda' style
12 - Wipe up 'zelda' style
- speed! is an optional specifying how fast the screen wipes to the new image. The default is 1, but you can make it a higher number if you want it to go faster.
wipe("Menu.gif", 9, 1) // Wipe right Zelda style
[ top ]

NAME: With
FORMAT: With(handle$)

This command allows you to use methods from within a file without having to include the file directly, or use implicit includes. Instead, you specify which file to use methods from and access them by typing a period ('.') followed by the name of the method. You can also use this command for accessing member methods or variables in a class or structure, by using the '->' operator, followed by the method or variable name.
- handle$ is the name of the file, class, or structure to access.
with ("System")
{
	mwin("Just testing the With command!")
	.Pause()
}
[ top ]

NAME: Zoom in on the screen
FORMAT: zoom(percent!)

This command zooms in on the screen.
- percent! is the percent to zoom in.
// Zoom in on the screen.
for (z! = 0; z! < 4; z!++)
{
	zoom(5)
}
[ top ]

previous, forward