[Help Neede] Trying to revamp a script for CC 1.62
#1
Posted 15 April 2014 - 03:25 AM
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
Posted 15 April 2014 - 09:34 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).
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
Posted 15 April 2014 - 10:21 AM
Bomb Bloke, on 15 April 2014 - 09:34 AM, said:
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
Edited by wojbie, 15 April 2014 - 10:22 AM.
#4
Posted 15 April 2014 - 10:29 AM
#5
Posted 16 April 2014 - 02:30 PM
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.
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
Posted 16 April 2014 - 02:40 PM
Edited by wojbie, 16 April 2014 - 02:41 PM.
#7
Posted 16 April 2014 - 02:59 PM
wojbie, on 16 April 2014 - 02:40 PM, said:
#8
Posted 16 April 2014 - 03:02 PM
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
Posted 16 April 2014 - 03:05 PM
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!!! . 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 endThe 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.
Edited by vedalken254, 16 April 2014 - 09:01 PM.
#10
Posted 16 April 2014 - 10:16 PM
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
Posted 16 April 2014 - 10:27 PM
vedalken254, on 16 April 2014 - 02:59 PM, said:
wojbie, on 16 April 2014 - 02:40 PM, said:
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
There may be update coming if i get my new tlco to work correctly. And Pocket Computer Auto Monitor. But you heard nothing
But thats after i update extended shell ;p
Ahem.. Happy you got it working
Edited by wojbie, 16 April 2014 - 10:29 PM.
#12
Posted 16 April 2014 - 11:21 PM
wojbie, on 16 April 2014 - 10:27 PM, said:
vedalken254, on 16 April 2014 - 02:59 PM, said:
wojbie, on 16 April 2014 - 02:40 PM, said:
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
There may be update coming if i get my new tlco to work correctly. And Pocket Computer Auto Monitor. But you heard nothing
But thats after i update extended shell ;p
Ahem.. Happy you got it working
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
Posted 17 April 2014 - 02:38 AM
#14
Posted 17 April 2014 - 03:27 PM
wojbie, on 16 April 2014 - 10:27 PM, said:
vedalken254, on 16 April 2014 - 02:59 PM, said:
wojbie, on 16 April 2014 - 02:40 PM, said:
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
There may be update coming if i get my new tlco to work correctly. And Pocket Computer Auto Monitor. But you heard nothing
But thats after i update extended shell ;p
Ooh, I want in :3
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users