202 posts
Posted 24 December 2013 - 07:33 PM
The following problem has been fixed. Please scroll down to the 9th reply to see my new problem. :D/>
I'm working on a turtle tunnel program. Right now I'm trying to make it so that the user can specify and fuel slot, put fuel in that slot, and then the fuel in that slot won't be dumped into a chest when the turtle inventory gets full. My problem is with that last step. When I run the program and make the turtle run the drop off function for the first time, it works fine. However, I am trying to allow the user to save the settings they chose for the tunnel to another file so they don't have to type them in every time. When I save the setting of the slot the fuel should be placed in, and then run the program using the saved settings, the fuel gets dumped into the chest. From debugging using print, I know that the program knows what the slot is, but it still dumps the fuel.
Current Code:
http://pastebin.com/U1XL1dJ9The parts that this post concerns are the useFuel function(lines 72-95), the dropoff function(lines 97-114), the part where I load the settings(lines 297-311), and the part where I save the settings(lines 443-465).
Help is appreciated!
Thanks! :D/>
Edited on 29 December 2013 - 04:08 PM
91 posts
Posted 25 December 2013 - 12:34 AM
Are you using quotes in your settings file? If it says
"some setting"
in your file then what its actually checking for is
\"some setting\"
Also, wouldn't it just be easier to have a list of variables at the top for the user to define?
On another note: if you use string.lower() on your inputs you only have to check for one possible variation.
local input = string.lower(read())
"hello", "Hello", "HeLlO" all become "hello"
Edited on 24 December 2013 - 11:36 PM
202 posts
Posted 25 December 2013 - 12:39 AM
Do you mean like have a list of variables at the top of the program and the user can just edit the program and change them? This might not be what you mean but if it is then it doesn't really help me. I understand that this may be easier to do but it doesn't accomplish what I want the program to do.
And thanks for the tip about string.lower()
I'm still having trouble with my previous issue but I wanted to continue working so I made a function that will stack any of the coal it mines with the coal in the fuel slot. However, I'm also having trouble with this. When I try to call the stackFuel function it gives me this error;
turtle:22: Expected Number
I think this means I've used one of the methods from the turtle api incorrectly but I can't figure out how. The four methods I've used in the stackFuel function are turtle.select(), turtle.compareTo(), turtle.transferTo(), and turtle.getItemCount(). I fear this may also be related to the program not reading that the fuelSlot is correctly.
91 posts
Posted 25 December 2013 - 01:08 AM
Have you tested to make sure its reading the settings? Try something like importing your settings from the file then print the variables you stored them in to see if they have the correct values. If they have the correct values, then you know the problem is somewhere else.
202 posts
Posted 25 December 2013 - 02:32 AM
I tried printing out all the variables it should've read from the file and everything was fine. It read and printed them just how they should have. Now I've no idea what the problem is.
91 posts
Posted 25 December 2013 - 04:15 AM
Does it raise any errors?
Also, its best to use local variables as much as possible. An easy way for you to add them in would be to do
local variable = ""
at the top for each variable. This essentially makes a blank variable. There may be a better way to do this but I'm not sure.
202 posts
Posted 25 December 2013 - 01:17 PM
No, it does not raise any errors. As I said in the original post, it just dumps the fuel like it's not supposed to.
227 posts
Location
Germany
Posted 25 December 2013 - 06:17 PM
I think I fixed it.
You put the tonumber() in the write function of the file, but not in the read function.
Any line that gets read will return a string, even if you write a number to the file.
Just put a tonumber(h.readLine()) on the "fuelSlot = " line.
http://pastebin.com/6C2x2ptm
202 posts
Posted 26 December 2013 - 03:31 AM
Thank you so much, this worked perfectly. I can't believe I didn't think of that.
However, I am still having trouble with my stackFuel function. Any thoughts on that?
Nevermind I fixed it. Thanks so much for your help! :D/>
Edited on 26 December 2013 - 02:42 AM
202 posts
Posted 26 December 2013 - 05:04 PM
To prevent from spam, I'm just going to post this on this topic since it has to do with the same program. I've fixed my previous issues, but I'm now having an issue with the enderchest part of the runChest() function. It works perfectly the first time I run it, however the second time I run it(not loading from the settings file) it doesn't prompt me to use enderchests. Using print I found that when it checks to see if useEnder is already chosen, it thinks that useEnder is 'n'. I don't know why this is and it almost seems like it is carrying over what the variable is from the previous run of the program.
Code:
http://pastebin.com/VbzaRCbf
Edited on 29 December 2013 - 01:47 AM
227 posts
Location
Germany
Posted 28 December 2013 - 08:15 AM
After you program finishes the variable useEnder is still given.
So when your program checks if useEnder is correct (y/n Y/N), it is.
You can just delete the variable after the program has finished with
useEnder = nil
http://pastebin.com/6C2x2ptmlike this
202 posts
Posted 29 December 2013 - 01:50 AM
Thank you for the reply, however this did not seem to fix my problem. I still must restart the turtle after running the program one time for the program to work correctly.
Code:
http://pastebin.com/VbzaRCbf
Edited on 29 December 2013 - 01:48 AM
208 posts
Posted 29 December 2013 - 03:01 AM
You could try localising the variable.
7508 posts
Location
Australia
Posted 29 December 2013 - 04:30 AM
The following problem has been fixed. Please scroll down to the 9th reply to see my new problem. :D/>
If you're not going to add the problem to the OP then you should link the reply, to link it just click the number link on the right-hand side of the reply, it will bring up a box containing the direct URL.
Edited on 29 December 2013 - 03:30 AM
227 posts
Location
Germany
Posted 29 December 2013 - 07:46 AM
UseEnder = nil works fine for me. Did you use the fixed version?
202 posts
Posted 29 December 2013 - 05:07 PM
The following problem has been fixed. Please scroll down to the 9th reply to see my new problem. :D/>
If you're not going to add the problem to the OP then you should link the reply, to link it just click the number link on the right-hand side of the reply, it will bring up a box containing the direct URL.
I'm sorry, I didn't realize that would be such a big problem…
However, thanks to wieselkatze, my problem is solved.
Thanks so much! :D/>
Edited on 29 December 2013 - 04:07 PM