From 7ca8a9346f5b6a3aa830da400a6b1826a6671ec7 Mon Sep 17 00:00:00 2001 From: Sorvani Date: Tue, 9 Jul 2013 07:09:10 -0700 Subject: [PATCH] an example of how to track time --- Lua-Examples.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Lua-Examples.md b/Lua-Examples.md index 5cbb186..f8c4528 100644 --- a/Lua-Examples.md +++ b/Lua-Examples.md @@ -56,6 +56,27 @@ function event_trade(e) end ``` +``` +-- this is an example of how to track time on an NPC. +function event_spawn(e) + -- time_a is declared global to be available later. + time_a = os.time(); + -- os.time(); returns an integer value in seconds. + e.self:Shout("The time is now: "..time_a); +end + +function event_say(e) + -- time_b is local because we have no need for it to be global, though the script would work both ways + local time_b = os.time(); + if(e.message:findi("hail")) then + e.self:Say("The time is now: "..time_b); + -- os.difftime(t2,t1) returns an integer value in seconds t2-t1 + local time_diff = os.difftime(time_b,time_a); + e.self:Say("It has been "..time_diff.." seconds since I spawned"); + end +end +``` + ### Player ``` -- player.lua example of access and changing the lockpick value of a door.