Jump to content




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


13 replies to this topic

#1 vedalken254

  • Members
  • 7 posts
  • LocationMinnesota, USA

Posted 15 April 2014 - 03: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/dc5...ec39e6a2e09d7b6 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.

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,098 posts
  • LocationTasmania (AU)

Posted 15 April 2014 - 09: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.

#3 Wojbie

  • Members
  • 630 posts
  • LocationKinda lost

Posted 15 April 2014 - 10:21 AM

View PostBomb Bloke, on 15 April 2014 - 09:34 AM, said:

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 by wojbie, 15 April 2014 - 10:22 AM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,098 posts
  • LocationTasmania (AU)

Posted 15 April 2014 - 10:29 AM

Excellent. I've got an immediate use for that, so thank you. :)

#5 vedalken254

  • Members
  • 7 posts
  • LocationMinnesota, USA

Posted 16 April 2014 - 02: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 by vedalken254, 16 April 2014 - 02:37 PM.


#6 Wojbie

  • Members
  • 630 posts
  • LocationKinda lost

Posted 16 April 2014 - 02: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 by wojbie, 16 April 2014 - 02:41 PM.


#7 vedalken254

  • Members
  • 7 posts
  • LocationMinnesota, USA

Posted 16 April 2014 - 02:59 PM

View Postwojbie, on 16 April 2014 - 02:40 PM, said:

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).

#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,098 posts
  • LocationTasmania (AU)

Posted 16 April 2014 - 03: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".

#9 vedalken254

  • Members
  • 7 posts
  • LocationMinnesota, USA

Posted 16 April 2014 - 03: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 by vedalken254, 16 April 2014 - 09:01 PM.


#10 vedalken254

  • Members
  • 7 posts
  • LocationMinnesota, USA

Posted 16 April 2014 - 10: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.computerc...ated-for-cc16x/

Edited by vedalken254, 16 April 2014 - 10:17 PM.


#11 Wojbie

  • Members
  • 630 posts
  • LocationKinda lost

Posted 16 April 2014 - 10:27 PM

View Postvedalken254, on 16 April 2014 - 02:59 PM, said:

View Postwojbie, on 16 April 2014 - 02:40 PM, said:

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 by wojbie, 16 April 2014 - 10:29 PM.


#12 vedalken254

  • Members
  • 7 posts
  • LocationMinnesota, USA

Posted 16 April 2014 - 11:21 PM

View Postwojbie, on 16 April 2014 - 10:27 PM, said:

View Postvedalken254, on 16 April 2014 - 02:59 PM, said:

View Postwojbie, on 16 April 2014 - 02:40 PM, said:

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.

#13 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 17 April 2014 - 02:38 AM

I feel like an easy and more sensible workaround would be to simply store your tables in one table.

#14 apemanzilla

  • Members
  • 1,421 posts

Posted 17 April 2014 - 03:27 PM

View Postwojbie, on 16 April 2014 - 10:27 PM, said:

View Postvedalken254, on 16 April 2014 - 02:59 PM, said:

View Postwojbie, on 16 April 2014 - 02:40 PM, said:

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users