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

Cobblestone Generator Program Error

Started by TheBrownBus, 14 October 2012 - 04:18 PM
TheBrownBus #1
Posted 14 October 2012 - 06:18 PM
So, I have this program that's supposed to collect Cobblestone from a simple lava/water generator and display progress on a 4x2 monitor. But when I try to run the program, I get an error saying: "bios:328: [string "Cobblestone"]:3: 'end' expected (to close 'function' at line 1)". What is going wrong?

Code: http://pastebin.com/JQxajwH5
Doyle3694 #2
Posted 14 October 2012 - 06:25 PM
Wait now….. You're returning a function that's not named and defining it on the go? OK, seems legit…

That counter() function makes no sense, I made a cobblegen without display and It was only simple code. Adding a monitor saying how much cobble there is don't need to be that complicated?
Doyle3694 #3
Posted 14 October 2012 - 06:26 PM
btw, your indentation make my eyes hurt
PixelToast #4
Posted 14 October 2012 - 06:58 PM
yea, might want to scrap the counter function entirely
TheBrownBus #5
Posted 14 October 2012 - 07:45 PM
Just delete it, or should I replace it with something?
PixelToast #6
Posted 14 October 2012 - 07:47 PM
Just delete it, or should I replace it with something?
wherever you use that function just use i=i+1 instead
TheBrownBus #7
Posted 14 October 2012 - 07:55 PM
I use it in the

local iterator = counter()
line, and if I replace

counter()
with

i=i+1
I get "Unexpected Symbol"
Doyle3694 #8
Posted 14 October 2012 - 07:59 PM
oh yeah, no ='s in declarations. do:

local functon counter()
   i = i+1
end

local iterator = counter
I'm unexperienced in giving variables functions, but I think the () will actually call the function, so when you call iterator use

iterator()
BrolofTheViking #9
Posted 14 October 2012 - 08:09 PM
If I'm understanding this correctly, you basically want something that will return i, and increase i by 1 every time it is referenced, right?
like i++ in java.
Or are you trying to do it the other way around, and increase it by one, then return the value? (++i in java)
TheBrownBus #10
Posted 14 October 2012 - 08:10 PM
oh yeah, no ='s in declarations. do:

local functon counter()
   i = i+1
end

local iterator = counter
I'm unexperienced in giving variables functions, but I think the () will actually call the function, so when you call iterator use

iterator()
When I do that, the programs hangs.
Doyle3694 #11
Posted 14 October 2012 - 08:11 PM
are you sure that's excactly the point it hangs?
TheBrownBus #12
Posted 14 October 2012 - 08:11 PM
If I'm understanding this correctly, you basically want something that will return i, and increase i by 1 every time it is referenced, right?
like i++ in java.
Or are you trying to do it the other way around, and increase it by one, then return the value? (++i in java)
i++
TheBrownBus #13
Posted 14 October 2012 - 08:12 PM
are you sure that's excactly the point it hangs?
It never hung until I put your code in.
TheBrownBus #14
Posted 14 October 2012 - 08:19 PM
Just to clarify, the counter() declaration at the beginning has been removed, and where I had "local iterator = counter()", I now have

local function counter()
    i=i+1
end
local iterator = counter
Doyle3694 #15
Posted 14 October 2012 - 08:22 PM
have you changed all your iterator's to iterator()
TheBrownBus #16
Posted 14 October 2012 - 08:24 PM
have you changed all your iterator's to iterator()
They were already like that.
TheBrownBus #17
Posted 14 October 2012 - 08:26 PM
Should I change

local iterator = counter
to

local iterator = counter()
BrolofTheViking #18
Posted 14 October 2012 - 08:30 PM
do it like this

function counter()

i = i + 1
return (i - 1)
I didn't test it, but that should do it.
then you could just replace iterator with counter()
if you use iterator = counter(), it will just store the value of what counter returns, and will never call counter again.
you want to call counter each time, so replace iterator() with counter()
Doyle3694 #19
Posted 14 October 2012 - 08:34 PM
I have no experience with storing functions in variables.
TheBrownBus #20
Posted 14 October 2012 - 08:38 PM
do it like this

function counter()

i = i + 1
return (i - 1)
I didn't test it, but that should do it.
then you could just replace iterator with counter()
if you use iterator = counter(), it will just store the value of what counter returns, and will never call counter again.
you want to call counter each time, so replace iterator() with counter()
So scrap iterator altogether, and just use counter?
Lyqyd #21
Posted 14 October 2012 - 08:39 PM
Why use an iterator for something so simple? Just write out 1-9.
TheBrownBus #22
Posted 14 October 2012 - 08:41 PM
Why use an iterator for something so simple? Just write out 1-9.
Can you show an example of how I would put that in my code?
TheBrownBus #23
Posted 14 October 2012 - 08:46 PM
Updated code: http://pastebin.com/1VGFG0Ny
Lyqyd #24
Posted 14 October 2012 - 08:47 PM
You have nine of these in the printing output section:


modStr(turtle.getItemCount(iterator()))

Change the first one to:


modStr(turtle.getItemCount(1))

etc. This isn't your code, is it? Why not ask the original author for help?
TheBrownBus #25
Posted 14 October 2012 - 08:52 PM
You have nine of these in the printing output section:


modStr(turtle.getItemCount(iterator()))

Change the first one to:


modStr(turtle.getItemCount(1))

etc. This isn't your code, is it? Why not ask the original author for help?
I don't know who the original author is.
since I'm just numbering them now, should I scrap the counter() function?
BrolofTheViking #26
Posted 14 October 2012 - 08:58 PM
In your updated code, you got rid of the definition of counter(), but still referenced it.
But yes, if you're just going to number each one, get rid of every time counter() appears, and replace it with the number you want to be there.
TheBrownBus #27
Posted 14 October 2012 - 09:01 PM
Alright, this is the latest version of code, but it's hanging.

http://pastebin.com/sAfcE7M7
TheBrownBus #28
Posted 14 October 2012 - 09:03 PM
Nevermind, I fixed it.
TheBrownBus #29
Posted 14 October 2012 - 09:13 PM
It works! Thanks for the help!