Log In  

Using SERIAL() to write to stdout on Linux does not work.
OS: Linux Mint 21.2

function _init()
    string="test"
    for i=0,#string do
     poke(0x4300+i, string[i]) --string as an array of charcodes
    end

    serial(0x805,0x4300,#string + 1)

    printh("test2")
end

The stdout writing code came from this post about communicating with nodejs using serial.

This cart fails to write test to stdout using SERIAL() but succeeds when writing test2 using PRINTH().
The code doesn't make any error messages either.

P#135485 2023-10-06 00:16 ( Edited 2023-10-06 00:18)

I'm on Manjaro 23.0.2 and also don't get anything to stdout from SERIAL() using this code, FWIW.

P#135489 2023-10-06 00:46
1

This code works: (on manjaro)

str="hello"
poke(0x4300,ord(str,1,#str))
serial(0x805,0x4300,#str)

The issue with your code is poke(0x4300+i, string[i]) -- you want poke(0x4300+i, ord(string,i)) instead.

(If you try to poke a string it seems to set the address to 0 instead: poke(0,12)print(@0) poke(0,'a')print(@0) prints 12 0)

P#135494 2023-10-06 02:04 ( Edited 2023-10-06 02:04)

Thanks! I just tried it and it seems to work for me too. I guess whatever code was in that original post must be a bit outdated.

P#135495 2023-10-06 02:43

> (If you try to poke a string it seems to set the address to 0 instead: poke(0,12)print(@0) poke(0,'a')print(@0) prints 12 0)

I think the issue is that PICO-8 is trying to coerce the second arg to a number, probably using tonum(), which returns nothing if given an alpha character, meaning you are effectively doing poke(0), which infers the second arg, the value parameter, to be 0, similar to how you can clamp to positive numbers with just max(v) instead of saying max(v,0):

P#136122 2023-10-20 02:58 ( Edited 2023-10-20 03:02)

[Please log in to post a comment]