sanding a table with SendData()

Find quick help here to get you started with Hollywood
Post Reply
peceha
Posts: 111
Joined: Tue Dec 13, 2016 8:39 am
Location: Poland

sanding a table with SendData()

Post 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
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: sanding a table with SendData()

Post 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 :)
peceha
Posts: 111
Joined: Tue Dec 13, 2016 8:39 am
Location: Poland

Re: sanding a table with SendData()

Post 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).
peceha
Posts: 111
Joined: Tue Dec 13, 2016 8:39 am
Location: Poland

Re: sanding a table with SendData()

Post 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
peceha
Posts: 111
Joined: Tue Dec 13, 2016 8:39 am
Location: Poland

Re: sanding a table with SendData()

Post by peceha »

Looks like following sequence works just fine:

Code: Select all

...
saveBrush()
fileToString()
sendData()
stringToFile()
loadBrush()
...
Thanks
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: sanding a table with SendData()

Post by airsoftsoftwair »

Yes, but you can use virtual files to avoid disk accesses. See DefineVirtualFileFromString() for details.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: sanding a table with SendData()

Post by airsoftsoftwair »

Tables can now be easily serialized to/from strings, see here: viewtopic.php?f=18&t=2260&p=12199#p12199
Post Reply