Object Functions

Richard Kettering edited this page Jun 20, 2016 · 55 revisions
Clone this wiki locally

This page contains a semi-ordered list of most defined function calls you can find in Frogatto. Some of these are engine, some are defined in functions.cfg (or the frogatto module's functions-custom.cfg), and I expect some might be defined in a common prototype. To use this page, just search for the function you want. To find out which function you want, drop by the forums or IRC and ask us.

  • tbs_client(host, port, session=-1) : creates a client object to the tbs server
  • tbs_process(tbs_client) : processes events for the tbs client
  • tbs_send(tbs_client, msg) : sends a message through the given tbs_client connection

Functions in libraries are accessible via lib.library name.function name(). These are listed separately of the above functions, since they're not in the global namespace. Future globally-accessible functions should prefer libraries, since they don't pollute the global namespace like functions.cfg-based functions do. Libraries also have much better static typing support.


Note: This library is disabled by default.

  • xywh(x,y,w,h) : Returns a command to draw a debug rect on screen, enclosing the rectangle as defined by start x, start y, rectangle width, rectangle height.
  • xywh(list) : See above. Same args, but this time contained in a list [x,y,w,h].
  • xyxy(x1, y1, x2, y2) : Returns a command to draw a debug rect on screen, enclosing the rectangle as defined by the points x1/y1 and x2/y2.
  • xyxy(list) : See above. Same args, but this time contained in a list [x1,y1,x2,y2].


  • interpolate(thing, percent, thing) -> Given two compatible things, calculate the thing percent of the way from thing 1 to thing 2. Number-number and list-list combinations return numbers and lists. If both elements have a mid_x and mid_y value, then a map containing an interpolated mid_x and mid_y will be returned. A list containing an x/y value may be substituted for an object with {mid_x, mid_y}. In the case that a list is used, the returned object will contain a 0 and a 1 field, and so can be used in many situations where a list would otherwise be called for.
  • floor(number) -> Returns the number passed it without the decimal part.
  • ceil(number) -> Returns the next whole number which is larger than or equal to the number passed in.
  • tenth(number) -> Gives the decimal place, ie, anything less than or including the tenths place.
  • constrain(number u, number v, number w) -> Returns n, where n is as close to v as possible given that u < n < w. If u > w, then v will be half-way between both.
  • loop(number[, max=360]) -> Returns the number passed in, looped to be between 0, the number, and the max. Somewhat useful for circle calculations. For example: map([-90,0,90,270,450], lib.math.loop(value))[270, 0, 90, 270, 90].
  • in_range(min, var, max) -> Returns true if min <= var <= max. A convenient shortcut. Kin to constrain.
  • round(number) -> Rounds to the nearest whole number. For example, 2.5 rounds to 3 and -2.5 rounds to -3.
  • sin_in(percent) -> Given a percentage, uses a sine-based formula to weight the midpoint towards 1.0 (100%). This looks like acceleration as the arg approaches 1.0.
  • sin_in_out(percent) -> Applies both sin_in and sin_out to the decimal passed in. As with all easing functions, acceptable input ranges between 0.0 and 1.0.
  • sin_out(percent) -> Given a percentage, uses a sine-based formula to weight the midpoint towards 0.0 (0%). This looks like deceleration as the arg approaches 1.0.
  • default(maybe-a-decimal, decimal) -> Takes an arg that might be a decimal or might be null, and an arg that is a decimal. Returns the first arg if it is a decimal, or the second arg if the first arg is not a decimal. Good for when you may be dealing with an undefined value, such as a default that is often left blank. See the non-lib default() for a solution for objects and other such things that are always true if they're defined at all.
  • bezier_curve([​[points]] points, decimal percent) -> Returns a point percent way along the bezier curve with control points as listen in points. (Points is a list of [x,y]s.) Note that this list defines only one bezier curve, so each point you append to the list makes all previous points matter less. This is unlike a bezier curve in something like Inkscape (a vector graphics program), which chains together bezier curves with a length of 3. (Perhaps someday.)


  • toPoints(list points) : Takes a list of points in any common format. (object, map, or [x,y]). Returns a list of [x,y]-type points.
  • toPoint(point) : Takes a point in any common format (see toPoints()). Returns a point in [x,y] format.
  • camera(level) : Given the current level, returns the focus-point of the camera. This is usually the middle of the screen in level coordinates.
  • decimal(any) : Returns the decimal value of anything. Could perhaps be substituted by something like boolToDecimal(), but that seems a bit pedantic.
  • int(any) : Returns the integer value of anything.