Jump to content




Help With Counting



  • You cannot reply to this topic
8 replies to this topic

#1 TyDoesMC

  • Members
  • 154 posts
  • LocationEarth

Posted 29 July 2013 - 09:46 PM

I Need Help With Making a Program In CC That + 1 to: "Mob's Killed: 0" But Update It To 1 :P

#2 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 29 July 2013 - 11:00 PM

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


#3 jesusthekiller

  • Banned
  • 562 posts
  • LocationWrocław, Poland

Posted 30 July 2013 - 07: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


#4 billysback

  • Members
  • 569 posts

Posted 30 July 2013 - 08:12 AM

"I need help" not "Can someone make me a program"...
What do you need help WITH exactly? What don't you understand?

#5 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 30 July 2013 - 08:33 AM

View Postbillysback, on 30 July 2013 - 08:12 AM, said:

"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.

#6 Rwkeith

  • Members
  • 56 posts

Posted 30 July 2013 - 02:01 PM

There are several ways to do this. I would start with some tutorials.

#7 TyDoesMC

  • Members
  • 154 posts
  • LocationEarth

Posted 08 August 2013 - 04: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

#8 ikke009

  • Members
  • 224 posts
  • LocationSliding between sunbeams

Posted 09 August 2013 - 03: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.

#9 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 09 August 2013 - 09:35 AM

At this point, I'm going to move this into the appropriate section.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users