Code: http://pastebin.com/JQxajwH5
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Cobblestone Generator Program Error
Started by TheBrownBus, 14 October 2012 - 04:18 PMPosted 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
Code: http://pastebin.com/JQxajwH5
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?
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?
Posted 14 October 2012 - 06:26 PM
btw, your indentation make my eyes hurt
Posted 14 October 2012 - 06:58 PM
yea, might want to scrap the counter function entirely
Posted 14 October 2012 - 07:45 PM
Just delete it, or should I replace it with something?
Posted 14 October 2012 - 07:47 PM
wherever you use that function just use i=i+1 insteadJust delete it, or should I replace it with something?
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"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()
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)
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)
Posted 14 October 2012 - 08:10 PM
When I do that, the programs hangs.oh yeah, no ='s in declarations. do:I'm unexperienced in giving variables functions, but I think the () will actually call the function, so when you call iterator uselocal functon counter() i = i+1 end local iterator = counter
iterator()
Posted 14 October 2012 - 08:11 PM
are you sure that's excactly the point it hangs?
Posted 14 October 2012 - 08:11 PM
i++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)
Posted 14 October 2012 - 08:12 PM
It never hung until I put your code in.are you sure that's excactly the point it hangs?
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
Posted 14 October 2012 - 08:22 PM
have you changed all your iterator's to iterator()
Posted 14 October 2012 - 08:24 PM
They were already like that.have you changed all your iterator's to iterator()
Posted 14 October 2012 - 08:26 PM
Should I change
local iterator = counter
to
local iterator = counter()
Posted 14 October 2012 - 08:30 PM
do it like this
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()
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()
Posted 14 October 2012 - 08:34 PM
I have no experience with storing functions in variables.
Posted 14 October 2012 - 08:38 PM
So scrap iterator altogether, and just use counter?do it like thisI didn't test it, but that should do it.function counter() i = i + 1 return (i - 1)
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()
Posted 14 October 2012 - 08:39 PM
Why use an iterator for something so simple? Just write out 1-9.
Posted 14 October 2012 - 08:41 PM
Can you show an example of how I would put that in my code?Why use an iterator for something so simple? Just write out 1-9.
Posted 14 October 2012 - 08:46 PM
Updated code: http://pastebin.com/1VGFG0Ny
Posted 14 October 2012 - 08:47 PM
You have nine of these in the printing output section:
Change the first one to:
etc. This isn't your code, is it? Why not ask the original author for help?
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?
Posted 14 October 2012 - 08:52 PM
I don't know who the original author is.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?
since I'm just numbering them now, should I scrap the counter() function?
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.
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.
Posted 14 October 2012 - 09:01 PM
Posted 14 October 2012 - 09:03 PM
Nevermind, I fixed it.
Posted 14 October 2012 - 09:13 PM
It works! Thanks for the help!