|
| 07 Jan 2014 04:46 PM |
Ok so before you go TL;DR, I cut out as much as I can. You can just skim through the minigame to get an idea.
The problem here is I first say the variable ClockRunning is false, then stuff happens in inside a function I say ClockRunning is true. But a loop that says while ClockRunning == true do doesn't start up...
local blue = 0 local GameEnded = true local GameRunning = script.GameRunning.Value local ClockRunning = false script.Minutes.Value = 3 script.Seconds.Value = 0
-------------------------------------------------------- -- Timer Stuffs while ClockRunning == true do wait(1) script.Seconds.Value = script.Seconds.Value - 1 if script.Seconds.Value < 0 then script.Seconds.Value = 59 script.Minutes.Value = script.Minutes.Value - 1 end end -------------------------------------------------------- -- End the Game function EndGame() ClockRunning = false script.Minutes.Value = 0 script.Seconds.Value = 0 -- something that kills the players and changes their team wait(8) showMessage(getWinningTeamString()) -- showMessage is a function that shows a gui wait(5) hideMessage() -- take a guess GameEnded = true -- This is exactly like the while clockrunning loop... but this one works end -------------------------------------------------------- -- Runthrough of Game function RunGame() for i=1,36 do print("Checking Players") CheckPlayers() wait(5) if blue == 0 then EndGame() break end end if blue ~= 0 then EndGame() end end -------------------------------------------------------- -- The Actual Starting of the Game function startGame() if GameRunning == true then wait(2) -- move all players to blue team, pick one and move him to green, kill everyone. wait(8) showMessage("Zombies have 3 minutes to infect all Humans.") script.Minutes.Value = 3 script.Seconds.Value = 0 wait(5) ClockRunning = true --[[The while ClockRunning == true do loop doesn't start even though I said this]] hideMessage() RunGame() end end -------------------------------------------------------- while GameEnded == true do -- This one works but the clockrunning one doesn't? --blah blah, make GameRunning true and GameEnded false end |
|
|
| Report Abuse |
|
|
|
| 07 Jan 2014 05:10 PM |
| Could anyone skim through it and see if it's some silly mistake or something. I can't find anything |
|
|
| Report Abuse |
|
|
|
| 07 Jan 2014 05:13 PM |
What is the problem. If you don't know, narrow down the lines with prints.
Btw while variable do works aswell. |
|
|
| Report Abuse |
|
|
wubbzy301
|
  |
| Joined: 15 May 2010 |
| Total Posts: 1188 |
|
|
| 07 Jan 2014 05:14 PM |
Can you give me a error on the output? Example: script.Parent.Script - Line 1337 |
|
|
| Report Abuse |
|
|
|
| 07 Jan 2014 05:16 PM |
| No error, and I tried using prints. it simply doesn't want to start the clock. :/ |
|
|
| Report Abuse |
|
|
| |
|
robotmega
|
  |
| Joined: 16 May 2009 |
| Total Posts: 14084 |
|
| |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 07 Jan 2014 09:35 PM |
You're most likely problem is that the loop is that when you use: "while condition do" and the condition becomes false, the loop stops. When that condition becomes true (which it is false in the beginning) then nothing happens, I'm not sure if you thought it's going to start the loop when the variable becomes true |
|
|
| Report Abuse |
|
|
|
| 07 Jan 2014 09:38 PM |
| Ok so just remove the local ClockRunning = false in the beginning and change it to like local ClockStopped = true and have it check for while ClockRunning = false do? |
|
|
| Report Abuse |
|
|
|
| 07 Jan 2014 09:39 PM |
Try this:
corotuine.resume(coroutine.create(function() while wait(1) do if ClockRunning then script.Seconds.Value = script.Seconds.Value - 1 if script.Seconds.Value < 0 then script.Seconds.Value = 59 script.Minutes.Value = script.Minutes.Value - 1 end end end end)) |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 07 Jan 2014 09:40 PM |
It depends, do you want that loop to run when it becomes true? If so you would have to call a function that does that loop after you set it to true, or wrap an infinite loop in a thread that has a conditional statement to check if it's true.
In example: coroutine.wrap(function() while true do if whatever == true then --code end end end)() |
|
|
| Report Abuse |
|
|
|
| 07 Jan 2014 09:45 PM |
Wait is it because I'm trying to run both RunGame() and that clock loop at the same time? If so I can do a workaround and place it in a different script. |
|
|
| Report Abuse |
|
|
|
| 07 Jan 2014 09:46 PM |
Ah, that's where coroutines come in. They allow you to run loops and functions sperate from your code so they don't make it stop working
To make a coroutine without any fancy business, just use:
coroutine.resume(coroutine.create(function() --code end)) |
|
|
| Report Abuse |
|
|
|
| 07 Jan 2014 09:48 PM |
"Ah, that's where coroutines come in. They allow you to run loops and functions separate from your code so they don't make it stop working"
Let me rephrase that,
"Ah, that's where coroutines come in. They allow you to run loops and functions separate from your code so it doesn't get stuck on a loop"
|
|
|
| Report Abuse |
|
|
|
| 07 Jan 2014 09:48 PM |
@dog
Ok can you fit that in with my while ClockRunning == true do loop? I've never done corountines before |
|
|
| Report Abuse |
|
|
|
| 07 Jan 2014 09:50 PM |
Yes, I already did, a couple posts above.
It's EXTREMELY simple to do, you just put your code inside of a coroutine if you don't want to it get stuck. Memorize the heck out of these two lines:
coroutine.resume(coroutine.create(function() --put yo loop in here end)) |
|
|
| Report Abuse |
|
|
|
| 07 Jan 2014 09:53 PM |
Gotcha.
So when I say
ClockRunning = true RunGame()
It will start up that loop and do RunGame at the same time? |
|
|
| Report Abuse |
|
|
|
| 07 Jan 2014 09:54 PM |
| It should, If you added the coroutine correctly. |
|
|
| Report Abuse |
|
|
|
| 08 Jan 2014 03:32 PM |
and the clock didn't start... no errors
this is what I have
coroutine.resume(coroutine.create(function() while ClockRunning == true do wait(1) script.Seconds.Value = script.Seconds.Value - 1 if script.Seconds.Value < 0 then script.Seconds.Value = 59 script.Minutes.Value = script.Minutes.Value - 1 end end end))
ClockRunning = true |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2014 10:08 PM |
coroutine.resume(coroutine.create(function() while wait(1) do if ClockRunning then script.Seconds.Value = script.Seconds.Value - 1 if script.Seconds.Value < 0 then script.Seconds.Value = 59 script.Minutes.Value = script.Minutes.Value - 1 end end end))
ClockRunning = true
Try that. |
|
|
| Report Abuse |
|
|