Countdown
#61
@STR_Warrior
Thanks it works. What is the best method to make a repeating countdown with 10 seconds?
In the chat should be:
9
8
7
...
Reply
Thanks given by:
#62
Not sure if this is the best method (or if it works) but:
function CountDown(Param)
 cRoot:Get():BroadcastChat(Param[1])
end)

for I=1, 10 do -- Countdown.
 AddSchedule(CountDown, {I}, I * 20)) -- 20 ticks is one second right? then 1 * 20 is 20 ticks is one second etc.
end
Reply
Thanks given by:
#63
it works but it is not
9 8 7
it is:
1 2 3

And it comes this error:
Code:
[17:25:11] Stack trace:
[17:25:11]   [C](-1): (no name)
[17:25:11]   Plugins/SurvivalGames/main.lua(75): (no name)
[17:25:11] Stack trace end
[17:25:11] Error in plugin SurvivalGames calling function <callback>()
[17:25:12] LUA: Plugins/SurvivalGames/main.lua:75: attempt to index field '?' (a nil value)

The line is:
if ScheduleTable[I][3] < 0 then
Reply
Thanks given by:
#64
(01-16-2014, 02:26 AM)daniel0916 Wrote: it works but it is not
9 8 7
it is:
1 2 3
Then change
for I=1, 10 do -- Countdown.
 AddSchedule(CountDown, {I}, I * 20)) -- 20 ticks is one second right? then 1 * 20 is 20 ticks is one second etc.
end
to
local COUNT_TO = 10
for I=COUNT_TO, 1, -1 do -- Countdown
 AddSchedule(CountDown, {I}, (COUNT_TO - I) * 20))
end

Quote:And it comes this error:
Code:
[17:25:11] Stack trace:
[17:25:11]   [C](-1): (no name)
[17:25:11]   Plugins/SurvivalGames/main.lua(75): (no name)
[17:25:11] Stack trace end
[17:25:11] Error in plugin SurvivalGames calling function <callback>()
[17:25:12] LUA: Plugins/SurvivalGames/main.lua:75: attempt to index field '?' (a nil value)

The line is:
if ScheduleTable[I][3] < 0 then

When do you get the error? When it has finished counting down?
Reply
Thanks given by:
#65
(01-16-2014, 02:30 AM)STR_Warrior Wrote: When do you get the error? When it has finished counting down?

Every second and after 10 seconds the error stops.
Reply
Thanks given by:
#66
And you do still get the countdown message(9, 8, 7 etc)? Do you have anything else in the function that gets called?
Reply
Thanks given by:
#67
(01-16-2014, 02:38 AM)STR_Warrior Wrote: And you do still get the countdown message(9, 8, 7 etc)? Do you have anything else in the function that gets called?

Yes, the message come. No, i haven't anything else in this function.
Reply
Thanks given by:
#68
Could you post all your code somewhere? or send it to me using an PM. Ofcourse if you don't want to just don't do it, but I don't think I can see what's going on without seeing the code around everything.
EDIT:
Wait!! I've might found the problem. I'll have to rewrite the ScheduleTicking though. Just a sec.
Reply
Thanks given by:
#69
(01-16-2014, 02:45 AM)STR_Warrior Wrote: Could you post all your code somewhere? or send it to me using an PM. Ofcourse if you don't want to just don't do it, but I don't think I can see what's going on without seeing the code around everything.
EDIT:
Wait!! I've might found the problem. I'll have to rewrite the ScheduleTicking though. Just a sec.

(Do you know a git page where i can upload my code private? It should be safe.)

Okey, thanks.
Reply
Thanks given by:
#70
Use this code for the OnScheduleTick function:
function OnScheduleTick(Time)
	for Idx, ScheduleTask in pairs(ScheduleTable) do
		ScheduleTable[Idx][3] = ScheduleTable[Idx][3] - 1 -- Countdown
		
		if ScheduleTask[3] < 1 then
			ScheduleTask[1](ScheduleTask[2])
			ScheduleTable[Idx] = nil
		end
	end
end

If you want to post it on github privately you have to pay for it.
Reply
Thanks given by: daniel0916




Users browsing this thread: 18 Guest(s)