Jump to content




[Lua] [Error] "attempt to call nil" please help


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

#1 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 19 November 2012 - 08:18 AM

Hey, I'm writed an code an it don't work can you help me?

Error: st:2: attempt to call nil

code:
mon = peripheral.wrap("back")
rin = rs.getBoundledInput( "front" )
mon.setTextScale(2)
while true do
   if colors.test( rin, colors.lime) == true then
	  mon.setCursorPos(1,1)
	  mon.clearLine()
	  mon.write("Zasilanie: 100%")
	 elseif colors.test( rin, colors.yellow) == true then
	  mon.setCursorPos(1,1)
	  mon.clearLine()
	  mon.write("Zasilanie: 75%")
	 elseif colors.test( rin, colors.lightBlue) == true then
	  mon.setCursorPos(1,1)
	  mon.clearLine()
	  mon.write("Zasilanie: 50%")
	 elseif colors.test( rin, colors.magneta) == true then
	  mon.setCursorPos(1,1)
	  mon.clearLine()
	  mon.write("Zasilanie: 25%")
	else
	  mon.setCursorPos(1,1)
	  mon.clearLine()
	  mon.write("Zasilanie: 0%")
   end
  if colors.test( rin, colors.white) == true then
	 mon.setCursorPos(1,2)
	 mon.clearLine()
	 mon.write("Quarry: Wlaczone")
	else
	 mon.setCursorPos(1,2)
	 mon.clearLine()
	 mon.write("Quarry: Wylaczone")
   end
  sleep(0)
end

I'm from poland and this code have Polish language :)/>

#2 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 19 November 2012 - 08:19 AM

Line 2 should be:
rin = rs.getBundledInput( "front" )
instead of:
rin = rs.getBoundledInput( "front" )

The rest of the code should work (only took a quick glance though). :)/>

#3 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 19 November 2012 - 08:20 AM

You misspelled "bundledInput" on line 2. It should be
rin = rs.getBundledInput( "front" )

EDIT: ffsfnsnSN

#4 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 19 November 2012 - 08:20 AM

Is like this :/

Edit: It's writing new error
bios:206: [string "st"]:2: unexpected symbol


Working thanks :)/>

Edited by mibac138, 19 November 2012 - 08:23 AM.


#5 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 19 November 2012 - 08:23 AM

View Postmibac138, on 19 November 2012 - 08:20 AM, said:

Is like this :/

Edit: It's writing new error
bios:206: [string "st"]:2: unexpected symbol
Please post full code again. We can't know what went wrong like this. You probably put a '=', '(' or ')' wrong somewhere.
Edit: ok, glad it works. :)/>

#6 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 19 November 2012 - 08:37 AM

But the update system don't works can you help me? :)/>

Giving full code again:

mon = peripheral.wrap("back")
rin = rs.getBundledInput( "front" )
mon.setTextScale(2)
while true do
   if colors.test( rin, colors.lime) == true then
	  mon.setCursorPos(1,1)
	  mon.clearLine()
	  mon.write("Zasilanie: 100%")
	 elseif colors.test( rin, colors.yellow) == true then
	  mon.setCursorPos(1,1)
	  mon.clearLine()
	  mon.write("Zasilanie: 75%")
	 elseif colors.test( rin, colors.lightBlue) == true then
	  mon.setCursorPos(1,1)
	  mon.clearLine()
	  mon.write("Zasilanie: 50%")
	 elseif colors.test( rin, colors.magneta) == true then
	  mon.setCursorPos(1,1)
	  mon.clearLine()
	  mon.write("Zasilanie: 25%")
    else
	  mon.setCursorPos(1,1)
	  mon.clearLine()
	  mon.write("Zasilanie: 0%")
   end
  if colors.test( rin, colors.white) == true then
	 mon.setCursorPos(1,2)
	 mon.clearLine()
	 mon.write("Quarry: Wlaczone")
    else
	 mon.setCursorPos(1,2)
	 mon.clearLine()
	 mon.write("Quarry: Wylaczone")
   end
  sleep(0,5)
end


#7 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 19 November 2012 - 08:52 AM

Could you clarify what you mean with ' didn't work '? Anyway, there is one mistake at the one but last line:
sleep(0,5)
should be:
sleep(0.5)

The comma separates the parameters and only the first one is being used, so you'd sleep '0' seconds instead of '0.5'. Note that sleep(0) actually sleeps like 0.05 seconds or something.

#8 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 19 November 2012 - 08:53 AM

Second-to-last line:
sleep(0,5)

should be

sleep(0.5)

EDIT: it keeps happening

#9 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 19 November 2012 - 08:56 AM

Don't working
For example:
I'm run the program and quarry is off and when I'm turning this on it's writing querry is off and i have to restart program to update this
Please help (again :)/>)

#10 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 19 November 2012 - 08:58 AM

Oh, move line 2 in the while loop. So this line:
rin = rs.getBundledInput( "front" )
should go right under
while true do


#11 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 19 November 2012 - 09:00 AM

Very very mouch thanks working! :)/>

#12 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 19 November 2012 - 09:04 AM

Good. :D/> Just to explain it a bit. When you do that line, rin becomes the current status of the bundled cable (a numerical value), so you'd want to update that in every iteration of the loop. Now you only updated it once at the beginning of the program. :D/>

Off topic:

View PostKingdaro, on 19 November 2012 - 08:53 AM, said:

Second-to-last line:
sleep(0,5)

should be

sleep(0.5)

EDIT: it keeps happening
:D/> I am 'studying' right now, which means that I'm behind my laptop desperately in search of a distraction. :)/>

#13 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 19 November 2012 - 09:33 AM

View PostOrwell, on 19 November 2012 - 09:04 AM, said:

Good. :D/> Just to explain it a bit. When you do that line, rin becomes the current status of the bundled cable (a numerical value), so you'd want to update that in every iteration of the loop. Now you only updated it once at the beginning of the program. :D/>

Off topic:

View PostKingdaro, on 19 November 2012 - 08:53 AM, said:

Second-to-last line:
sleep(0,5)

should be

sleep(0.5)

EDIT: it keeps happening
:D/> I am 'studying' right now, which means that I'm behind my laptop desperately in search of a distraction. :)/>

It's new problem it's writing bit:40: double expected, got nil (It's happends only when "Zasilanie" - Power Level is changing)

#14 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 19 November 2012 - 09:39 AM

Change this line:
elseif colors.test( rin, colors.magneta) == true then
into this:
elseif colors.test( rin, colors.magenta) == true then
You spelled magenta wrong. :D/> So you passed a nil value to colors.test() which later on probably did a shift operation with it using the bit api, which led to that error. :)/>

#15 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 19 November 2012 - 09:51 AM

Thanks :)/>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users