Legacy GM Buffer Error

N

nick13579

Guest
Whenever my program tries to run this code:

var buff = async_load[? "buffer"];
buffer_seek(buff, buffer_seek_start, 0);
receive = buffer_read(buff, buffer_s16);

I get this error:

"Attempting to read from outside the buffer, returning 0
at gml_Object_obj_control_NetworkingEvent_1 (line 6) - receive = buffer_read(buff, buffer_s16);"

I thought this was weird because I said to put it at the start with buffer_seek(), but maybe I'm doing something wrong.

Help is much appreciated
 

TsukaYuriko

☄️
Forum Staff
Moderator
If reading from position 0 equals reading from outside of the buffer, the buffer is probably empty. The source of this problem might be in whatever you're using to send the buffer.
 
N

nick13579

Guest
Oh ok. Is there a way for me to see if the buffer is not empty?
 
N

nick13579

Guest
I changed my code to this:

var buff = async_load[? "buffer"];
if(buffer_get_size(buff) > 0)
{
buffer_seek(buff, buffer_seek_start, 0);
receive = buffer_read(buff, buffer_s16);
}

But I get the same error
 
E

elementbound

Guest
buffer_s16 reads two bytes, so you could still get this error if the buffer's size is one byte. Could you output the size of the buffer, for example with show_message? Also, if size is not the issue, maybe you could just read the buffer byte by byte, and output the values.
 
N

nick13579

Guest
Thanks for the reply. I'll try to show the size with show_message
 
N

nick13579

Guest
But it's weird. I print out what Game Maker receives and it shows letters instead of the number I am sending to it
 
N

nick13579

Guest
Ok, so I used show_message(string(buffer_get_size(buff))) and it is always 1
 
N

nick13579

Guest
Idk if this is the way you wanted me to do it, but I used show_message(buff) and got a value of 2
 
E

elementbound

Guest
Okay, so now we know that you are not receiving the data you expect to receive. Where do you get this buffer from? What are you loading with an async function? Is that a file included with the game? Is that something dynamically created? And if so, how do you create it?
 

FrostyCat

Redemption Seeker
Then you need to look into where the buffer came from, because your reading code disagrees with what's there. A buffer that has a s16 written to it in full cannot possibly have a size of 1. For instance, if this came from a Networking event, ensure that it is a data-type event (i.e. you have checked async_load[? 'type']) and the server-side code also sends a s16 in that position.
 
N

nick13579

Guest
I am using an Arduino MKR1000 to send the data.
I'll try to use async_load[? 'type'], and also, does the word type have to be in 'type' or can it be in "type" also?

Here is my code so far:

if(connected == true)
{
var buff = async_load[? "buffer"];
if(buffer_get_size(buff) > 1)
{
buffer_seek(buff, buffer_seek_start, 0);
receive = buffer_read(buff, buffer_string);
show_message(buff);
with(obj_slider)
{
pos = other.receive;
refresh = true;
}
}
}

Right now I write the data to another object, but I don't think that is interfering
 
N

nick13579

Guest
But I gotta go gys. Thanks so much for the replies and please keep in tough with this because I'm going to be back later. Once again, thanks guys!
 
N

nick13579

Guest
Ok thanks! That worked, but I also found that I can use buffer_text
Also, I got Game Maker to receive the correct data properly
 
E

elementbound

Guest
Mind telling us how? What was the problem? Maybe future readers could find it useful.
 
N

nick13579

Guest
Oh, ya. So what i was sending to Game Maker was a char, but in the other software I was sending it with (Arduino IDE) I didn't pass a char to the Udp.write command (This is the command that I used to send data to Game Maker). So I had to convert the data I wanted to send into a char, then send it and, in Game Maker, I had to use buffer_text in buffer_read(buff, buffer_tex); After this, Game Maker could receive the correct data from the Arduino.
I hope that helps. And thank you guys for all the help!

-Nick
 
Top