This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Help With Counting
Started by TyDoesMC, 29 July 2013 - 08:46 PMPosted 29 July 2013 - 10:46 PM
I Need Help With Making a Program In CC That + 1 to: "Mob's Killed: 0" But Update It To 1 :P/>
Posted 30 July 2013 - 12:00 AM
How do you want to notify the computer that it's changed? As an example I'll use the arrow keys.
local killed = 0 --#Our kill counter
local termX, termY = term.getSize() --#We need this to center text on the screen
local function printKilled() --#Every time you draw to the screen, this is called
local killText = killed.." mobs have been killed." --#This is our kill text
term.setCursorPos(termX/2-#killText/2, termY/2) --#Center it on the screen
term.write(killText) --#Write it to the screen
end
while true do
term.clear() --#Clear the screen first
printKilled() --#Print our kill count
term.setCursorPos(1,1) --#Set the cursor pos to the top left-hand corner
term.write("Press the arrow keys to increase/decrease the kill count") --#Write instructions
local e = {os.pullEvent("key")} --#Wait for a key event
if e[2] == keys.up then --#If the user hits the up key
killed = killed + 1 --#Increase the kill counter
elseif e[2] == keys.down then --#Otherwise,
killed = killed - 1 --#Decrease the kill counter
end
end
Posted 30 July 2013 - 08:30 AM
Right click: Decrease, Left click: Increase
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
local count = 0
while true do
term.clear()
term.setCursorPos(1, 1)
write("Count: "..tostring(count))
if ({os.pullEvent("mouse_click")})[2] == 1 then
count = count + 1
else
count = count - 1
end
end
Posted 30 July 2013 - 09:12 AM
"I need help" not "Can someone make me a program"…
What do you need help WITH exactly? What don't you understand?
What do you need help WITH exactly? What don't you understand?
Posted 30 July 2013 - 09:33 AM
"I need help" not "Can someone make me a program"…
What do you need help WITH exactly? What don't you understand?
I assumed that because he posted in general rather than AaP he wanted a program made for him.
Posted 30 July 2013 - 03:01 PM
There are several ways to do this. I would start with some tutorials.
Posted 08 August 2013 - 05:31 PM
i Need Help With Making a Update When The Computer Is Powered Like This:
RedstoneTick = 0
if rs.getInput("bottom", true)
then
RedstoneTick = 1
RedstoneTick = 0
if rs.getInput("bottom", true)
then
RedstoneTick = 1
Posted 09 August 2013 - 04:45 AM
RedstoneTick = 0
term.clear()
term.setCursorPos(1,1)
write("RedstoneTick: "..RedstoneTick)
while true do
os.pullEvent("redstone")
if rs.getInput("bottom",true) then RedstoneTick = RedstoneTick + 1 end
term.clear()
term.setCursorPos(1,1)
write("RedstoneTick: "..RedstoneTick)
end
Keep in mind this will actually keep counting up if for instance you keep the bottom powered with redstone and give any other side a redstone pulse. Shouldn't be a problem if you just give short pulses to the bottom.
Posted 09 August 2013 - 10:35 AM
At this point, I'm going to move this into the appropriate section.