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

Progressive mob arena!

Started by dombomb132, 04 March 2013 - 09:15 AM
dombomb132 #1
Posted 04 March 2013 - 10:15 AM
I am working on making a mob arena which gets harder as time passes. I'm using computercraft and soul shards to do this but need help with a program that lets a spawner spawn mobs every 20 seconds or so, i've written a program but it doesn't work as it seems to ignore the "if round < 30 then" or whatever and do the code even if that if statement is wrong

So here's the program:
sec = 0
round = 1

while true do

if sec==60 then
sec = 0
round = round + 1
end

sec = sec + 20

if redstone.getInput("right", true) then
if round > 30 then
if round < 51 then
redstone.setOutput("back", false)
sleep(2)
redstone.setOutput("back", true)
term.clear()
sleep(18)
end
end

if round > 50 then
if round < 71 then
redstone.setOutput("back", false)
sleep(4)
redstone.setOutput("back", true)
sleep(16)
end
end

if round > 70 then
if round < 101 then
redstone.setOutput("back", false)
sleep(6)
redstone.setOutput("back", true)
sleep(14)
end
end
end

if redstone.getInput("left", true) then
redstone.setOutput("back", true)
term.clear()
term.setCursorPos(1, 1)
print("There's no round in play.")
round = 1
sec = 0
sleep(1)
end
end

Thankyou, please help!!
Cranium #2
Posted 04 March 2013 - 04:32 PM
Moved to Ask a Pro. In the future, please read the stickies and forum guidelines before posting wherever you want.
SuicidalSTDz #3
Posted 04 March 2013 - 04:55 PM
Please use code format and spoilers

Spoiler
This looks much neater and it's in a spoiler!

Why do you use two if statements when detecting the round number?
remiX #4
Posted 04 March 2013 - 06:15 PM
Read comments

Spoiler
while true do

	if sec == 60 then
		sec = 0
		round = round + 1
	end

	sec = sec + 20
	
	-- Is all the checking of round in the block of checking the redstone signal on the right? If it is, you had it wrong - it's right now
	if redstone.getInput("right", true) then
		if round > 30 then -- for this, instead of having two if statements, you can do this: if round > 30 and round < 51 then ...
			if round < 51 then
			redstone.setOutput("back", false)
			sleep(2)
			redstone.setOutput("back", true)
			term.clear()
			sleep(18)
			end -- you were missing an end here
		end

		if round > 50 then
			if round < 71 then
				redstone.setOutput("back", false)
				sleep(4)
				redstone.setOutput("back", true)
				sleep(16)
			end
		end

		if round > 70 then
			if round < 101 then
				redstone.setOutput("back", false)
				sleep(6)
				redstone.setOutput("back", true)
				sleep(14)
			end -- you had an extra end here
		end
	end

	if redstone.getInput("left", true) then
		redstone.setOutput("back", true)
		term.clear()
		term.setCursorPos(1, 1)
		print("There's no round in play.")
		round = 1
		sec = 0
		sleep(1)
	end
end
dombomb132 #5
Posted 05 March 2013 - 05:08 AM
I use two if statements cause i'm new to computercraft and don't know everything about it yet…
dombomb132 #6
Posted 05 March 2013 - 05:24 AM
Don't know how to make spoilers but the extra end is to end the if redstone.getInput("right", true) statement. There wasn't a missing end at the beggining either and i've made the and statements but i found the problem, it was that when there was a redstone signal on the right but the round wasn't high enough, it didn't know what to do so it ignored the "if round > 30 then" statement and did the code below it for some reason so i made a new if statement saying if the round was lower then it would clear the screen and set the cursor to the start and then print that the round isn't high enough. Thankyou though :)/>