View Full Version : date calculation bug (or me?:-)
barca0
April 20th, 2006, 10:49 AM
lua:
local now = date.now ()
local c = now
local d = now
print ('c:') print (c)
c.Minute = c.Minute + 10
print ('c before:') print (c)
d.Minute = d.Minute - 10
print ('c after:') print (c)
console:
c:
20.04.2006/20:42:43
c before:
20.04.2006/20:52:43
c after:
20.04.2006/20:42:43
now how on earth can "c" change after an operation on "d" ???
txs in advance
barca
Rob H
April 20th, 2006, 11:15 AM
c and d both reference the same table
barca0
April 20th, 2006, 11:23 AM
....mhhh, actually I am a marketing guy. can you give me a hint on how to make two different variables out of a time in order to have a timespan?
birty
April 20th, 2006, 11:27 AM
d = table.copy (c)
barca0
April 20th, 2006, 11:56 AM
thanks birty! but since it did not let me calculate with it, I just derived the variables from the origin. itīs to have day, evening, night, etc.
local beforesunrise = date:new (sunrise)
local aftersunrise = date:new (sunrise)
beforesunrise.Minute = beforesunrise.Minute -30
aftersunrise.Minute = aftersunrise.Minute + 50
Todd Reed
April 22nd, 2006, 09:36 AM
I can't even get the date:now() function to work??
local d = date:now()
print (d)
Gives me...
[string "Todd's:\X10\Scripting"]:1: attempt to call field `now' (a nil value)
stack traceback:
[string "Todd's:\X10\Scripting"]:1: in main chunk
:cry:
Promixis
April 22nd, 2006, 10:00 AM
make sure you require the date library using
require 'date' at the top of this file.
Todd Reed
April 22nd, 2006, 10:15 AM
require("date")
d = date:now ()
print (d)
no change...
I am not liking the new Lua... :evil:
Promixis
April 22nd, 2006, 10:25 AM
something has gone wrong with your install OR you are overwritting the date library with your own variable.
Todd Reed
April 22nd, 2006, 10:35 AM
Restarted Girder, and ran that code first thing!
Yep, I must be using 'date' somewhere else...
Got to be carefull!!
:roll:
Promixis
April 22nd, 2006, 10:36 AM
Restarted Girder, and ran that code first thing!
Yep, I must be using 'date' somewhere else...
Got to be carefull!!
:roll:
yup, try to never ever ever use global variables...
Powered by vBulletin® Version 4.2.2 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.