Log In  

Cart #knutil-7 | 2022-12-02 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
9

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 ( CMDSCENES )

CMDSCENES([[
[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.

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 I,V IN PAIRS(SCENES) DO
    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.

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

Cart #knutil_bpack-0 | 2022-12-01 | Code ▽ | Embed ▽ | No License

BUNPACK: Slice the value with bit width.

Cart #knutil_bunpack-2 | 2022-11-30 | Code ▽ | Embed ▽ | No License
1

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

DMP: Dumps information about a variable.

Cart #vdmplua-2 | 2022-03-30 | Code ▽ | Embed ▽ | No License

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

Cart #stringhashtable-3 | 2022-07-30 | Code ▽ | Embed ▽ | No License
1

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
1

RCEACH: Iterate from rectangle values.

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

REPLACE: Perform string substitutions.

Cart #knutil_replace-0 | 2022-08-15 | Code ▽ | Embed ▽ | No License
5

TMAP: More compact operable foreach iterator.

Cart #tablemap-0 | 2022-03-21 | Code ▽ | Embed ▽ | No License

TBFILL: Creates a table filled with the specified values.

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

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

Cart #knutil_ttable-1 | 2022-08-28 | Code ▽ | Embed ▽ | No License
1

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".
BPACK:
BUNPACK:
EXRECT(RFMT): Drawing and overlap judgment with the generated rectangle.
TOC: Divide the value and exclude the remainder.
SPLIT(wrapper function): Split() for two-dimensional support. Defaults to space separator.
HTD: Convert a hexadecimal string to a 4-bit-16-bit table.
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.
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. "Bitwise operators" make it less significant.

++ REMOVED ++


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.

UPDATE HISTORY


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
P#59538 2021-03-03 12:49 ( Edited 2022-12-02 15:10)

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

P#113869 2022-07-01 13:11

@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... >_<

P#113871 2022-07-01 14:18

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.

P#113942 2022-07-04 04:21

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
P#115009 2022-07-30 12:01

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()
P#117147 2022-09-10 16:05 ( Edited 2022-09-10 16:07)

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()
P#117260 2022-09-12 09:36

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.
P#121722 2022-12-02 15:20

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2023-03-28 08:24:28 | 0.039s | Q:78