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

[ERROR] Bag Argument!

Started by Dolphindalt, 13 August 2012 - 02:42 AM
Dolphindalt #1
Posted 13 August 2012 - 04:42 AM
I'm trying to make a turtle controller but I cant find my error!

'134shell:65: bad argument: string exspected, got nil.

Heres the code…
  1. write('Please enter the bot's id: ')
  2. bot = tonumber(read()) – the ID of the turtle
  3. shell.run('clear') –clear the screen
  4. mode = 0 – set the mode to dig
  5. rednet.open('right') – open wifi port
  6. while true do – start infinite loop
  7. event, key = os.pullEvent() – wait for input
  8. shell.run('clear') – clear the screen again :P/>/>
  9. if key == 's' then –if the s button is pressed
  10. rednet.send(bot, 'backward')– send message for down button
  11. print('Backward') – write on the screen
  12. end
  13. if key == 'a' then – left
  14. rednet.send(bot, 'left')
  15. print('Left')
  16. end
  17. if key == 'w' then –up
  18. rednet.send(bot, 'forward')
  19. print('Forward')
  20. end
  21. if key == 'd' then – right
  22. rednet.send(bot, 'right')
  23. print('Right')
  24. end
  25. if key == 200 then
  26. rednet.send(bot, 'up')
  27. print('Up')
  28. end
  29. if key == 208 then
  30. rednet.send(bot, 'down')
  31. print('Down')
  32. end
  33. if key == ' ' then –if the key is the spacebar
  34. if mode == 0 then – if on digmode
  35. rednet.send(bot, 'dig') – send message to dig
  36. print('Dig') – write it
  37. elseif mode == 1 then – if on placemode
  38. rednet.send(bot, 'place') – send message to place block
  39. print('Place') –write
  40. end
  41. end
  42. if key == 203 then –if the key is left
  43. mode = 0 – set to digmode
  44. print('Dig mode selected.') –write it
  45. end
  46. if key == 205 then – if right
  47. mode = 1 – set to placemode
  48. print('Place mode selected.') –write
  49. end
  50. if key == 29 then –if the left ctrl is pressed
  51. rednet.send(bot, 'rs') – send message to enable redstone
  52. print('Redstone activated.')– write
  53. end
  54. end

Please help me get a fix!
Edit: Were it said enter ids, i entered the correct ones.
Luanub #2
Posted 13 August 2012 - 04:48 AM
Its due to line 33. The space bar is key # 57 not ' '.

I would also change your if statements. Instead of doing multiple if's to check the 1 input do 1 if with some elseif's. It will work better in the long run. You can add an and statement to check your modes as well.

Example

if key == 57 and mode == 0 then --if the key is the spacebar and if on digmode
  rednet.send(bot, 'dig') -- send message to dig
  print('Dig') -- write it
elseif key == 57 and mode == 1 then -- if on placemode
  rednet.send(bot, 'place') -- send message to place block
  print('Place') --write
elseif key == 203 then --if the key is left
  mode = 0 -- set to digmode
  print('Dig mode selected.') --write it
end

I would also use double quotes " instead of singles '

Also if you want to check for say both wasd and the arrow keys use an or

if key == 30 or key == 203 then -- left arrow key or "a" key pressed

Here is a chart for the key codes http://www.minecraft.../wiki/Key_Codes
Dolphindalt #3
Posted 13 August 2012 - 05:12 AM
I did what you said but now it says

"bios:206: [string "startup"]:55: '<eof>' exspected"

I'm kinda a noob at this. It would be nice to know how to read these error codes.
BigSHinyToys #4
Posted 13 August 2012 - 05:16 AM
I did what you said but now it says

"bios:206: [string "startup"]:55: '<eof>' exspected"

I'm kinda a noob at this. It would be nice to know how to read these error codes.
my
guess based on what you have said is that you put a end after every elseif you only need one per IF not counting ElseIF's like his example. the <eof> error is telling you there ate too many end statements you need to pin where they are and remove them.
Luanub #5
Posted 13 August 2012 - 05:17 AM

'134shell:65: bad argument: string exspected, got nil.
This means that instead of getting a string like the function expected it got nil or nothing.

"bios:206: [string "startup"]:55: '<eof>' exspected"

Is usually do to an extra or missing end somewhere in your code. Can I get a copy of the current updated code and I'll see if I can't find the error. The number in bold is the line of code that it is having a problem, it doesn't always mean that it is incorrect. But its a good place to start.
Dolphindalt #6
Posted 13 August 2012 - 05:21 AM
I'm realy a noob at this, how do I get my code off the computer?

Note: I didnt add any ends I just did what you said.
Luanub #7
Posted 13 August 2012 - 05:23 AM
goto %appdata% if your on a windows machine. Then goto .minecraft/saves/worldname/computer/computer id number and the files should be there

also for future reference

http://www.computercraft.info/forums2/index.php?/topic/118-codex-of-error-slaying-2/
Dolphindalt #8
Posted 13 August 2012 - 05:27 AM
I found out what was wrong. I was missing an end but now it says:

'134shell:65: bad argument: string exspected, got nil.

Also will I be able to get it off the computer on a multi player server?
Dolphindalt #9
Posted 13 August 2012 - 05:44 AM
Tils is frustrating :P/>/> If you have any codes that let you control turtles let me know, I'm done with this one!