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

How do you keep a Program going?

Started by Surprise655, 20 April 2016 - 04:50 PM
Surprise655 #1
Posted 20 April 2016 - 06:50 PM
I am making a Loot Generator for a Zombie Server I want to present this to or use myself. Anyway, I am trying to make the program restart itself so the next person and get loot after 15 mins.

Would you reboot it to run in again after it sleeps for 15 mins or something else?
KingofGamesYami #2
Posted 20 April 2016 - 08:25 PM
Utilize a while loop
Surprise655 #3
Posted 21 April 2016 - 04:43 PM
How would I code it? Cause if I would have to put the whole program in a BIG While loop. So I am bit confused not going to lie. I know what you are talking about. Just how is my question
Bomb Bloke #4
Posted 21 April 2016 - 05:00 PM
If you want to repeat the whole content of the script, then yeah, you wrap it all within your "while" loop.

Odds are you'll have some variables you're declaring or somesuch that could go above the loop, though you should know what you want repeated and what you don't. If you're really stuck, post what you've written so far.
Surprise655 #5
Posted 22 April 2016 - 06:50 PM
This is what I have:
eir1Guns = {4959, 4954, 4977, 4983, 4984, 4986, 4975, 4998, 5001, 5002, 4991, 4990, 9130, 5126, 5134, 5225, 5068, 5083, 5113, 5025, 5115}
Teir1Ammo = {4675, 4759, 4783, 4741, 4600, 4601, 4591, 4611, 4613, 4596, 4596, 4563, 4606, 4584, 4590, 4752, 4607, 4769, 4582, 4791}
Teir1Misc = {4846, 4852, 5111, 5457, 4815}
– ^ Loot Tables
function LootSpawn()
X = math.random(1, 4) –Teirs of Loot
Y = math.random(1, 3) – What to Spawn(Guns, ammo, ect)
if X == 1 then
if Y == 1 then
commands.give("@p", Teir1Guns[math.random(21)], 1)
commands.give("@p", Teir1Ammo[math.random(20)], math.random(6))
end
end
end
if redstone.getInput("back") then –Player Will push a Button then get loot then take 15 mins to reset loot.
LootSpawn()
end
Bomb Bloke #6
Posted 22 April 2016 - 11:30 PM
Well, we don't need to repeat your table / function declarations, so:

local Teir1Guns = {4959, 4954, 4977, 4983, 4984, 4986, 4975, 4998, 5001, 5002, 4991, 4990, 9130, 5126, 5134, 5225, 5068, 5083, 5113, 5025, 5115}
local Teir1Ammo = {4675, 4759, 4783, 4741, 4600, 4601, 4591, 4611, 4613, 4596, 4596, 4563, 4606, 4584, 4590, 4752, 4607, 4769, 4582, 4791}
local Teir1Misc = {4846, 4852, 5111, 5457, 4815}

-- ^ Loot Tables
local function LootSpawn()
	X = math.random(1, 4) --Teirs of Loot
	Y = math.random(1, 3) -- What to Spawn(Guns, ammo, ect)
	
	if X == 1 then
		if Y == 1 then
			commands.give("@p", Teir1Guns[math.random(21)], 1)
			commands.give("@p", Teir1Ammo[math.random(20)], math.random(6))
		end
	end
end

while true do
	os.pullEvent("redstone")  --# Yield until a redstone state change occurs.

	if redstone.getInput("back") then
		LootSpawn()
		sleep(15 * 60)
	end
end
Surprise655 #7
Posted 25 April 2016 - 04:40 PM
Thanks man