Jump to content


queebles's Content

There have been 6 items by queebles (Search limited from 10-February 22)


By content type

See this member's

Sort by                Order  

#193593 how can i condense the values from a table into one value?

Posted by queebles on 15 September 2014 - 05:44 AM in Ask a Pro

Well shoot, that bug is over a year old, guess I'll just get rid of the monitor and use mouse clicks on the terminal.



#193548 how can i condense the values from a table into one value?

Posted by queebles on 14 September 2014 - 06:01 PM in Ask a Pro

I've discovered something weird going on with this.... the monitor is letting me touch the screen outside of the screen. Idk if I can explain this.... the keypad is printed on the monitor at coordinates 1,1 which is good. however i can touch coordinates 0,0(top left corner of the border around the screen) which isn't even on the screen and it thinks that i hit the 1 button. in fact the whole thing is stretched up one and left one. visually its in the right place, but by touch it's messed up.. all coordinates from 0,0 - 0,9 and 0,0 - 9,0 register a touch. http://pastebin.com/BuvQtjkT



#193532 how can i condense the values from a table into one value?

Posted by queebles on 14 September 2014 - 04:57 PM in Ask a Pro

Ahhh, yes, thank you Bomb bloke, that helped. And you're right, there are definitely other problems.



#193477 how can i condense the values from a table into one value?

Posted by queebles on 13 September 2014 - 07:34 PM in Ask a Pro

Alright, told ya I'd be back... Thanks Lyqyd and Lignum, that was exactly what I needed. Now I'm stuck again, I'm not sure I'm using functions properly, also no matter which button I hit it only prints '1' and lets me keep pressing buttons after the first four. I'm not sure where I messed up... So here is what i have so far... http://pastebin.com/mKYJST0J

function check()
  entry = tonumber(codeTbl[1]..codeTbl[2]..codeTbl[3]..codeTbl[4])
  if entry == code then mon.setCursorPos(1,10) print("ACCESS GRANTED")  --do something here with redstone
    else mon.setCursorPos(1,10) print("ACCESS DENIED")
  end
_1st = false
_2nd = false
_3rd = false
_4th = false
codeTbl = {}
end
function _123or4() --is it the 1st, 2nd, 3rd, or 4th number you pressed
  if _1st == false then mon.setCursorPos(11,2) _1st = true
    elseif _2nd == false then mon.setCursorPos(12,2) _2nd = true
    elseif _3rd == false then mon.setCursorPos(13,2) _3rd = true
    elseif _4th == false then mon.setCursorPos(14,2) _4th = true
  end
end
mon = peripheral.wrap("left")
term.redirect(peripheral.wrap("left"))
mon.setTextScale(.5)
mon.setBackgroundColor(colors.black)
mon.clear()
codeTbl = {}  --table the code is hopefully being stored within
_1st = false
_2nd = false
_3rd = false
_4th = false
code = 1234
--read txt file and print it to monitor
hFile = fs.open("keypad.txt", "r")
for i = 1, 9 do
  print(hFile.readLine())
end
hFile.close()
--it looks like this
--/-\/-\/-\
--|1||2||3|
--\-/\-/\-/ ^^^^
--/-\/-\/-\
--|4||5||6|
--\-/\-/\-/
--/-\/-\/-\
--|7||8||9|
--\-/\-/\-/
w,h = mon.getSize()
repeat
  event,side,w,h = os.pullEvent("monitor_touch")
  if w == 1 or 2 or 3 and h == 1 or 2 or 3 then _123or4()
    print("1")
    elseif w == 4 or 5 or 6 and h == 1 or 2 or 3 then _123or4()
    print("2")
    elseif w == 7 or 8 or 9 and h == 1 or 2 or 3 then _123or4()
    print("3")
    elseif w == 1 or 2 or 3 and h == 4 or 5 or 6 then _123or4()
    print("4")
    elseif w == 4 or 5 or 6 and h == 4 or 5 or 6 then _123or4()
    print("5")
    elseif w == 7 or 8 or 9 and h == 4 or 5 or 6 then _123or4()
    print("6")
    elseif w == 1 or 2 or 3 and h == 7 or 8 or 9 then _123or4()
    print("7")
    elseif w == 4 or 5 or 6 and h == 7 or 8 or 9 then _123or4()
    print("8")
    elseif w == 7 or 8 or 9 and h == 7 or 8 or 9 then _123or4()
    print("9")
  end
i = #codeTbl
until i == 4
  if #codeTbl == 4 then check()
  end

I hope I don't have any typos, I transcribed that from minecraft



#193464 how can i condense the values from a table into one value?

Posted by queebles on 13 September 2014 - 03:19 PM in Ask a Pro

Wow, you answered quickly, I wasn't expecting that :) Cool, I didn't know that tonumber() was a thing. I'll give that a try. As for what this does, most of this code was me testing.... I'm trying to make a touchscreen keypad lock, without looking at anyone else's code(for my own sense of accomplishment), that requires the user to enter 4 numbers to unlock a door. I was having trouble figuring out how to compare the user's entries to the correct unlock code. Thank you very much, I'm sure I'll be back, I've got a few more things I'm having trouble with.



#193433 how can i condense the values from a table into one value?

Posted by queebles on 13 September 2014 - 03:28 AM in Ask a Pro

i have a table with 4 one digit numbers in it and i want to smush those 4 numbers into 1 four digit number. i don't know where to go from here.

tbl = {}

print("enter first number:") entry1 = read()
print("enter second number:") entry2 = read()
print("enter third number:") entry3 = read()
print("enter fourth number:") entry4 = read()

entry = entry1..entry2..entry3..entry4
print("this is: 'entry1..entry2..entry3..entry4'")
print(entry)

tbl[1] = entry1
tbl[2] = entry2
tbl[3] = entry3
tbl[4] = entry4

entryt = tbl[1]..tbl[2]..tbl[3]..tbl[4]
print("this is: 'tbl[1]..tbl[2]..tbl[3]..tbl[4]'")
print(entryt)

print("tostring with key and value")
for k, v in pairs(tbl) do
  print("key is:"..tostring(k).." value is:"..tostring(v))
end

a = entry
b = entryt
code = 1234
print("entry = "..entry)
print("entryt = "..entryt)
print("code = "..code)
if a == entry then print("a = entry")
  else print("a ~= entry")
end
if b == entryt then print("b = entryt")
  else print("b ~= entryt")
end
if a == b then print("a = b")
  else print("a ~= b")
end
if a == code then print("entry = code")
  else print("entry ~= code")
end
if b == code then print("entryt = code")
  else print("entryt ~= code")
end

i apologize for what i'm sure is just a mess, but i'm just learning..... anyway when i run this and enter the numbers 1,2,3,and 4 into the table and try to concatenate them into one number, they don't equal the code variable, which is 1234.... can someone help me do this please? thanks for listening :)