Site hosted by Angelfire.com: Build your free website today!
Previous Page
Next Page
Table of Contents


Function Reference

Math Functions sin cos atan2 rand
Display Functions camcolor turnrand turnru flipru
Move Functions ongrid centered
pipedir tilequery
fromdir todir curvetype
Targeting Functions place target taglink
Input Functions inpx inpy inps
Sound Functions sound ambsound

Functions

FunctionTypeDescription
long sin (char dir)
long cos (char dir)
math Trigonometric functions return what would normally be expected of them. Cosine works with the 256-angle measurements as it should. Sine is similar, but all values reflect the y-axis as being inverted. In other words, calls to these two functions with counter-clockwise-based angles will yield the same vector direction as expected from a normal mathematical set of axes, but the values returned by sine are as if the call was -sin(x) rather than sin(x).
char atan2 (int x, int y) math Returns the angle from the rectangular vector. A full range of 256 angles can be returned, as values of x and y can be either positive or negative. Due to limitations (cheapness) in the design, angles will lose accuracy when a vector encompasses a long distance. For cartesian directions, however, there is no loss of precision, no matter how long the vector is.
int rand (int n) math Returns a random integer between 0 to n - 1. The seed is determined by the timer, so the sequence changes from level to level, and from game to game. The seed is always saved when a demonstration is recorded; all "random" numbers will be random in the exact same order when running a previously saved demo.
char camcolor display Returns the background color of the tile underneath the object's x and y coordinates. This value is placed in an object's "pal" variable to represent a solid-color sprite.
int turnrand (int sprite) display Returns a sprite with applied random horizontal and vertical orientations. The like the rand function, the random seed for this function is different for every new level, but the same for each repeated demo.
int turnru (int spriter, int spriteu, char dir)
int flipru (int spriter, int spriteu, char dir)
display Returns a sprite with applied horizontal and vertical orientations as determined by the direction provided. Ninety-degree rotation of sprites is not implemented in Nibbler, so two sprites, one facing right and one facing up, must be provided. The flip flags of the resultant sprite are set to make the sprite look like it is facing in a particular cartesian direction. See the diagram for details.
char ongrid move This returns zero if any part of the current object's sprite is outside the visible coordinate space of (0, 0) to (xsize * 16 - 1, ysize * 16 - 1). After a call to the "getongrid" command, this function will return nonzero.
char centered move This returns nonzero if the integer parts of the x and y coordinates of the system are located at the center of a grid square. After a call to the "tilelock" command, an object will return nonzero; otherwise, zero is returned. NIB-OOL considers the center of a tile to be (+8, +8) from the upper left-hand corner of the grid square.
char pipedir (int pipeid, char sourcedir) move Use the pipedir function to establish the destination direction of a pipe. When a pipe location is established at the start of the level, only a pipe identification number (0 to 5) is placed in dispoff[][]. With this number and the source direction, one can easily determine the destination direction.
char tilequery <Coordpair>, char relheight move This function performs quite a few simple tasks. The only reason it appears in this language at all is that I had to optimize the code to a reasonable size by hard-coding common and simple analysis tasks. More or less, a "tile query" is a complex analysis of a particular grid square at the location in Coordpair. The results from this function are affected by relheight in the sense that the object calling the function must interpret squares differently depending on how "high" they should be. A value of zero for relheight will cause all low walls to be treated as impassible walls, but a value greater than zero will cause these walls to act as floors.

The following global variables are updated by tilequery:
canpass: 1 if passable. This same value is also returned by the function.
lowwall: 1 if a low wall. The square might be passable.
breakable: 1 if breakable.
validdir1, validdir2: For pipes and ramps, these values equal possible destination directions.
specdir: 1 if the square has a restrictive source and destination (i.e. a pipe or ramp).
occtype: 1 if a pipe; an object type otherwise. Only objects that "hog" a square will have this value set to the appropriate type. Such objects include ramps, springs, stationary fruit, stationary movable bricks, etc.
booster: 1 if an object can scale (go from floor height to "low wall" height).
slippery: 1 if the floor is greased.
hazard: 1 if there is a long electrical arc hogging the square.
bigoccupied: 1 if a large, hard-to-remove object hogs the square (e.g. masher body, snake body, etc).
smalloccupied: 1 if a small, easily removed object hogs the square (e.g. lizard, fruit).
movable: 1 if the object can be "pushed" to another square without significant chance of self-immolation.
firable: 1 if the object can be "fired" if touched (good chance of self-immolation).
canflatten: 1 if the object can be flattened by touch.
edible: 1 if the object can be eaten by a snake.
projectile: 1 if the object is a projectile, whether or not it has already been fired.
canswim: 1 if the object can swim in water.
char fromdir (char curve_type)
char todir (char curve_type)
move These two functions get direction information about a curve type. Of the twenty possible curves, at least one valid "origin" or "destination" direction will exist. The 2-D curves have both an origin and a destination direction. The 3-D curves have only one type: either origin only (dive), or destination only (emerge). If either fromdir or todir cannot gather a valid direction from the curve type, a value of 1 is the direction returned. The four cartesian directions indicate a successful evaluation.
char curvetype (char orgdir, char destdir) move The inverse of the functions above. This creates a curve type from the supplied origin and destination directions. A value of 1 in a direction directs the function to treat the curve type as a dive or emergence. The function will not return anything meaningful if the origin and destination directions are the same.
int place <Coordpair>, <Objname> [, <localvar1> = <initval1>, <localvar2> = <initval2>...] target Creates an object at the specified location. The new object will execute its first frame turn during the current frame. The optional initial values that can be assigned to the new object can follow in any number. These initial values will, in nearly all cases, override those values defined as defaults in the script header of that object. One should recall that the local variables have the scope of the new object, not the current object. (This function is exactly like the place command except that a pointer to the new object is returned.)
int target <Coordpair1>, <Coordpair2>, (<conditional expression>)
int target standard, (<conditional expression>)
target Returns a pointer to an object whose sprite falls completely or partially within the rectangular "box" specified by the corners Coordpair1 and Coordpair2. If "standard" is used instead of two coordinate pairs, a box ranging from (-8, -8) to (+7, +7) is used, which is the standard size of a grid square adjusted for the center placement protocol. The conditional expression mandates a screening test for targeted objects--only the objects that make the conditional expression true are targeted. The global pointer "targobj" is used to reference the potential target in this conditional expression.

On success, the target function returns the pointer. On failure (no object is found meeting the criteria), the function returns null. It is important to note that this function works on a "find-first-find-next" basis. In other words, successive calls to the same target function expression on the same frame turn return different pointers, cycling through more and more objects that meet the criteria provided until no more are left or the object script is satisfied with the current target.
int taglink target Returns a pointer to the object that has the same initialized tag as the current object. If no object is found with the same tag, the function returns null. If an object is found, subsequent calls to this function from the same object return more pointers to objects with the same tags, cycling through them until there are no more left. This function is only to be used during the first frame startup, when objects with dependencies "look" for each other.
char inpx (char inpnum)
char inpy (char inpnum)
char inps (char inpnum)
input User input is interpreted using three functions: the horizontal polling position, the vertical polling position, and the fire button up/down status. Inpx returns a left direction, right direction, or 1 (neutral x input). Inpy returns an up direction, a down direction, or 1 (neutral y input). Inps returns 1 if the fire button (usually the space bar) is depressed and 0 if it is not.

The input number passed to the function determines the input channel to read from. These numbers should be assigned at the start of a level. Player #1 should have the input number 0, player #2 should have the number 1, etc.
int sound (int num)
int ambsound (int num)
sound To play a sound that is rooted in the physical position of the object that generated it, two functions are provided. The first syntax (sound) plays a sound once; the second syntax (ambsound) plays a sound indefinitely. Once this sound has begun playing, the function returns a handle that an object can use to stop the sound.


Back to top



Previous Page
Next Page
Table of Contents
Back to Title Page