Jump to content




What am I doing wrong.


  • You cannot reply to this topic
14 replies to this topic

#1 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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?

#2 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 23 March 2013 - 03:15 AM

"args"? You should not use it. Use ... instead.
oldTerm.write(...)

Or set args manually
local args = {...}


#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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.

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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


#5 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

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

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 23 March 2013 - 02:59 PM

View PostKaoS, on 23 March 2013 - 04:39 AM, said:

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

#7 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

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

#8 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

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

#9 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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

#10 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

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

#11 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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

#12 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

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

#13 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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

#14 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

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

#15 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users