Jump to content


RickiHN's Content

There have been 15 items by RickiHN (Search limited from 10-February 22)


By content type

See this member's

Sort by                Order  

#191776 How do I run a loop until a key is pressed?

Posted by RickiHN on 21 August 2014 - 07:50 PM in Ask a Pro

Why not:
repeat
   event,p1 = os.pullEvent()
   stuff

until event=="char" and p1==("x")
Replace "x" with whatever key you want.
Or does it have to work with "any key"?



#191515 Table returning nil

Posted by RickiHN on 18 August 2014 - 02:04 PM in Ask a Pro

Pls put it in a code block and use indentation. That is almost impossible to read :P
Also pls mark of the 156th line for people as they don't get line numbers(and you don't expect them to count down all 156 lines to find the problem).



#191475 Error bioss:366 'end' expected in my security program please help!

Posted by RickiHN on 17 August 2014 - 10:14 PM in Ask a Pro

--check Passcode
function checkPasscode()
   if io.read == pass then
	  return true
	  numFails = 0
   else
	  return false
	  numFails = numFails + 1
   end
end
end <----????



#191449 mfr rednet cable not connecting correctly

Posted by RickiHN on 17 August 2014 - 05:26 PM in Ask a Pro

View PostCranium, on 17 August 2014 - 05:21 PM, said:

What version of ComputerCraft are you using?
Please note that version 1.6+ has no MFR support at all.
Hope I dont derail too much, but is there any idea on when/if the bundled cable support will be back? The lack of it is rather a deal breaker for me, so forced to stick to earlier versions myself.



#191446 Trouble placement of array variables and functions

Posted by RickiHN on 17 August 2014 - 05:22 PM in Ask a Pro

What exactly is this function "changeState" and where is it defined? And why are you feeding it the string "("control")"



#191440 Any ways to improve my simple tunnel script? (not urgent)

Posted by RickiHN on 17 August 2014 - 04:30 PM in Ask a Pro

Could you not do something like this?
	while not turtle.forward() do
		  turtle.dig()
	end


Nvm, missunderstood problem... :P



#191366 Passing strings(with spaces) from one script to another

Posted by RickiHN on 16 August 2014 - 07:14 PM in Ask a Pro

View PostYevano, on 16 August 2014 - 06:18 PM, said:

You're running the elevator script from startup, so loading startup again is pointless. You should instead load the elevator script as an API from the startup script and call some function in it to start it instead of using shell.run.

Ofc...

Was a long struggle(mostly me being a complete noob) but finally got it to work:

Startup:
	buttontext = {}
	buttontext[1]="Floor 1		 "
	buttontext[2]="Floor 2		 "
	buttontext[3]="Floor 3		 "
	buttontext[4]="Floor 4		 "
	buttontext[5]="Floor 5		 "
	buttontext[6]="Floor 6		 "
	buttontext[7]="Floor 7		 "
	buttontext[8]="Floor 8		 "
	buttontext[9]="Floor 9		 "
	
	
	
	
	shell.run("rm", "elevator")
	
	shell.run("pastebin", "get", "1M5sgXpT", "elevator")
	
	os.loadAPI("elevator")
	
	elevator.elevator(buttontext)


Elevator:
	function elevator(buttontext)
			--Load floor location from disk
			local FloorFile = fs.open("disk/floor", "r")
	
	
			if FloorFile then
					ThisFloor = tonumber(FloorFile.readLine())
					print("This floor: "..ThisFloor)
					FloorFile.close()
			else
					print("No Floor File/disk found")
					return
			end
	
			os.setComputerLabel("Elevator"..ThisFloor)
	
			buttoncolours={}
			for k=1, #buttontext do
					buttoncolours[k]=8192 --8192=green
			end
			buttoncolours[ThisFloor]=32 --32=lime
	
			mouseWidth = 0
			mouseHeight = 0
	
			monitor = peripheral.wrap("bottom")
	
			monitor.clear()
			monitor.setCursorPos(1,1)
			w,h=monitor.getSize()
			print(w)
			print(h)
	
			--Draw buttons
			for k=1, #buttontext do
	
					monitor.setBackgroundColour((buttoncolours[k]))
					monitor.setCursorPos(2,k*2)
					monitor.write(buttontext[k])
					monitor.setBackgroundColour((colours.black))
			end --for
	
			repeat
					event,p1,p2,p3 = os.pullEvent()
							if event=="monitor_touch" then
									mouseWidth = p2 -- sets mouseWidth
									mouseHeight = p3 -- and mouseHeight
									for k=1, #buttontext do
											if mouseWidth > 1 and mouseWidth < 18 and mouseHeight == k*2 and k~=ThisFloor then
													redstone.setOutput("top", true)
													sleep(1)
													redstone.setAnalogOutput("back", k)
													sleep(2)
													redstone.setOutput("top", false)
													redstone.setAnalogOutput("back", 0)
											end
									end
							end
			until event=="char" and p1==("x")
	end



Thanks a lot for the help :)



#191364 TE energy cell/EnderIO Capacitor bank power monitor program

Posted by RickiHN on 16 August 2014 - 06:18 PM in Programs

Wrote this simple plug'n'play script with the purpose of monitoring a TE3 Energy cells or EnderIO Capacitor Banks energy level and use it to output a redstone signal to toggle power production accordingly.

Posted Image


The script will by default detect any Cell or Capacitor adjacent or connected by cabled modems automatically and output a redstone signal out the back of the Computer once energy level falls below 10%. Redstone signal is then cut once energy levels are once again above 90%. (These percentages can easily be altered in the top of the code). For now it is limited to supporting just one Cell/capacitor per computer.

Should you wish to (it is entirely optional), the script will support and automatically detect an Advanced Monitor (1 high, 2 wide) either adjacent or attached by cabled modem. This will display the current state of the redstone signal and the current and maximum energy storage.

Great for preserving fuel in starter setups by controlling engines/dynamos/etc. to only run when needed.

http://pastebin.com/rjfa4ymR



#191362 DiskLabeler, no anvil required.

Posted by RickiHN on 16 August 2014 - 05:54 PM in Programs

View PostWin7yes, on 16 August 2014 - 05:41 PM, said:

label set disk "This Is The Name"
Let me explain it slowly:
label(Program wich is ran) set(Argument used to set the label) disk(If this is the name of a disk drive, it will use the disk drive and label the floppy in it) Asdfg(Name. If it has spaces it can be enclosed in quotes ("Name asdasda"))

Ahh right the "disk" is not not an argument for the label program, but in fact the direction/network address of the Disk Drive.



#191359 Passing strings(with spaces) from one script to another

Posted by RickiHN on 16 August 2014 - 05:41 PM in Ask a Pro

Ok I modified the code to use the os.loadAPI, but simply cannot get it to work for some reason:

Startup script:
buttons = {}
buttons[1]="Floor 1		 "
buttons[2]="Floor 2		 "
buttons[3]="Floor 3		 "
buttons[4]="Floor 4		 "
buttons[5]="Floor 5		 "
buttons[6]="Floor 6		 "
buttons[7]="Floor 7		 "
buttons[8]="Floor 8		 "
buttons[9]="Floor 9		 "

shell.run("rm", "elevator")
shell.run("pastebin", "get", "1M5sgXpT", "elevator")
shell.run("elevator")

Elevator script:
local buttontext = {}
os.loadAPI("startup")
buttontext = startup.buttons
os.unloadAPI("startup")
--Load floor location from disk
local FloorFile = fs.open("disk/floor", "r")

if FloorFile then
ThisFloor = tonumber(FloorFile.readLine())
print("This floor: "..ThisFloor)
FloorFile.close()
else
print("No Floor File/disk found")
return
end

os.setComputerLabel("Elevator"..ThisFloor)
local buttoncolours={}
for k=1, #buttontext do
buttoncolours[k]=8192 --8192=green
end
buttoncolours[ThisFloor]=32 --32=lime
mouseWidth = 0
mouseHeight = 0
monitor = peripheral.wrap("bottom")

monitor.clear()
monitor.setCursorPos(1,1)
w,h=monitor.getSize()
print(w)
print(h)
--Draw buttons
for k=1, #buttontext do
monitor.setBackgroundColour((buttoncolours[k]))
monitor.setCursorPos(2,k*2)
monitor.write(buttontext[k])
monitor.setBackgroundColour((colours.black))
end --for

function checkClickPosition()
for k=1, #buttontext do
  if mouseWidth > 1 and mouseWidth < 18 and mouseHeight == k*2 and k~=ThisFloor then
   redstone.setOutput("top", true)
   sleep(1)
   redstone.setAnalogOutput("back", k)
   sleep(2)
   redstone.setOutput("top", false)
   redstone.setAnalogOutput("back", 0)
  end
end
end

repeat
		event,p1,p2,p3 = os.pullEvent()
				if event=="monitor_touch" then
						mouseWidth = p2 -- sets mouseWidth
						mouseHeight = p3 -- and mouseHeight
						checkClickPosition() -- this runs our function
				end
until event=="char" and p1==("x")

I keep getting the error:

Quote

API startup is already being loaded
elevator:3: attempt to index ? (a nil value)

Is there some problem with loading the program named "startup"? Or can you not use tables from the API?



#191357 DiskLabeler, no anvil required.

Posted by RickiHN on 16 August 2014 - 04:43 PM in Programs

View Postsecret6timb1, on 08 August 2014 - 11:51 PM, said:

label set disk disknamehere <--- something like that

don't even need lua.

That would actually just name the computer "disk disknamehere".
You would have to run the disk.setLabel() to label disks to the best of my knowledge. For that reason I actually wrote a similar program when I had to label a lot of disks to make it all easier:

http://pastebin.com/XCsgdpJk

It will automatically detect any adjacent disk drives, so just run it as "programname disklabel".



#191346 Passing strings(with spaces) from one script to another

Posted by RickiHN on 16 August 2014 - 02:41 PM in Ask a Pro

View PostYevano, on 16 August 2014 - 02:24 PM, said:

Quoted arguments were added somewhat recently I think. If you surround your arguments in quotes then they will be treated specially so that spaces will not separate them.
Something like
local withquotes = { }
for i = 1, 9 do
	withquotes[i] = '"' .. buttontext[i] .. '"'
end
shell.run("elevator", unwrap(withquotes))
should work.
Hmm sadly cant get this to work. Probably because I am still using CC 1.58. (Value my bundled cables too highly :( )

View PostLink149, on 16 August 2014 - 02:38 PM, said:

Huh... If I get what you're saying, you say you'd like to 'import' some variables from a file to another, right ?
If so, why not use the os.loadApi function ?

 os.loadApi("somefile") 

If you do so, every global variables and functions defined in "somefile" will be available as "somefile.variable".
This sounds exactly like what I need!



#191340 Code questions

Posted by RickiHN on 16 August 2014 - 02:00 PM in Ask a Pro

Doh, brainfart...
You need to put:
energy = cube.getEnergyStored('unknown')
inside the while loop, else it will only detect the energy level once before reaching the while loop. You want it to do it continuously every cycle.



#191339 Code questions

Posted by RickiHN on 16 August 2014 - 01:56 PM in Ask a Pro

Replace:
energy = cube.getEnergyStored('right')
with:
energy = cube.getEnergyStored('unknown')



#191337 Passing strings(with spaces) from one script to another

Posted by RickiHN on 16 August 2014 - 01:46 PM in Ask a Pro

I wrote a script to interact with Enhanced Portals 3 through touch screen monitors to simulate elevators. It all works beautifully.

However I predict that I might want to use the code multiple places and I have been sharing the code as well. To that end I would greatly prefer that I could add the details(text for the touchscreen buttons) through a separate piece of code and then refer to the same main bit of coding(so that I only have to manage/update one main program). What I came up with was this:

Unique startercode that can be customized for each individual use:
local buttontext = {}
buttontext[1]="Floor 1		 "
buttontext[2]="Floor 2		 "
buttontext[3]="Floor 3		 "
buttontext[4]="Floor 4		 "
buttontext[5]="Floor 5		 "
buttontext[6]="Floor 6		 "
buttontext[7]="Floor 7		 "
buttontext[8]="Floor 8		 "
buttontext[9]="Floor 9		 "

shell.run("rm", "elevator")
shell.run("pastebin", "get", "1M5sgXpT", "elevator")

shell.run("elevator", buttontext[1], buttontext[2], buttontext[3], buttontext[4], buttontext[5], buttontext[6], buttontext[7], buttontext[8], buttontext[9])


Core program:
local buttontext = {...}

--Load floor location from disk
local FloorFile = fs.open("disk/floor", "r")

if FloorFile then
ThisFloor = tonumber(FloorFile.readLine())
print("This floor: "..ThisFloor)
FloorFile.close()
else
print("No Floor File/disk found")
return
end

os.setComputerLabel("Elevator"..ThisFloor)
local buttoncolours={}
for k=1, #buttontext do
buttoncolours[k]=8192 --8192=green
end
buttoncolours[ThisFloor]=32 --32=lime
mouseWidth = 0
mouseHeight = 0
monitor = peripheral.wrap("bottom")

monitor.clear()
monitor.setCursorPos(1,1)
w,h=monitor.getSize()
print(w)
print(h)
--Draw buttons
for k=1, #buttontext do
monitor.setBackgroundColour((buttoncolours[k]))
monitor.setCursorPos(2,k*2)
monitor.write(buttontext[k])
monitor.setBackgroundColour((colours.black))
end --for

function checkClickPosition()
for k=1, #buttontext do
  if mouseWidth > 1 and mouseWidth < 18 and mouseHeight == k*2 and k~=ThisFloor then
   redstone.setOutput("top", true)
   sleep(1)
   redstone.setAnalogOutput("back", k)
   sleep(2)
   redstone.setOutput("top", false)
   redstone.setAnalogOutput("back", 0)
  end
end
end

repeat
		event,p1,p2,p3 = os.pullEvent()
				if event=="monitor_touch" then
						mouseWidth = p2 -- sets mouseWidth
						mouseHeight = p3 -- and mouseHeight
						checkClickPosition() -- this runs our function
				end
until event=="char" and p1==("x")

Now in theory this works, but whenever there is a space in the button text, it is treated as separate arguments (http://computercraft.../wiki/Shell.run)
This means that "Floor 1" becomes "Floor" and "1".

Is there anything I can do to prevent/circumvent this?