Flux library
Part of Flow
Core helpers of the Flux gamemode package on the global Flux table.
They cover console output (Flux.print, Flux.dev_print), the registry of player
actions (Flux.register_action), the loaded schema (its folder, name, information and
inclusion) and the global UI offset that HUD elements follow on the client.
The same file replaces file.Write with a version that creates missing folders.
Summary
Functions
Functions
Internal
This function is internal. It is not part of the public API and may change without notice.
Sets the offset returned by Flux.global_ui_offset.
Parameters
- x Number
- y Number
Prints a debug message to the console, but only in development or when the debug_output_in_production setting is enabled.
Parameters
- message String
Draws one frame of a registered position animation: calls the callback with the current position, then eases the position toward the target. Raises an error if the animation has not been registered.
Flux.register_animation(anim_id, box_x - max_width, nil, FrameTime() * 8)
Flux.draw_animation(anim_id, box_x, box_y, function(x, y)
draw.textured_rect(Theme.get_material('gradient'), x, y, box_width, box_height, accent_color)
end)
Parameters
- id String ID of the animation
- tx Number target x
- ty Number target y
- callback Function draws the contents; called with the current (x, y), where an unanimated axis receives the target value
Draws a spinning cog icon, usually as a loading indicator. All cogs drawn in a frame share one rotation, which advances with every call.
Parameters
- x Number screen x of the center of the cog
- y Number screen y of the center of the cog
- w Number width
- h Number height
- color Color optional, defaults to
Color(255, 255, 255)
Retrieves whatever was registered for the action with the specified identifier.
Parameters
- id String identifier of the action
Returns
- Map/Function the registered value, or nil if there is none
Returns the table storing all of the actions, keyed by identifier. This is the storage table itself, not a copy.
Returns
- Map
Gets the folder of the currently loaded schema.
Returns
- String the schema folder; the client falls back to 'flux' if it is not known yet
Gets the table containing the information about the currently loaded schema. The server reads it from the schema's gamemode .txt file once and caches it; the client uses the copy shared by the server.
Returns
- Map schema info with the name, author, description, version and folder fields
Gets the name of the currently loaded schema.
Returns
- String the schema name, or 'Unknown' if it cannot be determined
Returns the version of the Flux core, as declared in its package metadata.
Returns
- String
Returns the global UI offset, which follows the local player's view movement. HUD elements add it to their position to appear to lag behind the camera.
Returns
- Number x offset
- Number y offset
Includes all of the plugins inside the folder, files first, then folders. Does not handle plugins nested inside of other plugins.
Parameters
- folder String folder relative to the Lua search paths (lua/, gamemodes/)
Includes the files of the currently loaded schema. On the client, shortly afterward notifies the server and runs the FluxClientSchemaLoaded hook.
Prints a message to the console. Tables are printed with PrintTable.
Parameters
- message Any
Registers an action that can be assigned to a player. The value is stored as given; note that Player#do_action only runs it if it is a table with a callback function field, which is then called with the player and the action ID.
Parameters
- id String identifier of the action
- callback Map/Function optional, defaults to
nilhandler of the action, see above
Creates the state of a position animation unless one with this ID already exists, which makes it safe to call every frame.
Parameters
- id String unique ID of the animation
- x Number starting x, or nil to leave the x axis unanimated
- y Number starting y, or nil to leave the y axis unanimated
- delta Number fraction of the remaining distance covered on every draw, 0 to 1
See also
Sets the fill percentage of the circular action indicator drawn in the middle of the HUD. The value is cleared after every draw, so call this each frame while it should be visible.
Parameters
- percentage Number fill percentage from 0 to 100
- alpha Number optional, defaults to
255opacity of the indicator from 0 to 255
Creates or overwrites the state of a position animation.
Parameters
- id String unique ID of the animation
- x Number current x, or nil to leave the x axis unanimated
- y Number current y, or nil to leave the y axis unanimated
- delta Number fraction of the remaining distance covered on every draw, 0 to 1
Returns
- Map the animation state with the x, y and delta fields
See also
Writes a Lua file into lua/_flux/client and marks it for download, so that the clients
include it when they load. The files are included in the order of their names, which
is why the gamemode's own start with a number. Packages that generate clientside code
call this from their FLWriteClientFiles handler, since the folder is emptied before
the files are written.
Parameters
- path String file name, relative to lua/_flux/client
- contents String Lua code