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

Bios 367 error

Started by Entimedation, 19 June 2015 - 12:45 AM
Entimedation #1
Posted 19 June 2015 - 02:45 AM
http://pastebin.com/TjJn8K8u

Link for my code.
Still new and trying to figure things out. Please don't make fun of my coding it was self done and I'm still learning. Constructive criticism only.


I am getting:

bios:367: [string "startup"]:16: '(' expected

I am not sure what this is looking for. I'm guessing it has something to do with either the function before it or the lines after and not the actual ( since it is there. I have not been able to find this error yet however. Any help is greatly appreciated as well as tips on my coding.

E: little more info. This is just a simple attack dump items script. I know I made it more complex than needed but as I stated I'm still learning so wanted to play with the way I code before I go to more complex scripts. This is a fairly easy task so if I can't figure this out I can't do more.
Edited on 19 June 2015 - 02:31 AM
MKlegoman357 #2
Posted 19 June 2015 - 06:07 AM
You've got your function declarations wrong. Same with ifs and for loops. Functions and if, for, while, do, always must be ended with an 'end':


function test ()
  if true then
    for i = 1, 5 do
      print(i)
    end
  end
end

test()

To return a value from a function you almost got it right: you use the 'return' keyword, except that you don't need to call the function again, just pass the value:


function getNumber ()
  return 5
end

Also, you should first declare your functions before calling them, so Lua would know what you want to call. Meaning you should move the if at the top of your code down to the bottom.
flaghacker #3
Posted 19 June 2015 - 06:10 AM
You need to close functions and for loops with end instead of return. Your checkInv for example should look like this (you also had a useless turtle.getItemCount in there):


function CheckInv()
  for i = 1, 16 do
    if turtle.getItemCount(i) > 1 then
      checkInv(true)
    end
  end
end

Your functions also seem to call each other to create a loop effect, that will give give an error after some time. You should use an actual loop instead:

Edit: :ph34r:/>
Edited on 19 June 2015 - 04:15 AM
MKlegoman357 #4
Posted 19 June 2015 - 06:17 AM
Note that functions don't need to always return a value. For example, your 'drainInv()' function returns true, but you never catch nor use the value, meaning that you could remove the 'return' from there. Also, Lua is a case-sensitive language. Functions 'drainInv()' and 'DrainInv()' are two different functions. And one more thing: use local variables. As a beginner it's of course easier for you to make global variables but later you should switch to using local variables. Here's a tutorial for them.

And try to fix the code by yourself and post it here. We'll be able to comment on your code, so you could learn more :lol:/>

EDIT: and welcome to the forums!
Edited on 19 June 2015 - 04:19 AM
Entimedation #5
Posted 19 June 2015 - 12:37 PM
Awesome feedback thanks all. Of course it would be ends, went from coding AHK to this and forgot my basics. I have troubles with the while and if still. I understand when to use which but never quite know what I want my code to do I guess. Anyway I will fix the bugs and post again with any continuing issues. Thanks again for the help! I love how programmers are almost always excited and willing to help others learn!