This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
cmckain14's profile picture

Vote Counter

Started by cmckain14, 16 September 2013 - 07:25 PM
cmckain14 #1
Posted 16 September 2013 - 09:25 PM
I am trying to build something that will count the votes it receives over rednet and that works but I have no idea how to have who/what has the most votes go on top. Also when it finishes (Stops the loop) how would I allow it to determine who wins?

y = 0
n = 0
p = 0
t = 0
size = 4 --From 1 to 5
side = "left" --Your monitor
m = peripheral.wrap(side)
m.setTextScale(size) --Sets size
repeat
  rednet.open("right")
  id, message, distance = rednet.receive()
  term.clear()
  term.setCursorPos(1,1)
  if message == "Yes" then
    y = y + 1
    t = t + 1
    end
  if message == "No" then
    n = n + 1
    t = t + 1
    end
  if message == "Present" then
    p = p + 1
    t = t + 1
    end
  print("Yes: "..y)
  print("No: "..n)
  print("Present: "..p)
until t > 5

electrodude512 #2
Posted 16 September 2013 - 10:00 PM
I'm not really sure what you're asking.

At the end of the loop (after the until t > 5), try adding:

if y > n then
  print("Yes")
elseif y < n then
  print("No")
else
  print("Tie")
end
cmckain14 #3
Posted 16 September 2013 - 10:15 PM
I'm not really sure what you're asking.

At the end of the loop (after the until t > 5), try adding:

if y > n then
  print("Yes")
elseif y < n then
  print("No")
else
  print("Tie")
end
Perfect, thanks!