Page 1 of 1

sanding a table with SendData()

Posted: Thu Sep 14, 2017 9:29 am
by peceha
Hello,
I've been trying to send a table (about 300 items inside containing sub-tables, numbers and strings - that is dungeon map generated on server computer) to the client computer:

Code: Select all

SendData(clientID,ArrayToStr(maze))
On the client computer I have:

Code: Select all

maze=ReceiveData(connectionID,#RECEIVEALL)
maze=StrToTable(maze)
and after using:

Code: Select all

ForEach(maze,DebugPrint)
i get:
0 0
The received table is not correct - what am I doing wrong?
Thanks

Re: sanding a table with SendData()

Posted: Thu Sep 14, 2017 10:13 pm
by airsoftsoftwair
ArrayToStr() doesn't convert arbitrary tables into strings. It turns a number of characters stored inside a table into a text string. There is currently no function to turn a table into a string but you can easily write one by creating a virtual file and then use WriteTable() to write the table to it and then use FileToString() to get the virtual file back as a string, it's as easy as that :)

Re: sanding a table with SendData()

Posted: Thu Sep 14, 2017 11:03 pm
by peceha
Thanks, that worked - but I used real file instead of virtual one (just couldn't figure out how to write a table into virtual file).

Re: sanding a table with SendData()

Posted: Fri Sep 15, 2017 9:12 am
by peceha
Just one more :D
How to change a brush into the string (or better - send it using the SendData() command) ?

I have a 16x16 pxl avatar that needs to be sent over the network to the rest of the computers.
I have found SaveBrush() command to make a file out of it and then FileToString()... is that correct? or there is some other way to send a brush?

Thanks

Re: sanding a table with SendData()

Posted: Mon Sep 18, 2017 4:22 pm
by peceha
Looks like following sequence works just fine:

Code: Select all

...
saveBrush()
fileToString()
sendData()
stringToFile()
loadBrush()
...
Thanks

Re: sanding a table with SendData()

Posted: Mon Sep 18, 2017 4:48 pm
by airsoftsoftwair
Yes, but you can use virtual files to avoid disk accesses. See DefineVirtualFileFromString() for details.

Re: sanding a table with SendData()

Posted: Tue Oct 01, 2019 4:28 pm
by airsoftsoftwair
Tables can now be easily serialized to/from strings, see here: viewtopic.php?f=18&t=2260&p=12199#p12199