- ComputerCraft | Programmable Computers for Minecraft
- → Zelman89's Content
Zelman89's Content
There have been 20 items by Zelman89 (Search limited from 10-February 22)
#133523 Loop repeats one more time
Posted by
Zelman89
on 14 July 2013 - 01:53 PM
in
Ask a Pro
Full code if interested. The zDrive contains "for k,v then" type loop functions. Not sure if this is a loop paradox issue or something crazy.
everything works so I put in a spoiler but here is my issue.
if I press any key not noted it ends the loop and clears the screen but sometimes it runs the first part one more time. Not sure if the cache is not clearing or what. I want to press any key and the screen clears and it ready for the next input. Any ideas what my issue is.
Spoiler
--Phase 4 The loop
parallel.waitForAny(
function()
while true do
--Term Writing
if nir == 2 then
zDrive.slotPerTerm(reader1, col1, row1, slotMax1)
zDrive.slotPerTerm(reader2, col2, row1, slotMax2)
elseif nir == 1 then
zDrive.slotPerTerm(reader1, col1, row1, slotMax1)
end
--Mon Writing
if MO == 2 then
if nir == 2 then
zDrive.slotPerMon(reader1, 1, 2, slotMax1, mon1, ckMon1)
zDrive.slotPerMon(reader2, 1, 2, slotMax2, mon2, ckMon2)
elseif nir == 1 then
zDrive.slotPerMon(reader1, 1, 2, slotMax1, mon1, ckMon1)
end
elseif (MO == 1) and (nir >= 1) then
zDrive.slotPerMon(reader1, 1, 2, slotMax1, mon1, ckMon1)
end
sleep(0)
end end,
function()
while true do
event, char = os.pullEvent("char")
if char == "r" then
shell.run("storageL")
elseif char == "h" then
shell.run("storageL")
else
zDrive.monClear(MO, mon1, mon2)
zDrive.monClear(1, term, nil)
term.setCursorPos(1, 1)
break
end
end
end
)
parallel.waitForAny(
function()
while true do
--Term Writing
if nir == 2 then
zDrive.slotPerTerm(reader1, col1, row1, slotMax1)
zDrive.slotPerTerm(reader2, col2, row1, slotMax2)
elseif nir == 1 then
zDrive.slotPerTerm(reader1, col1, row1, slotMax1)
end
--Mon Writing
if MO == 2 then
if nir == 2 then
zDrive.slotPerMon(reader1, 1, 2, slotMax1, mon1, ckMon1)
zDrive.slotPerMon(reader2, 1, 2, slotMax2, mon2, ckMon2)
elseif nir == 1 then
zDrive.slotPerMon(reader1, 1, 2, slotMax1, mon1, ckMon1)
end
elseif (MO == 1) and (nir >= 1) then
zDrive.slotPerMon(reader1, 1, 2, slotMax1, mon1, ckMon1)
end
sleep(0)
end end,
function()
while true do
event, char = os.pullEvent("char")
if char == "r" then
shell.run("storageL")
elseif char == "h" then
shell.run("storageL")
else
zDrive.monClear(MO, mon1, mon2)
zDrive.monClear(1, term, nil)
term.setCursorPos(1, 1)
break
end
end
end
)
everything works so I put in a spoiler but here is my issue.
function()
while true do
event, char = os.pullEvent("char")
if char == "r" then
shell.run("storageL")
elseif char == "h" then
shell.run("storageL")
else
zDrive.monClear(MO, mon1, mon2)
zDrive.monClear(1, term, nil)
term.setCursorPos(1, 1)
break
end
end
end
if I press any key not noted it ends the loop and clears the screen but sometimes it runs the first part one more time. Not sure if the cache is not clearing or what. I want to press any key and the screen clears and it ready for the next input. Any ideas what my issue is.
#133388 high numbers turning into scientific notation
Posted by
Zelman89
on 13 July 2013 - 10:31 PM
in
Ask a Pro
I am using that same code and still having issues.
and it returns 1.2345678123456879E7
Any idea on how I can print a large number with out it going to scientific notation?
amount = 12345678.123456879
local s = string.format("%f", amount)
print(s)
and it returns 1.2345678123456879E7
Any idea on how I can print a large number with out it going to scientific notation?
#130520 Makeing a colored box
Posted by
Zelman89
on 30 June 2013 - 10:37 PM
in
Ask a Pro
Thanks for the info, on a side note can someone explain one more thing to me. I found some code and I don't undstand the "amountString:sub". What does " :sub " do? I understand the whole code to this point and the sub comes out of no where.
term.write(amountString:sub(#amountString - (sizeX - i), #amountString - (sizeX - i)))
#130399 Makeing a colored box
Posted by
Zelman89
on 30 June 2013 - 12:41 PM
in
Ask a Pro
I know there is button threads and I always get lost trying to read the code. I just want to be able to make a box with a background color and it not going to be a button. I found this touch button code and can understand half of it but can anyone break it down a little farther with comments so I can understand what is happening. Tables are one thing I still don't fully understand. I inserted some of my comments to show what I get and don't get.
--button on/off color
bactive = colors.cyan
binactive=colors.gray
--text on/off color
tactive=colors.white
tinactive=colors.black
--Background color
bgcolor = colors.black
buttons = {}
--I understand this is where values are being put into the table
function newButton(id,xmin,xmax,ymin,ymax,text,func)
buttons[id] = {}
buttons[id]["xmin"] = xmin
buttons[id]["xmax"] = xmax
buttons[id]["ymin"] = ymin
buttons[id]["ymax"] = ymax
buttons[id]["active"] = false
buttons[id]["text"] = text
buttons[id]["func"] = func
end
---------------------------------------------------------------------------------
function printButton(id)
ymin = buttons[id]["ymin"]
ymax = buttons[id]["ymax"]
xmin = buttons[id]["xmin"]
xmax = buttons[id]["xmax"]
text = buttons[id]["text"]
ia = buttons[id]["active"]
width = xmax - xmin
height = ymax - ymin
if ia then m.setBackgroundColor(bactive) m.setTextColor(tactive)
else m.setBackgroundColor(binactive) m.setTextColor(tinactive) end
-- what is happening here? This is where I get lost.
for j = ymin,ymax do
m.setCursorPos(xmin,j)
for i = xmin,xmax do
m.write(" ")
end
end
m.setCursorPos(xmin + width / 2 - #text / 2 + 1,ymin + height / 2)
m.write(text)
m.setBackgroundColor(bgcolor)
end
#127115 counting peripherals
Posted by
Zelman89
on 17 June 2013 - 07:24 PM
in
Ask a Pro
Okay so I spent a little more time on this issue and tried to rewrite it. I hoped in rewriting it I could find my flaw. Here the info you will need. My guess is I am not geting the values returned out of my second function.
Error: test3:12: attempt to index ? (a nil value)
Program: http://pastebin.com/EM8Xw47y
API: http://pastebin.com/LUDBC9i1
Error: test3:12: attempt to index ? (a nil value)
Program: http://pastebin.com/EM8Xw47y
API: http://pastebin.com/LUDBC9i1
#126729 counting peripherals
Posted by
Zelman89
on 16 June 2013 - 12:06 PM
in
Ask a Pro
made those changes and getting "attempt to index ? (a nil vaule)" on line 4
seems solid code to me, is a variable not able to pass to the API for some reason?
here is the fuction again for ref:
Moni1, Moni2 = zDrive.findTperipherals("monitor")
seems solid code to me, is a variable not able to pass to the API for some reason?
here is the fuction again for ref:
function findTperipherals(p)
s = {}
for _,v in pairs(rs.getSides()) do
if #s == 2 then break end
if peripheral.getType(v) == p then
table.insert(s, v)
end
end
return unpack( s )
end
#126720 counting peripherals
Posted by
Zelman89
on 16 June 2013 - 11:34 AM
in
Ask a Pro
theoriginalbit, you code is awesome but it doesn't work if I try to put the first part into a custom api. Am I missing something?
I also had a custom error message which see it cause some issues too...
API "zDrive"
My program:
I also had a custom error message which see it cause some issues too...
API "zDrive"
--Set up two peripherals
function findTperipherals(p)
s = {}
for _,v in pairs(rs.getSides()) do
if #s == 2 then break end
if peripheral.getType(v) == p then
table.insert(s, v)
end
end
return unpack( s )
end
function wrapTperipherals(j, l, k, m)
if k ~= nil then
MO = 2
l = peripheral.wrap(j)
advMon(l, j)
m = peripheral.wrap(k)
advMon(m, k)
elseif j ~= nil then
MO = 1
l = peripheral.wrap(j)
advMon(l, j)
notes("IMPORTANT", "With a second advanced monitor","you will see more information.")
sleep(3)
else
niceError("No advanced monitors attached to the computer","")
return
end
end
--Header function
function header(te)
term.clear()
term.setCursorPos(1, 1)
term.setTextColor(colors.cyan)
cprint("---------========= "..te.." =========---------")
term.setTextColor(colors.white)
end
--Error Messages
function niceError(Ea, Eb)
header("Error!")
term.setCursorPos(1, 3)
cprint(Ea)
cprint(Eb)
local x, y = term.getCursorPos()
if Eb == "" then
y2 = y
elseif Eb ~= "" then
y2 = y + 1
end
term.setCursorPos(1, y2)
term.setTextColor(colors.cyan)
cprint("---------========= Error! =========---------")
term.setTextColor(colors.white)
error()
end
--Center text print
function cprint (t)
local x2, y2 = term.getCursorPos()
local x, y = term.getSize()
term.setCursorPos(math.ceil((x/2) - (t:len()/2)), y2)
print(t)
end
--Notes
function notes(te, ta, tb)
term.clear()
term.setCursorPos(1, 1)
term.setTextColor(colors.cyan)
cprint("---------========= "..te.." =========---------")
term.setCursorPos(1, 3)
term.setTextColor(colors.white)
cprint(ta)
cprint(tb)
term.setCursorPos(1, 6)
term.setTextColor(colors.cyan)
cprint("---------========= "..te.." =========---------")
term.setCursorPos(1, 8)
term.setTextColor(colors.white)
end
My program:
--Set up two peripherals
MO = 0
Moni1, Moni2 = zDrive.findTperipherals("monitors")
--Moni1 holds side info and mon1 is variable to write with
zDrive.wrapTperipherals(Moni1, mon1, Moni2, mon2)
mon1.write("This is Monitor 1!")
mon2.write("This is Monitor 2!")
print("There is "..MO.."/2 monitors connected.")
#126567 counting peripherals
Posted by
Zelman89
on 15 June 2013 - 10:20 PM
in
Ask a Pro
Bomb, this is very helpful in my learning but I have further refined my program and decided that I will always have two monitors but don't know on what sides. This is the code, I don't get an error but I don't get left and right as an answer.
I get nil after i run the program. I am trying to use rs.getside() and peripheral.getType() to generate a table that has sides and what peripheral is attached to them. I can't figure out how to break it down into two different variables. If I have a monitor on both the left and the right, I want reader1 = left and reader2 = right. Any ideas?
for k,v in pairs(redstone.getSides()) do if peripheral.getType(v) == "monitor" then return v end reader1, reader2 = tostring(v) print(reader1.." "..reader2) end
I get nil after i run the program. I am trying to use rs.getside() and peripheral.getType() to generate a table that has sides and what peripheral is attached to them. I can't figure out how to break it down into two different variables. If I have a monitor on both the left and the right, I want reader1 = left and reader2 = right. Any ideas?
#126501 Advance Nuclear Reader — Misc Peripherals addon
Posted by
Zelman89
on 15 June 2013 - 06:17 PM
in
Ask a Pro
works perfectly but now is there any way to count how many came back having something in its slot? I tried this:
never mind had a typo somewhere
(wrap the sensor to "nreader" or somesuch here) u = 0 for i=1,9 do UUID,state,title,cardinfotable = nreader.get(i) if UUID ~= nil then print(something) u = u + 1 else u = u end end print(u.."slot in use"
never mind had a typo somewhere
#126486 counting peripherals
Posted by
Zelman89
on 15 June 2013 - 05:05 PM
in
Ask a Pro
Title: counting peripherals
I am working on part of a program that can detect a specific peripheral an create 3 variables to use in a sperate program. Here is what I have.
It prints the sides i have monitors on (ex. top) and i get ture or false following them that I don't need. I am stumped on how to have this create a variable for each side so I can wrap them sperately because i want diferent text on two different monitors and need two different varables for .write. would something like x, y = v work? (still new at this). I also need to make a third varable that i can use for how many monitors are connect in case i want to be crazy with a third monitor.
I am working on part of a program that can detect a specific peripheral an create 3 variables to use in a sperate program. Here is what I have.
for k,v in pairs(redstone.getSides()) do if peripheral.getType(v) == "monitor" then print(v) print(#v) end end
It prints the sides i have monitors on (ex. top) and i get ture or false following them that I don't need. I am stumped on how to have this create a variable for each side so I can wrap them sperately because i want diferent text on two different monitors and need two different varables for .write. would something like x, y = v work? (still new at this). I also need to make a third varable that i can use for how many monitors are connect in case i want to be crazy with a third monitor.
#125983 Advance Nuclear Reader — Misc Peripherals addon
Posted by
Zelman89
on 13 June 2013 - 02:48 PM
in
Ask a Pro
I am working with misc peripherals and more specifically the advanced nuclear reader that can hold 9 sensors. I know I can use the getslot() to pull information from the sensor card but I can't find if it possible to write a code that will check if new senors have been added. My goal is to write a program that will detect which slot has a sensor and pull the information off it. This will allow me to add sensor cards as I go and not have to update the program.
In short is there a function that will check all slots and return true or false if a slot as a card in it.
In short is there a function that will check all slots and return true or false if a slot as a card in it.
- ComputerCraft | Programmable Computers for Minecraft
- → Zelman89's Content


