Fandom

Doom Wiki

FraggleScript functions

3,484pages on
this wiki
Add New Page
Talk3 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

This is a comprehensive list of FraggleScript functions:

System variables

These are functions rather than variables, but are always available to the player:

consoleplayer 
The player on the console, ie. in a network game, the player on this machine.
displayplayer
fov 
The current field of view size
trigger 
The object which triggered the current script to start
script 82 {
    // kill the object which started this script
    kill(trigger);
} 

Control functions

break 
Exit a loop, eg.
while (1) {
  break();
}
continue 
Move to the next iteration in a loop
while (1) {
  continue();
  print("this message is never displayed");
}
return 
Stop the current script
script 1 {
   return();
   print("this message is never displayed");
}
goto 
Jump to a particular label
script 1 {
   goto(my_label);
   print("this message is never reached");
   my_label:
}
include 
Execute the contents of the lump specified (acts like "#include" in C)
// include the contents of the wad lump named 'things.h'

include("things.h");   

Basic language functions

print 
Print a message to the console
print("hello, world");
rnd 
Returns a random number from 0..255
script 1 {
    int my_number = rnd();
    if (my_number % 2 == 0) {
        print("heads");
    } else {
        print("tails");
    }
}
prnd (legacy extension)
Returns a random integer from 0..255 (using the doom random table)
input 
(non-functional) read a line from the keyboard
beep 
Make a sound
clock 
Returns the level time, in 1/100ths of a second
wait 
Causes the current script to delay further execution for time number of clocks (1 clock = 1/100 of a second)
tagwait 
Causes the current script to delay further execution until all activity associated with the tag number passed to it has stopped
scriptwait 
Causes the current script to delay further execution until all instances of the script with number scriptnum have finished execution
startscript 
Causes script to run at the start of a level
scriptrunning 
Returns a non-zero result if any instances of the script with scriptnum are currently waiting, and zero otherwise
startskill 
Starts a new game on a skill level from 1 to 5
exitlevel
Exit the level
tip 
Display a message to the player (in the centre of the screen)
timedtip (legacy extension)
Prints a centered message to all players, which lasts clocks/100 number of seconds

Messages

message
Display a message to the player
playermsg
Send a message to a particular player
playermsg(2, "Hello, player 2");
playertip
Send a tip to a particular player (centre-of-screen message)
playertip(2, "Dont go this way, player 2!");
playeringame
Returns 1 if the given player is in the game
if (playeringame(2)) {
    print("player 2 is in the game!");
}
gameskill (legacy extension)
Returns a value from 1 to 5 representing the skill level of the current game
gamemode (legacy extension)
Returns an integer value representing the current mode of gameplay

Player information and control

playername
Returns the name of a given player
playerobj
Returns a reference to the object controlled by a player
playeraddfrag (legacy extension)
With one argument 1 frag will be added to that player's frag count. If passed two arguments, 1 frag will be added to the first player's frag count against the second player specified (for tally screen). If both players are the same number, a frag will be subtracted from that player's frag count (suicide)
isplayerobj (legacy extension)
Returns 1 if the trigger object or specified object is a player avatar, and 0 otherwise
skincolor (legacy extension)
Returns the number corresponding to a player's colour, or can be used to set colour
playerkeys (legacy extension)
If passed a player number (0-31) and a key number (0-5), this function will return 1 if the player possesses that key or 0 if he does not. If additionally passed the givetake parameter, it will give the key to the player if givetake is non-zero, or will take the key away from the player if givetake is zero. In this case, the function always returns zero regardless
playerammo (legacy extension)
If passed a player number (0-31) and an ammo type number (0-5), this function will return the amount of that type of ammo the player has. If additionally passed the amount parameter, it will set the player's ammo of that type to this amount, clipping it into the range of zero to the maximum amount the player can carry for that type
maxplayerammo (legacy extension)
Sets a player's maximum ammo
playerweapon (legacy extension)
If passed a player number and weapon type number, this function will return 1 if that player has that weapon, 0 if he does not. If additionally passed the givetake parameter, it will set the player's possession of that weapon. 0 will take the weapon away, while any non-zero number will give it to the player

Objects

spawn 
Spawns a new mapthing with various parameters
kill 
Passed nothing, this function kills the thing that triggered the current script. Passed a mapthing number or mobj reference, this function will kill the mapthing to which it refers
removeobj 
Passed a mapthing number or mobj reference, this function will remove the mapthing to which it refers
objx
Returns the X coordinate of an object
objy
Returns the Y coordinate of an object
objz
Returns the Z coordinate of an object
teleport 
Passed one parameter, this function attempts to teleport the trigger object to a teleport destination in the sector with tag number sectortag. Passed a mapthing number or a mobj reference, this function attempts to teleport the specified mapthing. This function automatically spawns fog objects and plays sounds in the appropriate locations
silentteleport 
This function works identically to teleport() except that no fog is spawned and no sounds are played
damageobj 
Passed one parameter, this function attempts to do damage in the specified amount to the trigger object. Passed a mapthing number or mobj reference, this function attempts to do damage to the specified object
player
If the object is a player, returns the number of the player
objsector 
Passed nothing, this function returns the tag number of the sector which the trigger object is currently in. Passed a mapthing number or mobj reference, this function attempts to do likewise for the specified object
objflag
If passed only one argument, this function will return 1 if the specified flag is set for the trigger object, and 0 otherwise. Passed all 3 arguments it will set or clear a flag for the specified object
pushobj
objangle 
Passed nothing, this function returns the high-precision angle of the trigger object. Passed a mapthing number or mobj reference, this function does likewise for the specified mapthing. Passed a mapthing number or mobj reference and an angle the specified mapthing's angle will change
objhealth 
Passed nothing, this function returns the current health value of the trigger object. Passed an integer or mobj reference, this function does likewise for the specified mapthing
spawnexplosion (legacy extension)
Spawns a projectile and immediately changes it to the death state so it creates an explosion
radiusattack (legacy extension)
Creates a silent, invisible radius attack at the location of mobj spot. Mobj source defines the creator of the attack (for message purposes). The damage in the center of the attack is defined by int damage. The size of the radius depends on the amount of damage passed to the function
testlocation (legacy extension)
Passed nothing, this function returns if the trigger object is clear of any wall or other objects. Passed a mapthing number or mobj reference, this function does likewise for the specified mapthing
pushthing (legacy extension)
Given a mapthing number or mobj reference, this function pushes the specified thing along a line from its location in the direction of angle for a distance and speed affected by the force applied and its mass. External forces such as friction, wind, or explosions are vector-additive and will still affect the object while it is moving
objdead (legacy extension)
objreactiontime (legacy extension)
reactiontime (legacy extension)
Passed one value, a mapthing number or mobj reference, this function will return the specified object's reaction time, or the amount of time it must sit without being able to move. Given the val parameter, it will first set the object's reaction time to the specified value, and then return this new value
objtarget (legacy extension)
Passed one value, a mapthing number or mobj reference, this function will return a reference to that object's current target, which for enemies is the last thing to hurt them and get their attention. If the second parameter is passed, which may also be either a mapthing number or mobj reference, the target will be set to this object
objmomx (legacy extension)
This function either returns or sets the x momentum of the specified object
objmomy (legacy extension)
This function either returns or sets the y momentum of the specified object
objmomz (legacy extension)
This function either returns or sets the z momentum of the specified object
spawnmissile (legacy extension)
This function can be used to cause one object to fire a projectile at another object. The source and target parameters may be either integer mapthing numbers or mobj references
mapthings (legacy extension)
Returns the number of mapthings in a level. This does not include projectiles, dropped weapons, or FS spawned entities
objtype (legacy extension)
Returns the type of an object in the form of an integer. When nothing is passed the type of the trigger will be returned. When passed a map object or mapthing number it will return the type of that object
mapthingnumexist (legacy extension)
This will test a mapthing number to see if it exists. It will return 1 for an existing mapthing number or 0 for a non-existing mapthing number

Sector control

floorheight 
Passed one parameter, this function returns the current floor height of the first sector with tag number tagnum. Given two parameters, it first instantly sets the floor height of all sectors with this tag and then returns the new height
floortext
floortexture (legacy extension)
Passed one parameter, this function returns the current flat displayed on the floor of the first sector with tag number tagnum. Given two parameters, it will set the flats of all tagged floors to flatname, and then return the new flat name
movefloor 
Passed two parameters, this function gradually moves all sectors' floors tagged tagnum to destheight at the default floor movement speed. If given the speed parameter, the speed of the floors will be as specified multiplied by the basic floor movement factor
ceilheight
ceilingheight (legacy extension)
Passed one parameter, this function returns the current ceiling height of the first sector with tag number tagnum. Given two parameters, it first instantly sets the ceiling height of all sectors with this tag and then returns the new height
moveceil
moveceiling (legacy extension)
Passed two parameters, this function gradually moves all sectors' ceilings tagged tagnum to destheight at the default ceiling movement speed. If given the speed parameter, the speed of the ceilings will be as specified multiplied by the basic ceiling movement factor
ceiltext
ceilingtexture (legacy extension)
Passed one parameter, this function returns the current flat displayed on the ceiling of the first sector with tag number tagnum. Given two parameters, it will set the flats of all tagged ceilings to flatname, and then return the new flat name
lightlevel 
Passed one parameter, this function returns the current light level of the first sector with tag number tagnum. Given two parameters, it first instantly sets the light level of all sectors with this tag and then returns the new level
fadelight 
Passed two parameters, this function gradually changes the light level of all sectors tagged tagnum to destlevel at the default light fade speed. If given the speed parameter, the speed of the fade will be as specified multiplied by the basic light fade factor
colormap 
Passed one parameter, this function returns the current colormap of the first sector with tag number tagnum. Given two parameters, it first sets the colormap of all sectors with this tag and then returns the name of the new colormap. If the colormap specified does not exist between C_START and C_END in a currently loaded wad, an error will occur and the game will exit

Cameras

setcamera 
This function instantiates a camera viewpoint at the object specified by either a mapthing number or an mobj reference with the given optional parameters. Pitch may be a value between -50 and 50, with 0 being straight ahead
clearcamera 
This function turns off any currently active cameras and returns the viewpoint to the console player
movecamera (legacy extension)
This function is used to move a camera object toward the target object and to targetheight z coordinate at 'movespeed' speed, while independently turning it to face targetangle from its current angle, turning at 'anglespeed' speed.This function returns the integer value 1 if the camera moved, and 0 if it did not. This function is best used in a loop that tests its return value, calling it repeatedly until it returns 0, and then waiting for the next gametic. This could be accomplished as in the following example:
script 0
   {
      while(movecamera(cameranodes.elementAt(0), 40.0, 5.0, 0.0, 0.0))
      {
         wait(1);
      }
   }

This example would move the camera toward the first camera node on the map at 5 units per tic, with zero change in angle. Notice that the camera's linear and angular movements are independent, and that either may be zero if only one type of movement is desired.

Math functions

pointtoangle 
This function returns the high-precision angle between the two points (x1, y1) and (x2, y2) relative to the coordinate axes
pointtodist 
This function returns the high-precision distance between the two points (x1, y1) and (x2, y2)
max (legacy extension)
Returns the maximum of two fixed-precision numbers
min (legacy extension)
Returns the minimum of two fixed-precision numbers
abs (legacy extension)
Returns the absolute value of a fixed-precision number
sin (legacy extension)
Returns the sinus, in radiant, of a fixed-precision angle
asin (legacy extension)
Returns the arc sinus, in radiant, of a fixed-precision angle
cos (legacy extension)
Returns the cosinus, in radiant, of a fixed-precision angle
acos (legacy extension)
Returns the arc cosinus, in radiant, of a fixed-precision angle
tan (legacy extension)
Returns the tangent, in radiant, of a fixed-precision angle
atan (legacy extension)
Returns the arc tangent, in radiant, of a fixed-precision angle
exp (legacy extension)
Returns the exponential of a fixed-precision number
log (legacy extension)
Returns the logarithm of a fixed-precision number
sqrt (legacy extension)
Returns the square root of a fixed-precision number
floor (legacy extension)
Returns the floor of a fixed-precision number
pow (legacy extension)
Returns the power of a fixed-precision number by another fixed-precision number

Sound effects

startsound 
This function plays a sound from lump "soundname" at the location of the mapthing specified. soundname can be any sound whether normally in the game or not (new sounds will be hashed in dynamically), but the sound lump must exist and must start with "DS"
startsectorsound 
This function plays a sound from lump "soundname" at the sound origin of the first sector with tag number tagnum. soundname can be any sound whether normally in the game or not (new sounds will be hashed in dynamically), but the sound lump must exist and must start with "DS"
stopsound (legacy extension)
This functions stops any sound playing at the specified origin mobj
stopsectorsound (legacy extension)
This functions stops any sound playing at all sectors that have the specified tag
changemusic 
This function changes the currently playing music to the music lump "musname." As with sounds, this may be a new lump, but it must exist and must start with "D_". Passing the string "-" to this function will cause the music to stop without any new song starting
ambientsound (legacy extension)
This function plays a sound from lump "soundname" at full-volume on the global sound channel. This is suitable for global ambience that needs no general source. soundname can be any sound whether normally in the game or not (new sounds will be hashed in dynamically), but the sound must exist and must start with "DS"

Hubs

changehublevel

Doors

opendoor 
This function opens all sectors tagged tagnum like doors. If no waittime or speed are specified, the door will open at normal speed and will not close on its own. If waittime is specified, the door will wait that number of clocks (100 clocks per second). If waittime is present but is 0, the door will not close on its own. speed may be set to alter the opening and closing speed of the door
closedoor 
Similar to opendoor(), this function closes all sectors tagged tagnum like doors

Heads-up GUI

newhupic (legacy extension)
createpic (legacy extension)
Creates a new heads-up pic using the lump 'lumpname', which must be a standard Doom-format screen graphic, at unscaled screen coordinates (x, y), which may range from 0 to 319 and from 0 to 199 respectively. If draw is non-zero, the pic will be drawn to the screen, and if trans is non-zero, the pic will be drawn translucent. Priority determines how the pic will draw in relation to any other existing heads-up pics spawned by FraggleScript -- it will draw over any pics with a lower priority number, and under any pics with a higher priority number. Note that FraggleScript heads-up pics always have lower priority than any native heads-up graphics, such as the player HUD.

Heads-up pics are valid for the duration of the level in which they were created, and will be saved in savegames. This function returns an integer value which can be used as a handle to track and later manipulate this particular heads-up pic. You should always capture the handle unless you never intend to change or hide the pic after creating it. There is not currently any method for creating different heads-up pics on a particular player's screen

deletehupic (legacy extension)
modifyhupic (legacy extension)
Modifies attributes of the FS heads-up pic with this handle. lumpname must be set, but it can be set to its current value if it is not desired to change it. x or y can be optionally changed as well, and x may be set to -1 if no change in x coordinate is desired
modifypic (legacy extension)
sethupicdisplay (legacy extension)
setpicvisible (legacy extension)
Modifies the visibility of the FS heads-up pic with this handle. Set visible to a non-zero value to have the pic drawn, and set it to zero to hide it

Miscellaneous

runcommand 
Executes a console command
script 10 {
    // quit the game

    runcommand("quit");
}
linetrigger
Activates a particular Doom line trigger
playdemo (legacy extension)
Plays the specified demo if the lumpname exists
checkcvar (legacy extension)
Returns the value of a console variable
setlinetexture (legacy extension)
Used to set texture for linedefs with a specified tagnum
lineflag (legacy extension)
This function retrieves or sets flags for a line. If passed two parameters, this function will return 1 if the specified flag is set for the line, and 0 otherwise. Passed all 3 arguments it will set or clear a flag for the specified line. A list of line flags can be found in things.h. Note that line numbers are as they are in the editor, and not tags. Also, 1-sided lines will always block clipped objects even if the blocking flag is cleared
setcorona (legacy extension)
This function can change the dynamic light/corona settings of a sprite which has a dynamic light/corona setting attached to it
setfade (legacy extension)
Set the screen's color to the one specified with the red, green and blue attributes. The alpha value determines the translucency of the color. All values are in the range of 0 to 255

Also on Fandom

Random Wiki