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

Program for detecting chest deposits

Started by Cast, 06 July 2012 - 08:48 AM
Cast #1
Posted 06 July 2012 - 10:48 AM
Hiya gang,

I just started working with CC about 3 days ago. My original usage was to use computers to tell a story through floppy discs the user finds around an adventure map (because tomes and any other book mods I've found aren't compatible with forge). However, after reading about the different possibilities with this mod I am now kinda addicted…and trying to learn more.

So, I spent all day yesterday trying to figure out a good setup for this one issue I am having. My intended goal is for the user to enter a room with a giant monitor on the wall and a chest with either a ccSensor or some time of redstone current combo that can send info to the computer behind the monitor (through a pneumatic tube or something). All of that I have taken care of, but what I cannot work out is the event countdown for the computer. I have gone through several tutorials and tried my hand…but noobage has won out. I need help writing code for the computer to display input info from the chest that the player deposits items in. Like a countdown timer…but with items (say he has to collect 50 zombie flesh…the monitor would tick down to 0 with each subsequent deposit.). Then when it reaches 0 the program would send out a redstone signal to unlock a door or do some other doody.

The easiest setup that I have determined would be for an Item Detector (from Redpower 2) to send a pulse to the computer each time the desired items passes through the tube. Then I would just need a countdown program and I could start it at 50 or whatever number is desired. I am just having trouble getting over the gap of writing the event correctly. I'm missing some logic somewhere.

Any help is much appreciated!!!

Thanks,
~Cast
Deathknight0897 #2
Posted 06 July 2012 - 11:00 AM
Yeh pretty much if u need help with this i would be more than willing to help you out with some code for your adventure im no pro but certainly can help you out a lot i will be back Monday pm me if u want my help

i have already created a program very simulur i would also suggest letting you use my start up kit machine that allows a user to pick a start up class ie mage knight archer however that's not finished yet but close to being finished
The easiest setup that I have determined would be for an Item Detector (from Redpower 2) to send a pulse to the computer each time the desired items passes through the tube. Then I would just need a countdown program and I could start it at 50 or whatever number is desired. I am just having trouble getting over the gap of writing the event correctly. I'm missing some logic somewhere
Deathknight0897 #3
Posted 06 July 2012 - 11:02 AM
oh also if you send me what code u have already i will take a look on my smartphone why i am away pm it to me and i will see what is salvageable this seems a much better solution than you keep having to post topics on how to do things for your adventure map i will be able to code most things for you and anything i don't know ill learn quick :P/>/>
Cast #4
Posted 06 July 2012 - 11:21 AM
Cool! Thanks man. And um…in a fit of frustration I deleted everything a couple of hours ago and went to to watch tv. Haha. It seems simple enough I am just missing something. I know how to get the computer to calculate an input redstone signal and I know how to transfer that information to the monitors and such. I am just missing something in the event and variables I think. I feel like I am on the brink of understanding it, but I got really tired of reading and researching and figured I'd break down and ask. Also it might have something to do with peripherals? Becasue I did try to fool around the with CCSensors mod as well. But I figured the computer just detecting a redstone signal might be easier to code? Not sure there.

And the startup kit for the different classes sounds great! I actually had that implented already (although in a dumbed down version). I just have them push a button and a dispensor spits out gear from a location they can't reach by themselves. I had thaumcraft2, weapons mod, and a couple of others for the map. So they get to kinda feel like they belong to a class with the weapons they wield and the story progresses from there. This initial section is based off of Edgar Allen Poe's "Masque of the Red Death". The player has to go through 7 different colored rooms each with progressing difficulty and there is a theme at the end. I have implemented computer craft everywhere now with monitors and special messages. And using the floppy discs they find to tell the story is really cool to. I've learned alot…just really new at all of this and working my way to the more advanced stuff. The first time I got my computer to display "Hello World!" on a big monitor on a wall I kinda wet myself a little. It's all very fascinating learning lua through playing a game…

Anyway, I'll get back with you and send you any code I work up next time I take a stab at the room.
MysticT #5
Posted 06 July 2012 - 05:32 PM
Here's an example of how to do it. I commented it so you know what it does.

local amount = 50 -- the amount of items to collect
local inputSide = "left" -- the side of the redstone input
local monitorSide = "back" -- the side the monitor is on
local textScale = 3 -- the text size (1-5)

local count = 0 -- the current item count

-- setup monitor
local monitor = peripheral.wrap(monitorSide)
monitor.setTextScale(textScale)
term.redirect(monitor)

local function clear()
  -- clear the screen
  term.clear()
  term.setCursorPos(1, 1)
end

local bLastInput = false

while true do
  clear()
  write(count.."/"..amount) -- write the current amount and total (current/total)
  os.pullEvent("redstone") -- wait for redstone change
  local input = rs.getInput(inputSide) -- get the input on the input side
  if input ~= bLastInput then -- if it's different than the last one (i.e. it changed, it's a pulse)
	if input then -- if the input is on
	  count = count + 1 -- add to the count
	  if count == amount then
		-- the total amount was reached, do something
		break -- exit the loop, remove it if you don't want it to stop
	  end
	end
	bLastInput = input -- set the last input to the new one
  end
end

clear() -- clear the monitor
-- you can print some text to the monitor here, and it should stay until the next restart.
term.restore() -- restore the output to the terminal
It should work as it is, but you may want to do some changes.
Hope it helps.
Cast #6
Posted 06 July 2012 - 08:14 PM
Hey thanks! I've been working at it again. Failing but learning more. I guess I'll just copy this and give it a try. I did get pretty far…and I understand most of the code you put. There were just a couple of things I couldn't find while trying to research. I'm going through the Lua basics guide right now heh. I had my if/then statements close and I knew it was a pullEvent that I needed for the current to tick up the math…but I got stuck trying to define variables (I was trying to define the redstone pulse as a variable) and such and apply that logic to the program when I wanted it to represent a summation tally. And I would have never thought of bLastInput. It is just stuff I havn't learned yet. Oh well. I was close. Another week and I would have broken through. Haha.

My hats off for the help. I'll study this and see what other CC contraptions I can create.
Cast #7
Posted 06 July 2012 - 08:59 PM
Hmmm. There seems to be a problem with this line. I keep getting an unexpected symbol error. I changed rs to redstone by chance (since that is how its listed in the api, but doesn't seem to be the solution)

local input == rs.getInput(inputSide)
Cast #8
Posted 06 July 2012 - 09:02 PM
Okay so I just changed it to

local input = redstone.getInput(inputSide)

and it works! Wootness. Now I can move on with my life. :P/>/>

Once again very much appreciated!!!
MysticT #9
Posted 06 July 2012 - 09:03 PM
Ups, it should be:

local input = rs.getInput(inputSide)
Already fixed above.
Cast #10
Posted 06 July 2012 - 09:05 PM
No problem my friend. I bow before your awesomeness in much appreciation. I am literally sitting here in front of a monitor punching a redstone button and watching the numbers ascend with glee. And its all because of you. Ha! …now to go take some migraine medicine. :P/>/>