Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
nezd

Bad argument #1 string expected

Question

Hi!(again)

My program for robot(flashed in eeprom) dont work and causes error i typed in topic title.

Here is the code:

robot = component.proxy(component.list("robot")())
rs = component.proxy(component.list("redstone")())
function getBatteryPercent ()
  local percent = computer.energy() * 100 / computer.maxEnergy()
  return percent
end
function wait(seconds)
  local begin = os.time()
  repeat
    computer.pullSignal(0.05)
  until os.time() - begin >= seconds
end
while true do
  robot.turn(true)
  robot.turn(true)
  robot.move(1)
  while robot.compare() ~= true do
    robot.move(3)
    if robot.detect(5) == true then
      robot.turn(false)
      robot.swing()
      robot.turn(true)
    end
    if robot.detect(4) == true then
      robot.turn(true)
      robot.swing()
      robot.turn(false)
    end
  end
  robot.turn(true)
  robot.move(0)
  robot.turn(true)
  while true do
  if redstone.getInput(1) > 0 then
    if getBatteryPercent() < 20.0 then
      rs.setOutput(0, 15)
    else
      rs.setOutput(0, 0)
    end
    wait(60)
  else
    robot.move(3)
end end end

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

You forgot to specify the direction in a functions swing() and compare()

Ðnd the robot can not move to the sides 4 and 5, for this it is necessary to turn to left/right.

What do you mean about sides 4 and 5? There is no code thats moves it to this sides.

Link to post
Share on other sites
  • 0

Only this way:

robot = component.proxy(component.list("robot")())
rs = component.proxy(component.list("redstone")())
function getBatteryPercent()
  return computer.energy() * 100 / computer.maxEnergy()
end
function wait(seconds)
  local begin = os.time()
  repeat
    computer.pullSignal(0.05)
  until os.time() - begin >= seconds
end
while true do
  robot.turn(true)
  robot.turn(true)
  robot.move(1)
  while not robot.compare(3) do
    robot.move(3)
    robot.turn(false)
    robot.swing(3)
    robot.turn(true)
    robot.turn(true)
    robot.swing(3)
    robot.turn(false)
  end
  robot.turn(true)
  robot.move(0)
  robot.turn(true)
  while true do
    if rs.getInput(1) > 0 then
      if getBatteryPercent() < 20 then
        rs.setOutput(0, 15)
      else
        rs.setOutput(0, 0)
      end
      wait(60)
    else
      robot.move(3)
    end
  end
end
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.