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

Scoreboard Help

Started by Swappcub, 01 July 2014 - 07:37 PM
Swappcub #1
Posted 01 July 2014 - 09:37 PM
I'm doing a simple project in the bottom of my house but I cant seem to do it :(/>
I have been reading tutorials for hours now and I have learned some stuff but not a lot.
I am trying to make a program that is on a 1x2 monitor and all it says is my name centered like this —> Swappcub = 0
It should add +1 every time it receives a redstone signal to the back of it. It should reset to 0 when it receives a redstone signal to the front.
I tried to do it many different ways but I think it would be very simple for someone with a little more expeience then me.
Please Help!
Cranium #2
Posted 01 July 2014 - 09:42 PM
What kind of code do you have so far?
Swappcub #3
Posted 01 July 2014 - 09:57 PM
one sec Srry :P/>
Swappcub #4
Posted 01 July 2014 - 10:05 PM
local attachedMonitor = peripheral.wrap("right")
attachedMonitor.setTextScale(1)
attachedMonitor.clear()
attachedMonitor.setCursorPos(1,3)
attachedMonitor.write("Swappcub = ")
attachedMonitor.setCursorPos(1,12)
attachedMonitor.write("0")
–below this wont work :/
if rs.imput("front")
then attachedMonitor.clear()

Swappcub #5
Posted 01 July 2014 - 10:06 PM
I had a bit more (like text backround color) but I erased most of it when I got kinda mad *facepalm*
Swappcub #6
Posted 01 July 2014 - 10:27 PM
Normally I reply faster but the posts need to be approved :/
Cranium #7
Posted 01 July 2014 - 10:28 PM
Well, it's rs.getInput("front"), not what you have written there.
Swappcub #8
Posted 01 July 2014 - 10:30 PM
But how would I get it to add the numbers?
Swappcub #9
Posted 01 July 2014 - 10:56 PM
Is it possible?
KingofGamesYami #10
Posted 02 July 2014 - 02:38 PM
Adding is very simple. variable = variable + 1 will increase variable by 1.


local attachedMonitor = peripheral.wrap("right")
attachedMonitor.setTextScale(1)
attachedMonitor.clear()
attachedMonitor.setCursorPos(1,3)
local score = 0  --#set score as a (numeric) variable, so we can increase it.
attachedMonitor.write("Swappcub = ")
attachedMonitor.setCursorPos(1,12)
attachedMonitor.write( score )  --#instead of writing "0" we write the value of variable score, at this point it is 0.
while true do
 if rs.getInput("front") then
  score = score + 1 --#increase our variable by 1
  attachedMonitor.setCursorPos(1, 12)
  attachedMonitor.write( score ) --#write the increased variable
 elseif rs.getInput( "back" ) then
  score = 0 --#reset variable to 0
  attachedMonitor.setCursorPos( 1, 12 )
  attachedMonitor.write( score.."  " ) --#I added a couple of spaces so it will erase any number with 3 or less digits. 
 end
end
Swappcub #11
Posted 02 July 2014 - 07:44 PM
Oh god XD I wrote 120 or so lines of text :/ it had like 5 or 6 errors-when i am finished with this small project thanks to you, i will upload a small video and show you it :)/>/> Thank You! –After I am finished I will try to find a tutorial on Variables to fry my eyes and brain on. :P/>
Edited on 02 July 2014 - 05:46 PM
Swappcub #12
Posted 02 July 2014 - 08:35 PM
Weird :/ I try to run the code but it keeps saying to long without yielding? Solutions?

Code:

Pastebin get kidVxZiW
Lyqyd #13
Posted 02 July 2014 - 08:42 PM
Well, that isn't going to do what you want it to. You're going to want to pull redstone events, which are triggered when redstone state changes, then examine the inputs to take the appropriate action. You'll need to keep track of the last state of the two sides, so you know when they have changed.
Swappcub #14
Posted 02 July 2014 - 08:53 PM
:wacko:/> English please?
So remove the redstone events after they are triggered?
KingofGamesYami #15
Posted 03 July 2014 - 03:10 PM

local attachedMonitor = peripheral.wrap("right")
attachedMonitor.setTextScale(1)
attachedMonitor.clear()
attachedMonitor.setCursorPos(1,3)
local score = 0  --#set score as a (numeric) variable, so we can increase it.
attachedMonitor.write("Swappcub = ")
attachedMonitor.setCursorPos(1,12)
attachedMonitor.write( score )  --#instead of writing "0" we write the value of variable score, at this point it is 0.
while true do
 os.pullEvent( "redstone" ) --#pull a redstone event so that it yields, preventing "too long without yielding"
 if rs.getInput("front") then
  score = score + 1 --#increase our variable by 1
  attachedMonitor.setCursorPos(1, 12)
  attachedMonitor.write( score ) --#write the increased variable
 elseif rs.getInput( "back" ) then
  score = 0 --#reset variable to 0
  attachedMonitor.setCursorPos( 1, 12 )
  attachedMonitor.write( score.."  " ) --#I added a couple of spaces so it will erase any number with 3 or less digits.
 end
end
Edited on 03 July 2014 - 01:11 PM
Swappcub #16
Posted 03 July 2014 - 05:07 PM
Okay, I guess I'll try this later–
Swappcub #17
Posted 03 July 2014 - 05:33 PM
I'm running the code below but the number wont show up :/

pastebin get DtJd065q
KingofGamesYami #18
Posted 03 July 2014 - 07:48 PM
Problem is here:

attachedMonitor.write("1") --#write the increased variable
It should be this:

attachedMonitor.write( score ) --#score is a variable.
Swappcub #19
Posted 03 July 2014 - 08:01 PM
I tried that to, but the number wont show up :(/>

It shows this

Swappcub =

and redstone pulse to front does nothin
KingofGamesYami #20
Posted 03 July 2014 - 08:41 PM
let me re-write this program entirely… I normally call monitors "mon"

local mon = peripheral.wrap( "right" )  --#wrap da monitor
mon.setTextScale( 1 )  --#set text scale to 1
mon.clear()  --#clear the monitor
mon.setCursorPos( 1, 3 )  --#set the cursor position
mon.write( "Score: " ) 
local x, y = mon.getCursorPos()  --#get the position after writing "Score: "
local score = 0 --#set score to 0
mon.write( score )  --#write 0
while true do
 os.pullEvent( "redstone" )  --#wait for redstone
 if rs.getInput( "front" ) then  --#test the front redstone input
  mon.setCursorPos( x, y ) --#set cursor position to position we defined earlier.
  score = score + 1  --#increase score by one
  mon.write( score )  --#write the current score
 elseif rs.getInput( "back" ) then
  score = 0  --#reset score
  mon.setCursorPos( x, y )  --#set cursor position to position we defined earlier.
  mon.write( score.."  " )  --#write the score + two spaces to cover up any multi-digit numbers
 end
end

To clarify, you are powering the computer not the monitor correct?
Edited on 03 July 2014 - 06:41 PM
Swappcub #21
Posted 03 July 2014 - 09:15 PM
yes the redstone signal will go into the computer not the screen/monitor

Mon will work the same as monitor right?
Swappcub #22
Posted 03 July 2014 - 09:38 PM
You've done it! :D/>
Thanks a ton, I'll make a video shortly :P/> (1 Day)

1 Problem (dosent matter much)
Instead of 0, 1, 2, 3
it goes 0, 1.0, 2.0, 3.0
Lyqyd #23
Posted 03 July 2014 - 10:07 PM
Sigh. His code is still broken, since he only implemented one of my suggestions.


local mon = peripheral.wrap("right")
term.redirect(mon)
local frontState = false
local counter = 0
while true do
  if rs.getInput("front") ~= frontState then
    if not frontState then
      counter = counter + 1
    end
    frontState = not frontState
  end
  if rs.getInput("back") then
    counter = 0
  end
  term.setCursorPos(1, 3)
  term.clearLine()
  write("Swappcub = "..tostring(counter))
  os.pullEvent("redstone")
end