General Helper

From Frictional Wiki
< HPL3‎ | SOMA‎ | Scripting
Jump to navigation Jump to search


The General helper turns a number of seconds into a clock display. This short example prints a clock string so you can see how the format switches work.

Print a clock string

  1. Open your mod’s map script. Keep its generated map class and callbacks; see Add your first script.
  2. Add this include alongside the other includes:
#include "helpers/helper_general.hps"
  1. Put the following body inside your existing OnStart() callback:
void OnStart()
{
    tString clock = String_SecondsToClockDisplay(65.25f, false, true, true, true);
    cLux_AddDebugMessage(clock);
}
  1. Save and start the map in development mode. If it is already running, press F5 to restart it.

The debug message is 01:05:25: one minute, five seconds and 25 hundredths. The four Boolean arguments select hours, minutes, seconds and hundredths, in that order. Here hours are hidden.

Change the format

The helper extracts each time component, pads values below 10 with a leading zero and separates enabled components with colons. Changing the last argument to false hides hundredths and gives 01:05.

The seconds component is not the total number of seconds. If you enable only seconds for this input, the result is 05; whole minutes have already been removed.

A stock use

The stock String_SecondsToClockDisplay caller formats an ETA with hours and hundredths hidden. You can use the same switches for a minutes-and-seconds display.

If the message does not appear

Check that you edited the script beside your mod’s map, retained its class and callback structure, and added the include. In development mode, use F1 → Show Error List or Show HPL Log.

See also