Note: This cartridge's settings do not allow embedded playback. A [Play at lexaloffle] link will be included instead.
Feature Overview
"KNUTIL" is a library for PICO-8 that contains functions that are frequently used in the games I have created.
I've kept the functions that I eventually needed in my production.
In this cart, I show you how the scene functions work with animations.
Z key: Execute the order command.
Up/Down: Select the order command.
SCENE MANAGER controls and replaces the order in which functions are called with a small number of tokens by using consecutive string instructions.
The generated SCENE can register a global function as an ORDER.
One of the registered ORDERS is retrieved by SCENE and the process is repeated for the specified length.
When the processing is finished, it repeats the processing of the next ORDER.
This is expected to facilitate the planning of the performance.
[SCENE NAME] : Specify the name generated by MKSCENES.
[COMMAND] : Specify the following ORDER COMMANDS.
[FUNCTION NAME] : Specify the name of the global function.
[DURATION FRAME]: Specifies the number of frames to be sustained; if set to 0, it will not automatically terminate.
ORDER COMMANDS
ST (SET): Delete all stacked ORDERS in SCENE and set new ORDERS.
CMDSCENES[[
UPD ST MANAGE 0
]]
Clean the SCENE "UPD" and add a "FUNCTION MANAGE".
PS (PUSH): Add an ORDER to the SCENE
CMDSCENES[[
KEY PS KEYCHECK 0
]]
Add the SCENE "KEY" with "FUNCTION KEYCHECK" at the top.
US (UNSHIFT): interrupt ORDER at the beginning of a SCENE.
CMDSCENES[[
DRW US DRAWRECT 200
DRW US NIL 100
DRW US DRAWCIRC 200
]]
Scene "DRW" is executed in the ORDER of DRAWCIRC, NIL, DRAWRECT.
RM (REMOVE): remove one ORDER.
CMDSCENES[[
DRW RM
]]
Removes the first ORDER of the SCENE "DRW".
CMDSCENES[[
DRW RM DRAWRECT
]]
Deletes the DRAWRECT ORDER of SCENE "DRW", starting from the top.
CL (CLEAR): Remove all stacked ORDERS from the SCENE.
CMDSCENES[[
KEY CL
]]
Deletes all the ORDERS registered in the SCENE "KEY".
FI (FIND): Search and retrieve ORDERS from a SCENE.
RES = CMDSCENES[[
DRW FI DRAWRECT
]]
In this case, the return value RES is a table, and the ORDER "DRAWRECT" is in the first element.
Create a function for ORDERS.
FUNCTION KEYCHECK( ORDER )
PRINT('PROCESSIONG ORDER')
END
Run each SCENE.
## In the _UPDATE() and _DRAW() functions
FOR V IN ALL(INDEXES)
SCENES[V].TRA()
END
ORDER function
FUNCTION [FUNCTION NAME] ( ORDER )
CLS()
IF ORDER.FST THEN
STOP"IT'S FIRST!"
END
IF ORDER.LST THEN
STOP"IT'S LAST!"
END
PRINT('COUNT: '..ORDER.CNT..'/'..ORDER.DUR)
END
Properties of ORDER
FST / LST
ORDER.FST : at first execution
ORDER.LST : at the last execution.
CNT / DUR
ORDER.CNT : Execution count of the currently running ORDER.
ORDER.DUR : Count of expected end of the currently running ORDER.
PRM
It contains the value specified in the second argument of CMDSCENES.
RATE
Used to specify the end from the start, e.g. in coordinates.
ORDER.rate('[start] [end]', duration, count )
The default values for duration and count are the ones specified in CMDSCENES.
Force ORDER termination.
Do return 1
or
do ORDER.rm = 1.
Functions other than scenes
There is one in this library that I have already posted.
HTBL: Converting a string to a table(Multidimensional Array / Hash Table / Jagged Arrays)
Note: This cartridge's settings do not allow embedded playback. A [Play at lexaloffle] link will be included instead.
Functions not posted on BBS. (I will post them some other time)
TONORM: String to type conversion(boolian, nil, number). TOHEX: Convert hexadecimal string without "0x". TTOH: Sum the numbers in argument 1 by shifting bits to argument 2. HTOT: Divide an integer value into 8 bits and make it into a table. REPLACE: Perform string substitutions. EXRECT(RFMT): Drawing and overlap judgment with the generated rectangle. TOC: Divide the value and exclude the remainder. JOIN: Convert a table containing strings into a single string. SPLIT(wrapper function): Split() for two-dimensional support. Defaults to space separator. HTD: Convert a hexadecimal string to a 4-bit-16-bit table. SLICE: Cuts out the table at the specified index. TBFILL: Creates a table filled with the specified values. (Two dimensional support) OUTLINE: Display text with edges. MKPAL: Create a table to be used in pal(), specifying the colors before and after the change. ECMKPAL: Generate a set of tables to be retrieved by MKPAL(). ECPALT: Run palt() on the table. TTABLE: If it is not a table, it returns FALSE, otherwise it returns as is. INRNG: Judges that the value is within the range of two values. AMID: Expand the arguments to positive and negative and do mid(). BMCH: Compares two values to judge that they both have a bit in common.
UPDATE HISTORY
v0.5
Mainly due to sub()'s CPU cost countermeasure.
replace: fix usage of sub()
htd: Convert from split()
htbl: Run newlines without replace()
scene: Save cost with split()&comb() at initialization
dbg: Change to display values without dbg() argument