Data Realms Fan Forums
http://45.55.195.193/

Timer troubles
http://45.55.195.193/viewtopic.php?f=73&t=21648
Page 1 of 1

Author:  Darkdoom [ Sat Mar 05, 2011 1:25 am ]
Post subject:  Timer troubles

First of all, you attach a script with
Code:
ScriptFile = ContentFile
[tab]FilePath = pathandstuff

right?
Second of all
a timer would go like
Code:
function Create(self)
[tab]self.timer = Timer()
end

function Update(self)
codeandsuch
[tab]timer.TimeTillSimMS(#s)
end

right?

Finnaly how would i reset that and maybe make a cooldown sequence so you cant exploit the code to constantly use the code controlled by said timer?

Author:  Asklar [ Sat Mar 05, 2011 1:35 am ]
Post subject:  Re: Timer troubles

You attached the script wrongly.

To attach you simply use ScriptPath = Mod.rte/Bla/TheFile.lua

Now, one thing with lua is that tabbing doesn't really matter.

And to reset timers you use TimerName:Reset();

Author:  TheLastBanana [ Sat Mar 05, 2011 1:54 am ]
Post subject:  Re: Timer troubles

Tabbing doesn't matter to the parser, but it does matter for readability. I'm way more likely to help somebody whose code is tabbed and readable (or, hey, you could even put in comments) than if their code is a big lump of characters.
Anyway, back on-topic:
Your Update function wouldn't do anything, currently - Timer:LeftTillSimMS() returns how long it'll be before a time is reached (in milliseconds). As well, you left out the "self." before the timer. As well, make sure that when you're calling a function, you use ":", not ".". This code would work, if you want the code to execute when 3 seconds has passed:
Code:
function Create(self)
[tab]self.timer = Timer()
end

function Update(self)
[tab]if self.timer.IsPastSimMS(3000) then
[tab][tab]<do something>
[tab]end
end

Author:  Darkdoom [ Sat Mar 05, 2011 2:00 am ]
Post subject:  Re: Timer troubles

EDIT: ninja'd

ok I will try that

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/