This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
vedalken254's profile picture

[Help Neede] Trying to revamp a script for CC 1.62

Started by vedalken254, 15 April 2014 - 02:25 AM
vedalken254 #1
Posted 15 April 2014 - 04:25 AM
Hi guys,

For those of you who are aware of PonyKuu's work, I'm trying to fix up his turtle swarm quarry programs to work with ComputerCraft v1.62. Thus far, I've identified the culprit, but due to my limited knowledge of Lua, can't seem to fix it.

http://pastebin.com/ZLh56Jmd is his master API program. The master/modulemine programs are fine as is the master API. I have isolated the issue into a set of lines in his module script found here on line 552 at this link: http://pastebin.com/b1eQmHRb . I don't know if something changed majorly in CC 1.62 in regards to how "file = fs.open ("disk/initdata", "r")" follwed by "communicationData = textutils.unserialize(file.readLine())" works, but it's not working so well anymore. If i run the same commands from file= etc to the actual operations, i've found that it removes the braces when unserialized but cuts off digits from the MasterID.

http://gyazo.com/dc5f9238dd8846181ec39e6a2e09d7b6 has an image showing what I just described.

I'd appreciate any help you guys can offer and I know I should know this stuff but I don't know Lua that well yet.
Bomb Bloke #2
Posted 15 April 2014 - 10:34 AM
I'm honestly floored at the answer to this one.

The issue is in textutils.serialise(). Dan has, for reasons I can't fathom right now, rigged it to include line breaks and indentation in its output. This not only breaks backwards compatibility with a(nother) metric —- ton of scripts, it makes it a royal pain in the backside to store multiple serialised tables in one file (or anything else alongside a serialised table, for that matter).

I can see this change in the first pre-release for 1.6, and I'm amazed no one picked up on the ramifications of it or pointed out why it might be a bad idea. Myself included.

Anyway.

In PonyKuu's script, fortunately he's only dumping the one table in the initdata file, so you should be able to just get away with using "readAll" instead of "readLine" at 551.
Wojbie #3
Posted 15 April 2014 - 11:21 AM
The issue is in textutils.serialise(). Dan has, for reasons I can't fathom right now, rigged it to include line breaks and indentation in its output. This not only breaks backwards compatibility with a(nother) metric —- ton of scripts, it makes it a royal pain in the backside to store multiple serialised tables in one file (or anything else alongside a serialised table, for that matter).

Bit of-topic but i found that using
string.gsub(textutils.serialize(),"\n%s*","")
cuts all line breaks and most of indentation while still making it work with unserialize function correctly. Bit of weird but works :D/>
Edited on 15 April 2014 - 09:22 AM
Bomb Bloke #4
Posted 15 April 2014 - 11:29 AM
Excellent. I've got an immediate use for that, so thank you. :)/>
vedalken254 #5
Posted 16 April 2014 - 03:30 PM
Howdy Guys,

Thanks for the replies. Bomb: He's actually storing three serialized tables in there. One for the masterID/channel #, one for the fallback location i think, and one for navigational purposes. So would splitting that off into two other files possibly fix the underlying issue? I also don't know how to instantiate what woj suggested. Would that be
 string.gsub(textutils.serialize(objtobeserialized), "\n%s*, "") 
?

Thanks again guys! I really appreciate this as I want his scripts to work again. :D/>

EDIT: Also, Woj: I might give up on this for your swarm miner provided yours is updated for CC 1.62.
Edited on 16 April 2014 - 01:37 PM
Wojbie #6
Posted 16 April 2014 - 03:40 PM
Th should work ok… i did not use any stuff that changed… i think…. wait no it will not work. And i don't think i will bother updating sooo. Sorry ;D
Edited on 16 April 2014 - 01:41 PM
vedalken254 #7
Posted 16 April 2014 - 03:59 PM
Th should work ok… i did not use any stuff that changed… i think…. wait no it will not work. And i don't think i will bother updating sooo. Sorry ;D
Sad Panda I is. PonyKuu's was awesome but a hassle to get all set up. Yours looked easy to set up and manage, but had a limitation on how many turtles could be used (30 vs Kuu's stacklimit size of 64).
Bomb Bloke #8
Posted 16 April 2014 - 04:02 PM
Eh, multiple tables it is. I'd even checked, but somehow missed that.

So in the "master" API, around line 298, we have:

        -- Communication data: master ID and communication channel
        file.writeLine (textutils.serialize ({MasterID = MasterID, channel = channel}) )
        -- Location data:
        file.writeLine (textutils.serialize (modPosition))
        -- Navigation data:
        file.writeLine (textutils.serialize (naviData))

And so the substitution call would be implemented along these lines:

        -- Communication data: master ID and communication channel
        file.writeLine ("{[\"MasterID\"] = "..MasterID..", [\"channel\"] = "..channel.."}")  -- No need for this line, simpler to serialise manually.
        -- Location data:
        file.writeLine (string.gsub(textutils.serialize(modPosition),"\n%s*",""))
        -- Navigation data:
        file.writeLine (string.gsub(textutils.serialize(naviData),"\n%s*",""))

… and you'd leave the "readLine" I mentioned earlier alone, instead of switching it to "readAll".
vedalken254 #9
Posted 16 April 2014 - 04:05 PM
Thanks for the quick reply, Bomb!

Wouldn't it just be easier to add another two files in both master API and module API (master & module) and then separate the tables? Or would that introduce more issues?

Thanks,
Veddy

EDIT: found something else while perusing the stuff. textutils.unserialize seems to remain broken regardless of what I do. I haven't tried the initial code separated into three files yet but the new code gives the same output as in the original post. http://pastebin.com/uKGVRedp is my module edits. Let me know if you find anything I did wrong in there. Also, http://pastebin.com/eudtyVw1 is the master file with my edits. I'm going to try one more thing before I do anything else.

2nd EDIT: Nope. Unserialize is broken as I've tried to get it to read properly via several different methods all to no avail.

3rd EDIT: Figured out a path…. now to fix more of the module api (line 118 seems to be broken now…. prolly has to do with me separating the positional and navidata into separate files from the communication data.

4th and FINAL EDIT: I FIXED IT!!! :D/>. the module snippet that I have is here:

function init ()
sleep(2)
local file = fs.open ("/disk/comminitdata", "r")
local posFile = fs.open ("/disk/posdata", "r")
local naviFile = fs.open ("/disk/navidata", "r")
local communicationData = textutils.unserialize (file.readAll ())
Master = communicationData.MasterID
channel = communicationData.channel
-- set module's location
location = textutils.unserialize (posFile.readAll ())
-- set navigation data
naviData = textutils.unserialize (naviFile.readAll ())

-- Then send a request to Master, to get our ID and to let Master remember us in its state table for modules
local response = request ("Master", 5)
ID = response.NewID
end
The broken part was still the x.readLine() functions in the os. Why I have to do x.readAll() now to parse for specific data is beyond me, but at least she's working now. :D/>
Edited on 16 April 2014 - 08:01 PM
vedalken254 #10
Posted 16 April 2014 - 11:16 PM
Thanks Wojbie and Bomb Bloke! You guys have been most helpful and I've given you guys credit in my turtle programs thread on this topic!

Thanks Again!
Veddy
EDIT: Link to that thread is: http://www.computercraft.info/forums2/index.php?/topic/18155-turtle-swarm-quarry-updated-for-cc16x/
Edited on 16 April 2014 - 09:17 PM
Wojbie #11
Posted 16 April 2014 - 11:27 PM
Th should work ok… i did not use any stuff that changed… i think…. wait no it will not work. And i don't think i will bother updating sooo. Sorry ;D
Sad Panda I is. PonyKuu's was awesome but a hassle to get all set up. Yours looked easy to set up and manage, but had a limitation on how many turtles could be used (30 vs Kuu's stacklimit size of 64).

:ph34r:/> Don't tell anyone but there was no limit in truth. I just said 30 cause over 30 it lagged server with amount of messages it send :ph34r:/>
:ph34r:/> There may be update coming if i get my new tlco to work correctly. And Pocket Computer Auto Monitor. But you heard nothing :ph34r:/>
:ph34r:/> But thats after i update extended shell ;p :ph34r:/>

Ahem.. Happy you got it working :D/>
Edited on 16 April 2014 - 09:29 PM
vedalken254 #12
Posted 17 April 2014 - 12:21 AM
Th should work ok… i did not use any stuff that changed… i think…. wait no it will not work. And i don't think i will bother updating sooo. Sorry ;D
Sad Panda I is. PonyKuu's was awesome but a hassle to get all set up. Yours looked easy to set up and manage, but had a limitation on how many turtles could be used (30 vs Kuu's stacklimit size of 64).

:ph34r:/> Don't tell anyone but there was no limit in truth. I just said 30 cause over 30 it lagged server with amount of messages it send :ph34r:/>
:ph34r:/> There may be update coming if i get my new tlco to work correctly. And Pocket Computer Auto Monitor. But you heard nothing :ph34r:/>
:ph34r:/> But thats after i update extended shell ;p :ph34r:/>

Ahem.. Happy you got it working :D/>

Thanks Wojbie. Also, if i figure out the auto monitor for my APIs and such, I'll let you know the code I used and let you modify it for yours.
Kingdaro #13
Posted 17 April 2014 - 03:38 AM
I feel like an easy and more sensible workaround would be to simply store your tables in one table.
apemanzilla #14
Posted 17 April 2014 - 04:27 PM
Th should work ok… i did not use any stuff that changed… i think…. wait no it will not work. And i don't think i will bother updating sooo. Sorry ;D
Sad Panda I is. PonyKuu's was awesome but a hassle to get all set up. Yours looked easy to set up and manage, but had a limitation on how many turtles could be used (30 vs Kuu's stacklimit size of 64).

:ph34r:/> Don't tell anyone but there was no limit in truth. I just said 30 cause over 30 it lagged server with amount of messages it send :ph34r:/>
:ph34r:/> There may be update coming if i get my new tlco to work correctly. And Pocket Computer Auto Monitor. But you heard nothing :ph34r:/>
:ph34r:/> But thats after i update extended shell ;p :ph34r:/>

Ooh, I want in :3