Jump to content


applesauce10189's Content

There have been 4 items by applesauce10189 (Search limited from 10-February 22)


By content type

See this member's

Sort by                Order  

#268869 Potential Computercraft Bug

Posted by applesauce10189 on 08 August 2017 - 11:03 AM in Ask a Pro

The illegal character is probably the tabs, I edit my programs with notepad++ because a youtube video showed me that you can do that and I find it just easier that way in my opinion.
It seems a "tab" in CC is just 2 spaces, whereas a tab in notepad++ is an actual indent.

Here's an updated version of the code:
print("starting program")
sleep(1)
rednet.open("back")
fuel = false
function alert()
while true do
  sleep(0.01)
  event, p1 = os.pullEvent("trigger")
  if p1 then
   rs.setOutput("left", true)
   sleep(0.3)
   rs.setOutput("left", false)
   sleep(0.3)
  end
end
end
function aCheck()
while true do
  id, msg = rednet.receive()
  if id then
   print(id.." said "..msg)
  end
  if id == 7 and msg == "fuelLow" then
   os.queueEvent("trigger", true)
  elseif id == 7 and msg == "fuelGood" then
   os.queueEvent("trigger", false)
  end
  sleep(0.01)
end
end
while true do
parallel.waitForAny(alert, aCheck)
print("Something went wrong.")
end

Now the only potential problem is it only runs the redstone blink once per event, however the computer telling it what to do should be essentially spamming the trigger as long as its needed so it's not really that big a problem.

That, and I can't think of an effective worth-while solution to it.



#268864 Potential Computercraft Bug

Posted by applesauce10189 on 08 August 2017 - 07:23 AM in Ask a Pro

So I made another thread which explained I'm playing with a lot of mods, still on that sever and making programs for fun, but I appear to have run into an issue.

I'm playing on minecraft version 1.7.10 with computercraft version 1.75, and because it's relevant to what I was trying to do, Project:Red version 4.7.0 pre 12.95


So I had a wireless modem on the back of the computer, it was originally on the right but I moved it just to see whether or not it was relevant to the problem, and project:red red alloy wiring on the left of the computer, using the computers lua interpreter I enabled and disabled the redstone signal on the left and everything acted just fine, however, when I run my program, the computer just dies. When I back out of the computer, it shows that the computer's on however the screen is entirely blank, it doesn't print anything to the screen. ctrl+t doesn't terminate the program, either. I think very rarely I spot an error, something along the lines of "windows:98" only there for a frame or so. On one occasion the entire computercraft mod on the server broke and I had to restart the server, all computers on the server read something about being unable to resume due to a problem with bios.lua, and then proceeded to be nothing more than a blank screen much like the originating computer. This only happened once and I haven't been able to recreate it.

The only way I was able to end the program was to break the modem, at which point the computer will run the first print then error when rednet.open tries opening a non-existent modem


print("starting program")
rednet.open("back")
print("rednet, opened")
fuel = false
print("fuel declared")
int = 0
print("int declared")
function alert()
print("alert function started")
while true do
print("alert loop has been run: "..int.." times")
int = int + 1
  while fuel == true do
  print("running fuel loop")
   rs.setOutput("left", true)
   sleep(0.8)
   rs.setOutput("left", false)
  end
end
end
function aCheck()
print("running aCheck")
while true do
  print("Waiting for rednet signal")
  id, msg = rednet.receive()
  print("Received rednet signal")
  if id then
   print(id.." said "..msg)
   print("test")
  end
  if id == 7 and msg == "fuelLow" then
   fuel = true
  elseif id == 7 and msg == "fuelGood" then
   fuel = false
  end
  sleep(0.01)
end
end
while true do
print("Starting main loop")
parallel.waitForAny(alert, aCheck)
print("Something returned")
end

Again, when this program is run the computer is just a purely blank screen, even though there's prints all over the place,

EDIT: I've made progress. Right after the print on line 1, I added a new line that's just sleep(5)
after that addition, the program doesn't break computercraft, it just doesn't serve its intended purpose.
Specifically, the rs.setOutputs don't seem to be acting how I'd like, on the left it just receives a constant signal rather than a toggling signal.

EDIT #2: I had a loop that was just turn on signal, sleep, turn off, no wonder it stayed constantly on, it probably wasn't even off for a single tick. Everything works as intended now. I still don't understand why I need a sleep on the second line though, I'm very curious about that.

EDIT #3: Here's my current version of the program though, if anyone could suggest improvements I could make. I'm still bad at coding.
print("starting program")
sleep(1)
print("jk, just slept a second, now starting")
rednet.open("back")
print("rednet, opened")
fuel = false
print("fuel declared")
int = 0
print("int declared")
function alert()
print("alert function started")
while true do
sleep(0.01)
print("alert loop has been run: "..int.." times")
int = int + 1
  while fuel == true do
  print("running fuel loop")
   rs.setOutput("left", true)
   sleep(0.5)
   rs.setOutput("left", false)
   sleep(0.5)
  end
end
end
function aCheck()
print("running aCheck")
while true do
  print("Waiting for rednet signal")
  id, msg = rednet.receive()
  print("Received rednet signal")
  if id then
   print(id.." said "..msg)
   print("test")
  end
  if id == 7 and msg == "fuelLow" then
   fuel = true
  elseif id == 7 and msg == "fuelGood" then
   fuel = false
  end
  sleep(0.01)
end
end
while true do
print("Starting main loop")
parallel.waitForAny(alert, aCheck)
print("Something returned")
end



#268740 read() persisting after parallel waitForAny returned a different function

Posted by applesauce10189 on 01 August 2017 - 08:02 PM in Ask a Pro

View PostDog, on 01 August 2017 - 12:52 AM, said:

A quick and dirty fix would be to wrap your main parallel call in a while loop and replace the parallel call in logOut with a return. That'll cycle the main parallel call and start the routines over, abandoning the read call in command.
function logOut()
  while true do
	_, key = os.pullEvent("key")
	if key == keys.f1 then
	  return --# instead of using parallel here, use a return to exit this function and cause the main parallel call to exit and restart
	elseif key == keys.f3 then
	  error("wut")
	end
  end
end

...

--# main parallel call
while true do --# use a while loop to restart the parallel call if it exits
  parallel.waitForAny(password, logOut)
end

Your solution works beautifully, thank you



#268714 read() persisting after parallel waitForAny returned a different function

Posted by applesauce10189 on 31 July 2017 - 07:43 PM in Ask a Pro

I'm playing with a lot of mods, I plan to have one central computer that controls many aspects of my base and gathers relevant statistics. None of that's actually in yet, because I was testing it before adding all that and encountered this issue.

The program's called startup so it boots up when you open the computer, and you're greeted with a password prompt. If you put in the password, you'll be taken to a placeholder prompt where read() is called, but I also used the parallel API's waitForAny to have a "logOut" function co-exist with the main function, so at any time I could press f1 to bring back the password prompt, or press f3 to kill the program entirely.

However, if I use f1 to bring back the password prompt, the read prompt from before is still accepting input, and basically providing an uncensored version of what should be asterisks. So basically I need a way to interrupt the read function that was called.

--uncomment this line when ready
--os.pullEvent = os.pullEventRaw
rednet.open("back")

--Set up the 'to do' list on the right monitors
mon = peripheral.wrap("right")
mon.clear()
mon.setCursorPos(1,1)
mon.setTextColor(colors.white)
mon.write("To do list:")
mon.setCursorPos(1,2)
mon.write("1: Finish the machinery line")
mon.setCursorPos(1,3)
mon.write("2: Begin project 'Alpha'")
mon.setCursorPos(1,4)
mon.write("3: Mine. Always need more everything")
mon.setCursorPos(1,5)
mon.write("4: Get a nether star")
mon.setCursorPos(1,6)
mon.write("5: Improve power armor")
mon.setCursorPos(1,7)
mon.write("6: Expand the 'to do' list")

--self explanatory
function myClear(color)
  term.clear()
  term.setCursorPos(1,1)
  term.setTextColor(colors.purple)
  term.write("AppleOS Master Computer")
  term.setCursorPos(1,2)
  term.setTextColor(color)
end

--Bring back the password screen, or kill the program entirely, if these buttons are pushed
function logOut()
  while true do
    blank = " "
key = " "
    blank, key = os.pullEvent("key")
if key == keys.f1 then
 parallel.waitForAny(password, logOut)
elseif key == keys.f3 then
 error("wut")
end
  end
end

--Require a password to access the heart of the computer
function password()
  while true do
    myClear(colors.white)
    term.setCursorPos(1,2)
    term.write("Password: ")
inPass = read("*")
if inPass == "yoloswag" then
 command()
else
 term.setCursorPos(1,3)
 term.setTextColor(colors.red)
 term.write("Nope.")
 sleep(3)
end
  end
end

--do all the fancy things I plan to do with this computer
function command()
  --while true do
    term.write("this is temporary.")
read()
  --end
end


parallel.waitForAny(password, logOut)



I did some research, is the coroutine API something I should look into? I'm very bad with programming, but I'm willing to learn it if that's how I gotta fix this