Log In  

Hello, I am trying to pass my player.score variable (an int from 0 to wherever), using GPIO.

I have been using poke2(location, player.score) and then reading to the browser using pico8-gpio-listener.js library by Ben Wiley.

However, my player.score maxes out at 255 and then resets to 0. This doesn't seem right so any help would be appreciated. The player.score itself goes as high as I need it to, it's just when I use poke2() it limits to 4bits(?) I think.

P#122775 2022-12-20 23:58

poke2 will pass 16 bits from the value, poke4 all 32 bits.

can you share some code?

P#122778 2022-12-21 01:02

sure, here's the game: https://www.lexaloffle.com/bbs/?tid=45916

I am using

 --record score 
    poke2(0x5f80, player.score)
    --record gamestate
    poke2(0x5f81, state) 

within the game to push the score and

script src="scripts/pico8-gpio-listener.js"></script>
    <script>
      (function () {
        var gpio_divs = document.querySelectorAll(".gpio_values div");
        var gpio = getP8Gpio();
        gpio.subscribe(function (newIndices) {
          console.log(newIndices);
          for (var i = 0; i < 8; i++) {
            var div = (gpio_divs[0]);
            var div2 = (gpio_divs[1]);
            //console.log(div);
            div.innerText = gpio[0];
            div2.innerText = gpio[1];
            console.log('Player score: ' + gpio[0]);
            console.log('Gamestate: ' + gpio[1]);

            /*
            if(div[i]=255){
              div[i]+=255;
              console.log(div);
            }
            */
            if (newIndices.indexOf(i) === -1) {
              div.classList.remove("new");
            } else {
              div.classList.add("new");
            }
          }
        });
      })();
    </script>

in my html page to record the score/gamestate to the browser. Both the display on the page and console.log reach 255 and then cycle back to 0.

I am also a fairly amateur developer and especially with javascript, so please bear in mind :')

P#122780 2022-12-21 01:17

oh wait, poke2 is just a shortcut to poke one byte (8 bits of the number) at the address then another byte (next 8 bits, but I can never remember if low or high means first from the left or the right) at address + 1

so here you are overwriting the second byte when you poke the state, the address should be greater. then on the javascript side you’ll have to get two bytes and combine them into one number to get all 16 bits (or four bytes if you use all that for «big numbers» scores)

P#122790 2022-12-21 05:16

I'm not sure I understand. I had poke2(location, score) before I implemented poke2(location, state) and it still didn't go higher than 255.

Am I supposed to define a range of addresses with poke2?
I'm also not certain how I'd combine the bytes on the JS side.

P#122811 2022-12-21 20:12

[Please log in to post a comment]