Log In  


Cart #knutil-12 | 2023-08-13 | Code ▽ | Embed ▽ | No License
14

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.

Using SCENE

Create a SCENE ( MKSCENES )

SCENES = MKSCENES( { 'UPD', 'DRW', 'KEY' } )

SCENES: Contains the generated SCENEs.

Enter an ORDER into a SCENE ( SCMD )

SCMD([[
	[SCENE NAME] [COMMAND] [FUNCTION NAME] [DURATION FRAME]
	[SCENE NAME] [COMMAND] [FUNCTION NAME] [DURATION FRAME]
...
]])
  • [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.

Only "tab characters" are supported for indentation in command descriptions.

ORDER COMMANDS

ST (SET): Delete all stacked ORDERS in SCENE and set new ORDERS.

SCMD[[
UPD ST MANAGE 0
]]

Clean the SCENE "UPD" and add a "FUNCTION MANAGE".

PS (PUSH): Add an ORDER to the SCENE

SCMD[[
KEY PS KEYCHECK 0
]]

Add the SCENE "KEY" with "FUNCTION KEYCHECK" at the top.

US (UNSHIFT): interrupt ORDER at the beginning of a SCENE.

SCMD[[
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.

SCMD[[
DRW RM
]]

Removes the first ORDER of the SCENE "DRW".

SCMD[[
DRW RM DRAWRECT
]]

Deletes the DRAWRECT ORDER of SCENE "DRW", starting from the top.

CL (CLEAR): Remove all stacked ORDERS from the SCENE.

SCMD[[
KEY CL
]]

Deletes all the ORDERS registered in the SCENE "KEY".

FI (FIND): Search and retrieve ORDERS from a SCENE.

RES = SCMD[[
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
FOREACH(SCENES,TRANSITION)

ORDER function

FUNCTION [FUNCTION NAME] ()
	CLS()
	IF _FST THEN
		STOP"IT'S FIRST!"
	END
	IF _LST THEN
		STOP"IT'S LAST!"
	END
	PRINT('COUNT: '.._CNT..'/'.._DUR)
END

Properties of ORDER

The following parameters can be referenced as global variables.

_FST / _LST

_FST : at first execution
_LST : at the last execution.

_CNT / _DUR

_CNT : Execution count of the currently running ORDER.
_DUR : Count of expected end of the currently running ORDER.

_PRM

It contains the value specified in the second argument of SCMD.

_RATE

Used to specify the end from the start, e.g. in coordinates.

_RATE('[start] [end]', duration, count )

The default values for duration and count are the ones specified in SCMD.

Force ORDER termination.

Do RETURN 1
or
do _RM = 1.

Functions other than scenes

SET 1: Basic Library

★ Libraries for frequent use and quick implementation

AMID: Expand the arguments to positive and negative and do mid().

Cart #knutil_amid-1 | 2023-08-09 | Code ▽ | Embed ▽ | No License
2

BPACK: Pack the value of the bit specification with bit width.

Cart #knutil_bpack-2 | 2024-12-21 | Code ▽ | Embed ▽ | No License

BUNPACK: Slice the value with bit width.

Cart #knutil_bunpack-3 | 2024-12-21 | Code ▽ | Embed ▽ | No License

CAT: Concatenate tables. Indexes are added last and identical keys are overwritten.

Cart #concat___table-0 | 2022-03-11 | Code ▽ | Embed ▽ | No License
1

COMB: Combines two tables to create a hash table.

Cart #combine_table-0 | 2022-03-15 | Code ▽ | Embed ▽ | No License
1

ECPALT: Set transparency from palette table.

Cart #knutil_ecpalt-0 | 2023-08-07 | Code ▽ | Embed ▽ | No License

HTD: Split a continuous string of hexadecimal numbers into a table.

Cart #knutil_htd-0 | 2023-08-08 | Code ▽ | Embed ▽ | No License

HTBL: Converting a string to a table(Multidimensional Array / Hash Table / Jagged Arrays)

Cart #stringhashtable-8 | 2024-12-23 | Code ▽ | Embed ▽ | No License
2

INRNG: Tests that the specified value is within a range.

Cart #knutil_inrng-2 | 2022-06-30 | Code ▽ | Embed ▽ | No License
1

JOIN: Joins strings with a delimiter.

Cart #knutil_join-1 | 2022-09-10 | Code ▽ | Embed ▽ | No License
2

MKPAL: create a color swap table for use in PAL().

Cart #knutil_mkpal-0 | 2023-08-07 | Code ▽ | Embed ▽ | No License

MSPLIT: Multi-layer split.

Cart #knutil_msplit-1 | 2023-05-22 | Code ▽ | Embed ▽ | No License
2

OPRINT: Print with outline.

Cart #knutil_oprint-4 | 2024-07-01 | Code ▽ | Embed ▽ | No License
7

RCEACH: Iterate from rectangle values.

Cart #rceach-0 | 2022-03-30 | Code ▽ | Embed ▽ | No License
1

REPLACE: Perform string substitutions.

Cart #knutil_replace-1 | 2023-07-27 | Code ▽ | Embed ▽ | No License
6

TBFILL: Creates a table filled with the specified values.

Cart #knutil_tbfill-0 | 2022-09-12 | Code ▽ | Embed ▽ | No License
1

TMAP: More compact operable foreach iterator.

Cart #tablemap-1 | 2023-05-28 | Code ▽ | Embed ▽ | No License
1

TOHEX: Digit-aligned hexadecimal conversion (not including 0x).

Cart #knutil_tohex-1 | 2023-05-20 | Code ▽ | Embed ▽ | No License
2

TTABLE: If the argument is a table, the table is returned.

Cart #knutil_ttable-2 | 2023-07-28 | Code ▽ | Embed ▽ | No License
1

SET 2: Libraries to create objects

★ Rectangles that incorporate judgment and drawing, scenes that manage screen and operation transitions

EXRECT: Creates a rectangle object with extended functionality.

Cart #knutil_exrect-0 | 2023-04-24 | Code ▽ | Embed ▽ | No License
1

MKSCENES: This post! Manage screen and operation switching.

Cart #knutil-12 | 2023-08-13 | Code ▽ | Embed ▽ | No License
14

SET 3: Debugging Library

★ Real-time or stop and inspect at any timing

DBG: Displays any timing debugging value.

Cart #knutil_dbg-1 | 2023-08-10 | Code ▽ | Embed ▽ | No License
1

DMP: Dumps information about a variable.

Cart #vdmplua-4 | 2023-06-10 | Code ▽ | Embed ▽ | No License
3

++ REMOVED ++


TOC: flr(divide) can be substituted for \.
ECMKPAL: The format was changed and integrated in MKPAL.
OUTLINE: Renamed to OPRINT, will be reflected in v0.14 knutil.
SPLIT: Renamed to MSPLIT, will be reflected in v0.14 knutil.
TTOH: Sum the numbers in argument 1 by shifting bits to argument 2. This function has been re-specified to BPACK.
HTOT: Divide an integer value into 8 bits and make it into a table. This function has been re-specified to BUNPACK.
SLICE: Cuts out the table at the specified index. the function was removed because there is a {unpack()} with a similar function.
BMCH: Compares two values to judge that they both have a bit in common. "Bitwise operators" make it less significant.

TONORM: Normalize argument values to the correct type(boolian, nil, number).

UPDATE HISTORY


v0.14.0

  • amid:change the order of arguments.
  • ecpalt:be sure to perform initialization of the transparency settings.
  • htbl:token cost cut, note second return value.
  • htd:change from tmap to foreach.
  • dbg:support for nil
  • dmp:added _update_buttons().
  • mkpal:arguments before and after the change. support for multiple palette sets.
  • msplit:wrapper for split() is eliminated and renamed.
  • oprint:inherit outline() and rename function.
  • replace:support for multiple replacements.
  • tmap:support for false replacements.
  • ttable:use count() to determine.
  • scene:
    • cmdscenes:changed to scmd. for a while cmdscenes will remain for compatibility.
    • sh:delete order shift as it is not used.
    • order:
    • swap 𝘦𝘯𝘷[] and order parameters to support references from global variables
    • change parameter name(_rate _cnt _rm _fst _lst _nm _dur _prm)
  • changed diagram staging; no intervening shift processing.
  • parallel added to diagram production.
  • correction of library documentation.

  • [deleted]:
    • toc
    • tonorm
    • ecmkpal

v0.13.1

  • corrected commented out vdmp to dmp.

v0.13

  • scene:
    • cmdscenes:supports indentation description by tabs.

v0.12

  • library help added to pause menu.
  • bmch: unlisted.
  • exrect: fix variable and function names.
  • scene:
    • rate: adjustment of decimal point overflow countermeasures.
    • cmdscenes: continuous call handling.
    • added functions for iterators.
  • dbg: simplification by join.
  • replace: support for multiple replacements.

v0.11

  • htd: fixed table values to local variables
  • bpack: specification change from ttoh()
  • bunpack: specification change from htot()
  • slice: the function was removed because there is a {unpack()} with a similar function.

v0.10

  • split: supports multi-dimensional arrays
  • cmdscenes: fixed for split update
  • sceneorder: update for use of tuples
  • dmp: apply p8scii font color

v0.9

  • tbfill: changed to specify indexes at the beginning and end of tables, support for variable length arguments.
  • tohex: fixed for update of tbfill()

v0.8

  • join: use of tuples
  • tbfill: defaults to 1 or specifies the start of the table
  • tohex: support for updating join()

v0.7

  • sceneorder:"rate" func countermeasures against overflow of digits
  • code update saved token:
    • htbl: 7 tokens
    • tonorm: 9 tokens

v0.6

  • simplified handling of scene orders
  • rceach: name change from ecxy()
  • inrng: using tupple twice
  • exrect.con: name change from exrect.cont()
  • exrect.hov: name change from exrect.hover()
  • scenes: order.rate is calculated enough value in the last count
  • cmdscenes: change name from scenesbat

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
  • example: Add htbl() example use

Please do not use this library and its code for the purpose of promoting vaccines.

14


The documentation says CMDSCENES, but the code says SCENESBAT. Which is correct or am I misunderstanding something?


@tmskna

OH!!! In the currently uploaded version 'SCENESBAT' is correct! I was going to change it to CMDSCENES in a future version.

I often want to change the name after some time has passed since I created it.
My apologies... >_<


I have updated KNUTIL to version 0.6!

@tmskna
I changed the function name from SCENESBAT to CMDSCENES!

Scene iterating has been simplified.
The following code is an example.

SCENES = MKSCENES( { 'UPD', 'DRW', 'KEY' } )

FUNCTION _UPDATE()
  FOR I,V IN PAIRS(SCENES) DO
    V.TRA()
  END
END

Please check the UPDATE HISTORY for other changes.
Thank you.


KNUTIL has been updated to v0.7!

  • sceneorder:"rate" func countermeasures against overflow of digits
  • code update saved token:
    • htbl: 7 tokens
    • tonorm: 9 tokens

KNUTIL has been updated to v0.8!

  • join: Use of tuples
  • tbfill: Defaults to 1 or specifies the start of the table
  • tohex: Supported for update of join()

KNUTIL has been updated to v0.9!

  • tbfill: changed to specify indexes at the beginning and end of tables, support for variable length arguments.
  • tohex: fixed for update of tbfill()

NUTIL has been updated to v0.10 and v0.11!

v0.10

  • split: supports multi-dimensional arrays.
  • cmdscenes: fixed for split update.
  • sceneorder: update for use of tuples.
  • dmp: apply p8scii font color.

v0.11

  • htd: fixed table values to local variables.
  • bpack: specification change from ttoh().
  • bunpack: specification change from htot().
  • slice: the function was removed because there is a {unpack()} with a similar function.

1

KNUTIL has been updated to v0.12!

v0.12

  • library help added to pause menu.
  • bmch: unlisted.
  • exrect: fix variable and function names.
  • scene:
    • rate: adjustment of decimal point overflow countermeasures.
    • cmdscenes: continuous call handling.
    • added functions for iterators.
  • dbg: simplification by join.
  • replace: support for multiple replacements.

KNUTIL has been updated to v0.13!

v0.13

  • scene:
    • cmdscenes:supports indentation description by tabs.

1

There are two "vdmp" which should be "dmp".

  • In the description of the HTBL() article on this BBS
  • In the last (commented out) line of the "multidimensional table" example in the KNUTIL code

Thanks for the continuous improvements.


@tmskna

Yes, indeed.
Minor version updade to v0.13.1 to fix the past vdmp description.


I have updated knutil to v0.14.0!

  • amid:change the order of arguments.
  • ecpalt:be sure to perform initialization of the transparency settings.
  • htbl:token cost cut, note second return value.
  • htd:change from tmap to foreach.
  • dbg:support for nil
  • dmp:added _update_buttons().
  • mkpal:arguments before and after the change. support for multiple palette sets.
  • msplit:wrapper for split() is eliminated and renamed.
  • oprint:inherit outline() and rename function.
  • replace:support for multiple replacements.
  • tmap:support for false replacements.
  • ttable:use count() to determine.
  • scene:
    • cmdscenes:changed to scmd. for a while cmdscenes will remain for compatibility.
    • sh:delete order shift as it is not used.
    • order:
    • swap 𝘦𝘯𝘷[] and order parameters to support references from global variables
    • change parameter name(_rate _cnt _rm _fst _lst _nm _dur _prm)
  • changed diagram staging; no intervening shift processing.
  • parallel added to diagram production.
  • correction of library documentation.

  • [deleted]:
    • toc
    • tonorm
    • ecmkpal

1
function _draw()
	cls()
	if isparallel then
		foreach(scenes,function(s)
			tmap(s.ords,function(v,i)
				-- _scal.push,_scal.push,_scal.shift...
				s.tra(i)
			end)
		end)

When an element of s.ords is removed by s.tra(i), the indexes of subsequent elements are shifted and the next ORDER is skipped. (In the sample program, when an ORDER ends during PARALLEL, the immediately following valid ORDER is seen blinking.) Perhaps processing in reverse order would solve the problem.


@tmskna
Thanks for noticing that!
It looks like I need to update my library soon.

The code part you pointed out will be changed as follows.

function _draw()
	cls()
	foreach(scenes,isparallel and transitionp or transition)
end

function transitionp(v)
	for o in all({unpack(v.ords)}) do
		v.tra(o)
	end
end

By regenerating the table from unpack(), the effect of table-del will be avoided. Processing will proceed in order.



[Please log in to post a comment]