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

troubleshooting - i must be blind, cant see the error

Started by Dustmuz, 11 January 2015 - 02:28 AM
Dustmuz #1
Posted 11 January 2015 - 03:28 AM
Hello fellow people of the Earth..

i ran into a problem, i have a code, that i think should work, but its giving me an error, where i dont really see one..
is it just me, that is blind, or have i made an error somewhere

im getting

unexpected symbol on line 236
the first line of the code tag is line 223 of my program, i got you the entire function.


local function auto()
  mon.setBackgroundColor(black)
  for i=3,15 do
	mon.setCursorPos(22,i)
	mon.write("				 ")
  end
  print("auto")
  while true do
    local maxenergy = 10000000
    local energy = r.getEnergyStored()
    energyperc = math.floor((energy / maxenergy) * 100)
    if energyperc <= 5 then
      r.setAllControlRodLevels(0)
    elseif energyperc >= 6 and <=10 then
      r.setAllControlRodLevels(5)
    elseif energyperc >= 11 and <=15 then
      r.setAllControlRodLevels(10)
    elseif energyperc >= 16 and <=20 then
      r.setAllControlRodLevels(15)
    elseif energyperc >= 21 and <=25 then
      r.setAllControlRodLevels(20)
    elseif energyperc >= 26 and <=30 then
      r.setAllControlRodLevels(25)
    elseif energyperc >= 31 and <=35 then
      r.setAllControlRodLevels(30)
    elseif energyperc >= 36 and <=40 then
      r.setAllControlRodLevels(35)
    elseif energyperc >= 41 and <=45 then
      r.setAllControlRodLevels(40)
    elseif energyperc >= 46 and <=50 then
      r.setAllControlRodLevels(45)
    elseif energyperc >= 51 and <=55 then
      r.setAllControlRodLevels(50)
    elseif energyperc >= 56 and <=60 then
      r.setAllControlRodLevels(55)
    elseif energyperc >= 61 and <=65 then
      r.setAllControlRodLevels(65)
    elseif energyperc >= 66 and <=70 then
      r.setAllControlRodLevels(70)
    elseif energyperc >= 71 and <=75 then
      r.setAllControlRodLevels(75)
    elseif energyperc >= 76 and <=80 then
      r.setAllControlRodLevels(80)
    elseif energyperc >= 81 and <=85 then
      r.setAllControlRodLevels(95)
    elseif energyperc >= 86 and <=90 then
	r.setAllControlRodLevels(90)
    elseif energyperc >= 91 and <=95 then
      r.setAllControlRodLevels(95)
    elseif energyperc >= 96 and <=99  then
      r.setAllControlRodLevels(100)
    end
  end
end
Edited on 11 January 2015 - 02:49 AM
valithor #2
Posted 11 January 2015 - 03:36 AM
-snip

I might just be missing it, but could you mark in the code which line is 236.
Dustmuz #3
Posted 11 January 2015 - 03:41 AM
Sure :D/>

elseif energyperc >= 6 and <=10 then
Dustmuz #4
Posted 11 January 2015 - 03:48 AM
i see that i missed and end at the end, not closing the function
original post edited
Edited on 11 January 2015 - 02:51 AM
valithor #5
Posted 11 January 2015 - 03:57 AM
I believe your error is the energyperc >= 6 and <= 10, you need to put the variable there twice.

The "and" operator will see if both things on both side equal true, it does not do what you are trying to use it to do. What that is litterally trying to see is if energyperc is greater than or equal to 6, and then there is a unfinished statement on the otherside of the and which is causing the error you are seeing.

You could change that to elseif energyperc >= 6 and energyperc <= 10 then
Edited on 11 January 2015 - 03:00 AM
KingofGamesYami #6
Posted 11 January 2015 - 03:58 AM
-snip-

Edit: I'm wrong, and ninja'd
Edited on 11 January 2015 - 02:59 AM
Dustmuz #7
Posted 11 January 2015 - 04:20 AM
Valithor was right on this one :D/>

does any of you have a piece of code i could steal

something that checks if a file exists, if it does, delete it, and download it again from pastebin
KingofGamesYami #8
Posted 11 January 2015 - 04:23 AM

if fs.exists( file ) then
  fs.delete( file )
  local r = http.get( "url" )
  if r then
    local file = fs.open( file, "w" )
    file.write( r.readAll() )
    file.close()
  end
end
Dustmuz #9
Posted 11 January 2015 - 05:13 AM
Thanks King :)/>
lucy-san #10
Posted 11 January 2015 - 11:19 AM
Fixed your Frankenstein =D


local function auto()
  mon.setBackgroundColor(black)
  for i=3,15 do
        mon.setCursorPos(22,i)
        mon.write("                              ")
  end
  print("auto")

  local maxenergy = 10000000
  while true do
    local energy = r.getEnergyStored()
    energyperc = math.floor((energy / maxenergy) * 100)

    if energyperc > 60 then
      r.setAllControlRodLevels(enegryperc + 5 - energyperc % 5)
    else
      r.setAllControlRodLevels(energyperc - energyperc % 5)
    end
  end
end