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

What am I doing wrong.

Started by theoriginalbit, 23 March 2013 - 02:13 AM
theoriginalbit #1
Posted 23 March 2013 - 03:13 AM
I really cannot see what I'm doing wrong here, need some fresh eyes to help me.

code

local oldTerm = {}
for k,v in pairs(term) do
  oldTerm[k] = v
end


term.write = function( ... )
  oldTerm.write( unpack(args) )
end


the top half is perfectly fine. when I add the function into the program it crashes the computer, no error, just black screen. what have I done wrong?
LBPHacker #2
Posted 23 March 2013 - 03:15 AM
"args"? You should not use it. Use … instead.
oldTerm.write(...)

Or set args manually
local args = {...}
theoriginalbit #3
Posted 23 March 2013 - 03:20 AM
oh oops, typo, it should be arg, and I've used it before, but yeh, for some reason it doesn't work in this case, making it unpack( {…} ) seemed to have fixed it… hmmm odd…

thanks. LBPHacker.
theoriginalbit #4
Posted 23 March 2013 - 04:08 AM
Hmmmm interesting…. it doesn't like the table.concat…. actually the only thing it likes there is textutils.serialize({…}) :(/>



local function writePacket(method, ...)
  local msg = method..':'..table.concat( {...}, '|' )
  rednet.broadcast(msg)
end
KaoS #5
Posted 23 March 2013 - 04:39 AM
I dunno, I just tried it and it worked perfectly, you just have to make sure that {…} does not contain anything that cannot concat
theoriginalbit #6
Posted 23 March 2013 - 02:59 PM
I dunno, I just tried it and it worked perfectly, you just have to make sure that {…} does not contain anything that cannot concat
hmmm thats odd. well its just numbers. :/ Full Program
KaoS #7
Posted 23 March 2013 - 11:56 PM
well I tested and troubleshot and found that your problem is on line 49. setCursorBlink is not wrapping right. comment out that line and it works. I'll try and find a way to fix it
KaoS #8
Posted 24 March 2013 - 12:07 AM
ahah. you cannot concatenate booleans man… I would just rewrite the table.concat function to tostring everything. I'll never understand why it doesn't already do that
theoriginalbit #9
Posted 24 March 2013 - 12:41 AM
thanks KaoS its interesting that setCursorBlink was the cause, you would think that table.concat would use a tostring on what its trying to concat…

while you were away NeverCast and I figured out that it was actually something to do with my term overrides and I was getting this error flash up for a split second before the crash… http://puu.sh/2mk8E

I changed the code to make a term object and use term.redirect instead and it actually works perfectly fine (then I started using textutils anyway) as can be seen here… http://pastebin.com/UJWk8Qnv

its actually really odd, because with the term overrides even using print( … ) (in the term.write override) would error…
KaoS #10
Posted 24 March 2013 - 01:39 AM
not bad. I'm glad you got it working. I had an idea while working on your code. take a look


local oldT=term
_G.term=setmetatable({},{__index=function(self,index)
  if type(oldT[index])=="function" then
	return function(...) rednet.broadcast(textutils.serialize({_m=index,_a={...}})) return oldT[index](...) end
  else
	return oldT[index]
  end
end})

to automatically redirect any command. untested but just to show you what I mean
theoriginalbit #11
Posted 24 March 2013 - 01:42 AM
yeh I'm glad I got it working now too :)/> yay CCPresenter is now released! :P/>

yeh nice solution there … you and your awesome metatable stuff :P/> :)/>
KaoS #12
Posted 24 March 2013 - 01:57 AM
thanks, I love environments and metatables. they are what makes Lua so awesome :)/> the main reason I started coding was for re-formatting large amounts of information in projects I was busy with so one of my favorite things is processing a lot through the same intelligent command rather than setting it up for each instance
theoriginalbit #13
Posted 24 March 2013 - 01:59 AM
yeh fair enough :)/> i can see the benefit. but in this case not sure if it would work, since it only seemed that redirecting would fix it, same impl, different method of using it. its odd…
KaoS #14
Posted 24 March 2013 - 02:05 AM
well I got it working on your original paste which didn't redirect once I fixed the concat so it should work. it's not tested though. it's just an idea and at the moment you have a working, good program so no need to fix what's not broken right? congrats on the remote console
theoriginalbit #15
Posted 24 March 2013 - 02:08 AM
yeh exactly… if it aint broke… :P/>

thanks man :)/> I'm happy with it. gunna expand it at some point later…