What is BQ? Go
here.The logic for all the objects in Balding's Quest is handled by
Lua, with a set of script functions written by yours truly. My goal is to have a system in place somewhere between programming and a game creation tool. I tried to use plain English for the script functions, and Lua's syntax is much more readable than proper code, so I think this should allow even the relatively inexperienced to create their own objects!
For now, I'll just post a list of all the script functions, divided into categories, with all their parameters and brief descriptions. If a parameter has a question mark next to it, it means it's optional. (In LUA, you can pass as many params as you want.) Get ready, there's lots:
G U I / G L O B A L G A M E S T U F F:exitGame()-- Exits the game
DEV_showNumber(Num)-- A dev testing function: displays a value at the center of the screen
openTextBox(X?, Y?, Title?)-- Opens the text entry box
closeTextBox()-- Closes the text entry box
clearTextBox()-- Clears the text entry box
getEnteredText()-- Retrieves what's currently entered in the text box
setEnteredText(Text)-- Sets what's entered in the text box
displayText(Text, X?, Y?, Alignment?)-- Displays text. There is only one display text per scripted object, and I think it's always aligned center (for now at least).
clearText()-- Clears the object's display text.
setTextColor(R, G, B)-- Sets the object's display text color.
F I L E S :findFile(File_name, File_type)-- Finds a file somewhere within the game's directory.
-- (Checks the map's root folder first, then the map /WhateverType, then the game's root folder /WhateverType. I think.)
-- Returns the full file path with file name
setLocalDirectory(Directory)-- I need to make this automatic, but this sets the root directory for the map (in case it's not in the Maps folder).
-- Useful for mods and such (check out the animation editor).
loadMap(Map_filename, Clear_data?, Fade_Type?, Fade_Time?, Load_delay?)-- Loads a map and allows you to choose whether or not to clear the existing map and set various transition effects.
saveMap(Map_filename)-- Saves the map file.
loadLastMap(Fade_Type?, Fade_Time?, Load_delay?)-- Loads the last map loaded.
loadAnimFile(Anim_file, Object_pointer?)-- Sets the object's animation file. You could also pass it a pointer to a different object.
saveAnimFile(Anim_filename)-- Saves an animation file.
getAnimName()-- Returns the object's animation file name.
getName()-- Returns the object's (script) name.
getMapName()-- Returns the current map's name.
getObjectName(Object_pointer)-- Returns a specific object's name.
O B J E C T S E T U P :setUpObject(
Animation file,
Top Height, Bottom Height,
Left Width, Right Width,
Direction,
Type,
State,
Heath,
Max Speed H,
Max Speed V,
Display Layer
)-- The big all-in-one setup function you see at the start of most scripts.
M A I N H A N D L E R F U N C T I O N S :handleDeath()-- Runs the DEATH_SEQUENCE main script function if the object's health hits 0 or below.
handleMaxSpeed(Maxspeed_H?, Maxspeed_V?)
handleMaxSpeedH(Maxspeed_H?)
handleMaxSpeedV(Maxspeed_V?)-- Caps the object's movement speed.
handleFriction(Amount?)
handleFrictionH(Amount?)
handleFrictionV(Amount?)-- Reduces the object's speed until it stops.
handleMovement()-- Moves the object based on its velocity, etc.
handleTileCollisions(Type?, Stop?)-- Handles colliding with obstructions. Generally, you don't want to pass any params to handler functions.
handleAttacks()-- Handles being hit by "Attack" objects.
handleObjectCollisions(Object_pointer, Type?, Stop?)-- Handles colliding with objects.
-- This should go in the OBJECTS_LOOP main script function, passing it the otherObj.
handleObjects()-- Runs the OBJECTS_LOOP main script function, which automatically loops through every object.
handleGravity(Amount?)-- Applies gravity. Don't pass it a param and it will apply the map's current gravity.
O B J E C T S :setFlag(Flag, True/False, Object?)-- Sets a given flag for the object on or off.
-- (Flags and much more are defined in the INCLUDE_Objects.lua script.)
getFlag(Flag, Object?)-- Returns the current state of a given flag.
setAllFlags(True/False)-- Sets all flags to a given value. Probably not needed.
getType(Object_pointer?)-- Returns the Type of an object.
setObjectFocus(Object_pointer)-- Lets you switch focus between the current script and other objects (provided you have a pointer, which the OBJECTS_LOOP can give you).
-- Very useful for advanced manipulation of other objects.
createObject(Object_name, X, Y)-- Creates an object. (Using the script name, without extension.)
destroyObject(Object_pointer?)-- Deletes the object, or another object.
queueChild(Object_name, X, Y)-- Creates a queued up child object. Returns a unique ID for it.
-- NOTE: This stuff might not work anymore.
spawnChild(Child_ID, X, Y)-- Like create object. May not work anymore.
setSwitch(Switch_number, True/False)-- Sets a map switch value on or off.
-- Useful for levers & doors, etc.
-- There are only 0-9 switches right now, I think.
getSwitch(Switch_number)-- Returns true or false for the given switch.
skipObject()-- Skips the rest of the logic for the current object.
-- Useful for "hiding" objects, disappearing/reappearing, whatever.
getStartValue()-- Returns the Start Value set by the map editor.
-- Used in child scripts.
A T T A C K S : collideAttack(Attack_pointer)-- For the ATTACKS_LOOP main script function. (Use thisAttack.)
-- Returns true/false for a collision, allows you to do special, specific stuff with Attacks.
spawnAttack(X, Y, Damage?, Direction?, Type?, Life?, Animation_file?, End_animation?)-- Spawns an attack object. Used for attacks (duh), but also other object-to-object interactions.
setAttackPhysics(Top_height, Bottom_Height, Left_Width, Right_Width, X_Acceleration?, Y_Acceleration?, X_Initial_Force?, Y_Initial_Force?, Gravity_amount?, Maxspeed_H?, Maxspeed_V?, Collisions_on?)-- Sets the specs for the last created attack.
-- Nearly always called right after spawnAttack().
getRange(Start_X, Start_Y, Direction, Tile_type?)-- Unless you pass a Type param, this finds the range (in pixels) from the point to an obstruction in the given direction.
-- The monocle beam and electric traps are an example of this.
-- I think it up and left will return a negative value. I could change this if it bothers anyone.
P A R T I C L E S / E F F E C T S :
loadEffect(Animation_name)-- Load your effects once at the beginning of the script.
-- Pass the animation filename (without extension) and it returns a pointer to this effect for future use.
spawnEffect(Effect_pointer, X, Y, X_Velocity?, Y_Velocity?, Life?, Collisions_on?)-- Spawns an effect based on the effect pointer.
-- I may consolidate this with the attack objects so there are more physics options.
-- The particle plays until the animation is over or its Life expires (if Life is passed).
rotateEffect(Rotation, Flip_H, Flip_V)-- Rotates and flips the last spawned effect. Useful for getting more variety out of a single animation.
flashScreen(R, G, B, Time)-- Flashes the screen once with a given color for the length of Time.
I N P U T :keyPress(Key_code)-- Returns if a key is being pressed or not.
-- (Look in INCLUDE_Objects to find the list of key codes.)
-- I'll add key configuration eventually.
mouseClickL()
mouseClickR()-- Returns if the mouse has been clicked.
mousePosX()
mousePosY()-- Returns the position of the mouse cursor.
mouseIsOver()-- Returns true if the mouse cursor is over the object (based on the object's collision box, natch).
isClickedL()
isClickedR()-- Returns if the object is clicked by the mouse cursor.
P H Y S I C S :clearMovement()-- Clears the object's physics values.
setMaxSpeedH(Maxspeed_H)
setMaxSpeedV(Maxspeed_H)-- Sets the horizontal and vertical max speeds used by the handleMaxSpeed functions.
getMaxSpeedH()
getMaxSpeedV()-- Returns the current Horizontal and Vertical max speeds.
addVelX(Amount)
addVelY(Amount)
setVelX(Amount)
setVelY(Amount)-- Adds or sets the object's X or Y velocity.
-- You should typically only use Acceleration to manipulate objects.
getVelX()
getVelY() -- Returns the object's current X or Y velocity.
addAccelX(Amount)
addAccelY(Amount)
setAccelX(Amount)
setAccelY(Amount)-- Adds or sets the object's X or Y acceleration.
-- You should typically only use Acceleration to manipulate objects.
getAccelX()
getAccelY() -- Returns the object's current X or Y acceleration.
P O S I T I O N :
addPosX(Amount)
addPosY(Amount)
setPos(X?, Y?)
setPosX(X)
setPosY(Y) -- Adds to or sets the object's X or Y position.
getPos()-- Returns the object's X and Y position.
getPosX()
getPosY()-- Returns the object's X or Y position.
getDir()-- Returns the object's direction.
setDir()-- Sets the object's direction.
C O L L I S I O N S :setCollisionBox(Top_height, Bottom_height, Left_width, Right_width)-- Sets the collision box for the object, with its X,Y position at its center.
getTopH()
getBottomH()
getLeftW()
getRightW() -- Returns the dimensions of the object's collision box.
-- (Top height, bottom height, left width, or right width.)
setTopH(Top_height)
setBottomH(Bottom_height)
setLeftW(Left_Width)
setRightW(Right_Width)-- Sets the dimensions of the object's collision box.
collide(Direction)-- Returns true or false for a collision in a given direction.
-- NOTE: This DOES NOT test for a collision. It just returns if the object has collided within the last loop.
-- That means it should be called after handleTileCollisions and collideObject (in the OBJECTS_LOOP main function).
setCollisionFlag(Direction, True/False)-- Forces a collision flag for the object in a given direction on or off.
-- This should be avoided unless being used in a very special case.
collideTile(Direction, Stop?, Type?, X_shift?, Y_shift?)-- Returns true if the object collides with a specific tile (platform Type by default) in a given direction.
-- You can also shift the collision box temporarily for the test.
collideObject(Direction, Object_pointer, Stop?, Type?, X_shift?, Y_shift?)-- Like collideTile, but tests against the object pointed to.
collideLedge(Direction, Type?)-- My one HACK function, to test for ledges. I'm not sure if I even use this anymore...
-- I'll leave it here for posterity.
T I L E S :getTileType(X, Y, In_pixels?)
setTileType(X, Y, Type, In_pixels?) -- Gets and sets the tile Type of a tile in the map array.
-- (Test for Water, Ladder, Platform, etc.)
getTileGfx(X, Y, In_pixels?)
setTileGfx(X, Y, Tile_graphics_number, In_pixels?)-- Gets and sets the 8x8 tile graphics number (based on the tilesheet) of the current tile in the map array.
getTileBG(X, Y, In_pixels?)
setTileBG(X, Y, True/False, In_pixels?)-- Gets and sets the layer of a tile in the map array (background or foreground).
getTileRot(X, Y, In_pixels?)
setTileRot(X, Y, Rotation, In_pixels?)-- Gets and sets the rotation of a tile in the map array.
S T A T E M A C H I N E :setState(State)-- Sets the object's State.
-- (This will run the main script function EXIT_STATE on the current state then ENTER_STATE on the new state automatically.)
getState()-- Returns the current State of the object.
S O U N D S :
loadSound(Sound_filename)-- Like Effects, load the sound once at the beginning of the script and use the returned pointer to play it.
playSound(Sound_pointer, Volume?) -- Plays the passed sound. Volume is iffy until I upgrade the audio library.
getMusicTime() -- Get the position of the currently played background music (in MS, I think).
A N I M A T I O N S :playAnim(Animation_number?, Force?)
pauseAnim(True/False?)
stopAnim()-- Plays, Pauses, or Stops the animation.
getAnim()
setAnim(Animation_number)-- Gets or sets the current animation.
getFrame()
setFrame(Frame_number) -- Gets or sets the current frame.
getFrameLength(Frame?)-- Gets the length of the current (or a specific) frame in the current animation.
setFrameLength(Frame, Length)-- Sets the length of specific frame in the current animation.
getAnimCounter()
setAnimCounter(Time)-- Gets and sets the counter for the object's animations.
getNumberOfFrames()
getNumberOfAnimations()-- Returns the number of Frames/Animations in the object's animation file.
getFlipH()
setFlipH(True/False)-- Gets and sets the object's horizontal flip.
flipH()-- Flips the object horizontally.
getFlipV()
setFlipV(True/False)-- Gets and sets the object's vertical flip.
flipV()-- Flips the object vertically.
getRot(Rotation)
setRot(Rotation)-- Gets and sets the object's rotation.
rotL()
rotR()-- Rotates the object Left or Right.
getAnimOffsetX()
setAnimOffsetX(Offset_X)-- Gets and sets the object's animation x offset.
getAnimOffsetY()
setAnimOffsetY(Offset_Y)-- Gets and sets the object's animation y offset.
H E A L T H :getHP(Object_pointer?)
setHP(Object_pointer?)
addHP(Object_pointer?)-- Returns, sets, or adds to the HP of the object (or another object).