Log In  

While poking around with Pico8, I discovered a way to simulate char and unsigned char types.

--           tochar          --
    this function converts a value
    to make it emulate a char
    (256 max characters)

    it can emulate signed and
    unsigned chars. the value
    will not go beyond 0-255
    if unsigned, and if signed
    the values will remain at -128
    to 128.

    tochar returns a signed char
    and touchar returns an unsigned


    see sample;

function tochar(id)
    local res=id%256
    return flr(res)

function touchar(id)
    local res=((id-128)%255)-127
    return flr(res)


print(touchar(number, true))

Theres the code snippit, put it in and play with the sample.

info about it is in the code;
enjoy for anybody wanting to make char variables for what ever your reasons might be.

P#63413 2019-04-11 19:03

[Please log in to post a comment]