-- NS TECH AUTO HARVEST
-- DO NOT EDIT CODE WITHOUT PERMISSION
term.setTextColor(colors.yellow)
while true do
term.clear()
term.setCursorPos(1,1)
print("RUNNING NS TECH CODE - EDITING NOT PERMITTED")
print("NS Tech AutoHarvest v1.0")
print("---------------------------------------------------")
minutes(30)
seconds(00)
clocktime = minutes+seconds
repeat
if seconds == 0 then
minutes = minutes-1
seconds = 60
end
if minutes == -1 then
break
end
seconds = seconds-1
if seconds < 10 then
zero = 0
else
zero = ""
end
sleep(1)
print("Next harvest in "..minutes..":"..zero..seconds "minutes")
until minutes == -1
sleep(0.2)
print("Harvest in process")
sleep(5)
rs.setOutput("back", true)
sleep(8)
rs.setOutput("back", false)
sleep(5)
shell.run("startup")
end
input = read("")
if input == "harvest" then
rs.setOutput("back", true)
sleep(5)
rs.setOutput("back", false)
shell.run("startup")
if input == "exit" then
return
end
else
print("Invalid Command")
end
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Bios:202: Vm Error: | No Clue What I Am Doing..
Started by TylerTharp, 01 August 2013 - 09:12 PMPosted 01 August 2013 - 11:12 PM
I need help with this, cant seem to find the error source
Edited on 01 August 2013 - 10:16 PM
Posted 01 August 2013 - 11:21 PM
Your issue is on lines 10/11, where you are trying to make variables by using parentheses (which doesn't work):
Change that to:
You have another issue on line 28:
You forgot to put ".." in between seconds and "minutes". Change it to this:
Fix those things and it runs fine.
minutes(30)
seconds(00)
Change that to:
minutes = 30
seconds = 0
You have another issue on line 28:
print("Next harvest in "..minutes..":"..zero..seconds "minutes")
You forgot to put ".." in between seconds and "minutes". Change it to this:
print("Next harvest in "..minutes..":"..zero..seconds.."minutes")
Fix those things and it runs fine.
Posted 01 August 2013 - 11:23 PM
Your issue is on lines 10/11, where you are trying to make variables by using parentheses (which doesn't work):minutes(30) seconds(00)
Change that to:minutes = 30 seconds = 0
You have another issue on line 28:print("Next harvest in "..minutes..":"..zero..seconds "minutes")
You forgot to put ".." in between seconds and "minutes". Change it to this:print("Next harvest in "..minutes..":"..zero..seconds.."minutes")
Fix those things and it runs fine.
Thanks for the quick reply and help!
Posted 01 August 2013 - 11:34 PM
Problem solved
Edited on 01 August 2013 - 09:56 PM
Posted 01 August 2013 - 11:57 PM
I got help with the timer, how could I take out the seconds and have it update every minute and clear the line above it?
Would something along these lines work?
Would something along these lines work?
-- NS TECH AUTO HARVEST
-- DO NOT EDIT CODE WITHOUT PERMISSION
term.setTextColor(colors.yellow)
while true do
term.clear()
term.setCursorPos(1,1)
print("RUNNING NS TECH CODE - EDITING NOT PERMITTED")
print("NS Tech AutoHarvest v1.0")
print("---------------------------------------------------")
minutes = 30
seconds = 0
clocktime = minutes+seconds
repeat
minutes = minutes-1
end
if minutes == -1 then
break
end
sleep(1)
print("Next harvest in "..minutes..":"..zero..seconds.." minutes")
until minutes == -1
sleep(0.2)
print("Harvest in process")
sleep(5)
rs.setOutput("back", true)
sleep(8)
rs.setOutput("back", false)
sleep(5)
shell.run("startup")
end
input = read("")
if input == "harvest" then
rs.setOutput("back", true)
sleep(5)
rs.setOutput("back", false)
shell.run("startup")
if input == "exit" then
return
end
else
print("Invalid Command")
end
Edited by
Posted 02 August 2013 - 12:20 AM
Your code is a bit messy and I found that trying to fix it was harder than just starting from scratch. So I've gone ahead and written a very simple version of your code. Please read it to understand and don't just copy it :)/>
Pastebin: http://pastebin.com/LtJjski6
Pastebin: http://pastebin.com/LtJjski6
local wait_time = 30*60 --#This is the amount of time that we should wait between harvesting
local time_remaining = 0 --#This is our time remaining, in seconds. We can convert this into minutes by simply rounding down the result of time_remaining/60
term.setTextColor(colors.yellow)
local function wait() --#This function will wait for the amount of time given through wait_time and write the progress as it goes.
time_remaining = wait_time --#Make sure to reset our timer
print("RUNNING NS TECH CODE - EDITING PROHIBITED")
print("NS Tech AutoHarvest v1.0")
print("-----------------------------------------")
while not sleep(1) and time_remaining > 0 do --#This will sleep for one second and check if the time_remaining is more than 0
term.setCursorPos(1,4)
term.clearLine()
local minutes = math.floor(time_remaining/60) --#This is the minutes left
local seconds = math.floor(time_remaining%60) --#This is the seconds left
print("Time remaining: " .. minutes .. " minutes and " .. seconds .. " seconds.")
time_remaining = time_remaining - 1
end
end
while true do
term.clear()
term.setCursorPos(1,1)
wait()
local command_entered = false --#We'll keep track of whether or not a command has been entered through this variable
while not command_entered do --#While a correct command has not been entered, loop forever
write("Please enter a command: ")
local input = read()
if input == "harvest" then
rs.setOutput("back", true)
print("Harvesting...")
sleep(5)
print("Harvest complete! Press any key to continue.")
os.pullEvent("key")
rs.setOutput("back", false)
command_entered = true
else
print("Invalid command. Please try again")
end
end
end
Posted 03 August 2013 - 12:43 AM
Sorry for multiple posts about this program I am working on
I originally had this program setup to have an input after it was finished with the harvest, I want to get rid of that. But everytime I do I get this error.
Code:
I originally had this program setup to have an input after it was finished with the harvest, I want to get rid of that. But everytime I do I get this error.
Code:
local wait_time = 30*60
local time_remaining = 0
term.setTextColor(colors.yellow)
local function wait()
while true do
time_remaining = wait_time
print("RUNNING NS TECH CODE - EDITING PROHIBITED")
print("NS Tech AutoHarvest v1.0")
print("-----------------------------------------------------")
while not sleep(1) and time_remaining > 0 do
term.setCursorPos(1,4)
term.clearLine()
local minutes = math.floor(time_remaining/60)
local seconds = math.floor(time_remaining%60)
print("Next harvest in " .. minutes .. " minutes and " .. seconds .. " seconds.")
time_remaining = time_remaining - 1
shell.run("startup")
end
end
end
while true do
shell.run("startup")
end
Posted 03 August 2013 - 05:04 AM
I have a feeling that this is not the startup file (you haven't told use which file is this, I have every right to guess). Thing is, the most of this code is in the local function wait, which never gets called. Apart from that it only runs the startup endlessly. Post your whole code (and the startup code as well).
Posted 03 August 2013 - 11:40 PM
That is the startup file.
Posted 04 August 2013 - 12:30 AM
Hi Tyler. For future reference, it would be awesome if you could keep questions related to the same program to one thread. This way we can keep the AaP forum looking clean, and also pros can know what you've already done :)/>
Anyway, you've got some strange things going on in this program. The first thing I noticed is the shell.run("startup"). Why are you doing this? The program is already in a while loop, so running startup over and over again will just crash the computer. The second is that you made a wait function when it's really not necessary. Just have a while loop and get rid of the function, and things will be much nicer. My guess is that you took the wait function from my script, but it's not really the same thing. My wait function does not have any loops inside of it, whereas yours does.
Anyway, you've got some strange things going on in this program. The first thing I noticed is the shell.run("startup"). Why are you doing this? The program is already in a while loop, so running startup over and over again will just crash the computer. The second is that you made a wait function when it's really not necessary. Just have a while loop and get rid of the function, and things will be much nicer. My guess is that you took the wait function from my script, but it's not really the same thing. My wait function does not have any loops inside of it, whereas yours does.
Posted 04 August 2013 - 12:40 AM
Sorry about the multiple threads, I just noticed that you guys were trying to keep the forum clean.
I honestly do not know why I added the shell.run("startup"). I think it was because I confused myself. I have removed both the shell.run and the wait function and it seems to work fine now. But I do have one more question about it, I dont know if it is a mod thing or what, but it seems that if a player leaves the chunk the program restarts. It makes sense if it does I just didnt know if that was the case.
I honestly do not know why I added the shell.run("startup"). I think it was because I confused myself. I have removed both the shell.run and the wait function and it seems to work fine now. But I do have one more question about it, I dont know if it is a mod thing or what, but it seems that if a player leaves the chunk the program restarts. It makes sense if it does I just didnt know if that was the case.
Posted 04 August 2013 - 12:50 AM
Whoops, it seems help is still needed. I stupidly forgot to add the potion of the code that activates the redstone. Im not sure how to go about doing that, I thought that adding a simple rs.setOutput("bottom", true) would fix it, but it doesnt go along with the timer.
Here is the code:
Here is the code:
local wait_time = 30*60
local time_remaining = 0
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.green)
while true do
term.clear()
term.setCursorPos(1,1)
time_remaining = wait_time
print("RUNNING NS TECH CODE - EDITING PROHIBITED")
print("NS Tech AutoHarvest v1.0")
print("---------------------------------------------------")
while not sleep(1) and time_remaining > 0 do
term.setCursorPos(1,4)
term.clearLine()
local minutes = math.floor(time_remaining/60)
local seconds = math.floor(time_remaining%60)
rs.setOutput("bottom", true)
sleep(8)
rs.setOutput("bottom", false)
print("Next harvest in " .. minutes .. " minutes and " .. seconds .. " seconds.")
time_remaining = time_remaining - 1
end
end
Posted 04 August 2013 - 03:55 AM
In the means of changing the remaining time only in every 9 seconds? Well, that's becuse there is a 8-second sleep in the middle of the loop. By the way, I don't think you want to harvest and stuff in the countdown loop, so put that redstone part after the countdown loop, print "Harvesting now…" beforehand and you're done.it doesnt go along with the timer.
EDIT: Yes, the computers do stop working if you leave the chunk, but they also turn on automatically when you load the chunk if they were turned on when you unloaded it. Remember, you can force a chunk to be loaded using chunk loader blocks from other mods (eg. RailCraft).