CEL date today?

All about writing scripts for Celestia in Lua and the .cel system
Topic author
rthorvald
Posts: 1223
Joined: 20.10.2003
With us: 21 years 3 months
Location: Norway

CEL date today?

Post #1by rthorvald » 01.03.2008, 16:31

Looking through the available guides, and browsing through a lot of scripts, i cannot seem to find a CEL command to return to the current date / time if i have already visited other dates in the script. I don??t want a spesific time, i want to return to NOW, whenever NOW is.

Anybody know?

Thanks,
- rthorvald
Image

Avatar
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 19 years 1 month

Post #2by Chuft-Captain » 01.03.2008, 17:06

Dunno about CEL, but you can do it in celX..

Save the current time:

Code: Select all

  orig_time = celestia:gettime()

.
.
.
then at a later point in the script, reset to the saved time:

Code: Select all

  celestia:settime(orig_time )
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

Topic author
rthorvald
Posts: 1223
Joined: 20.10.2003
With us: 21 years 3 months
Location: Norway

Post #3by rthorvald » 01.03.2008, 17:59

Aha! Many thanks :-D

- rthorvald
Image

Avatar
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 10 months
Location: Thyrrenian sea

Re: CEL date today?

Post #4by Fenerit » 01.03.2008, 19:00

rthorvald wrote:Looking through the available guides, and browsing through a lot of scripts, i cannot seem to find a CEL command to return to the current date / time if i have already visited other dates in the script. I don??t want a spesific time, i want to return to NOW, whenever NOW is.

Anybody know?

Thanks,
- rthorvald


Indeed... Otherwise, often Celestia need to restart.
Never at rest.
Massimo

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 20 years
Location: Nancy, France

Post #5by Vincent » 02.03.2008, 15:51

Chuft-Captain wrote:then at a later point in the script, reset to the saved time:

Code: Select all

  celestia:settime(orig_time)

Don't forget to add the time that has passed since orig_time was saved (what should be done at the very beginning of the script): tnow = t0 + dt

Code: Select all

   script_time = celestia:getscripttime()
   celestia:settime(orig_time + (script_time/86400))
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Avatar
LordFerret M
Posts: 737
Joined: 24.08.2006
Age: 68
With us: 18 years 5 months
Location: NJ USA

Post #6by LordFerret » 03.03.2008, 05:07

There's no access to "os.date ([format [, time]])" or "os.time ([table])" ?

chris
Site Admin
Posts: 4211
Joined: 28.01.2002
With us: 23 years
Location: Seattle, Washington, USA

Post #7by chris » 03.03.2008, 05:32

The lack of a celx function to get the current system time seems like a significant omission to me, as does the lack of a cel script command to set the simulation time to the current system time. In celx, I think we should add a method called getsystemtime() that returns a Julian date for the current system time.

--Chris

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 20 years
Location: Nancy, France

Post #8by Vincent » 03.03.2008, 17:22

LordFerret wrote:There's no access to "os.date ([format [, time]])" or "os.time ([table])" ?
The os library is accessible from a Lua Hook context, but not in celx scripting. As an example, I use the following function in the Lua Tools to set the time to the current system time:

Code: Select all

local setCurrentTime = function()
   local UTCtime = os.date("!*t");
   celestia:settime(celestia:utctotdb(UTCtime.year, UTCtime.month, UTCtime.day, UTCtime.hour, UTCtime.min, UTCtime.sec));
end


chris wrote:The lack of a celx function to get the current system time seems like a significant omission to me, as does the lack of a cel script command to set the simulation time to the current system time. In celx, I think we should add a method called getsystemtime() that returns a Julian date for the current system time.

I'll mind this as soon as possible...
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 4 months
Location: NY, USA

Post #9by selden » 03.03.2008, 19:59

LordFerret wrote:There's no access to "os.date ([format [, time]])" or "os.time ([table])" ?


I suspect you'll get access to that library if you add these two lines to the beginning of your Celx script:

celestia:requestsystemaccess()
wait(0)

Also, you may want to change the line in celestia.cfg which says
ScriptSystemAccessPolicy "ask"
to be
ScriptSystemAccessPolicy "allow"
Selden

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 20 years
Location: Nancy, France

Post #10by Vincent » 03.03.2008, 21:30

selden wrote:I suspect you'll get access to that library if you add these two lines to the beginning of your Celx script:

celestia:requestsystemaccess()
wait(0)

Also, you may want to change the line in celestia.cfg which says
ScriptSystemAccessPolicy "ask"
to be
ScriptSystemAccessPolicy "allow"

Selden,

I tried this before posting my answer, but it didn't work...
Looks like the os library is not part of the standard Lua libraries.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 4 months
Location: NY, USA

Post #11by selden » 04.03.2008, 11:43

Vincent,

If the os. table can be accessed from the LuaHook environment, and if requestsystemaccess returns true,
then it is a *bug* that the os. table is nil when called from a celx script.
Selden

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 20 years
Location: Nancy, France

Post #12by Vincent » 04.03.2008, 12:12

selden wrote:Vincent,

If the os. table can be accessed from the LuaHook environment, and if requestsystemaccess returns true,
then it is a *bug* that the os. table is nil when called from a celx script.

Selden,

You're right ! The following script works with no problem when ScriptSystemAccessPolicy is set to "allow" in celestia.cfg:

Code: Select all

-- Title: Set time to the current system time

celestia:requestsystemaccess()
wait(0)

local setCurrentTime = function()
   UTCtime = os.date("!*t");
   celestia:settime(celestia:utctotdb(UTCtime.year, UTCtime.month, UTCtime.day, UTCtime.hour, UTCtime.min, UTCtime.sec));
end

setCurrentTime()


I made my first test with ScriptSystemAccessPolicy set to "ask", replying 'yes' to the access request displayed on screen. I thought that this was equivalent to setting ScriptSystemAccessPolicy to "allow", but that didn't work.
Is there a reason for this, or is this a bug ?
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 4 months
Location: NY, USA

Post #13by selden » 04.03.2008, 12:30

Vincent,

It's obviously a bug. I'm submitting it to tracker on SF.
Selden

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 20 years
Location: Nancy, France

Post #14by Vincent » 04.03.2008, 17:01

selden wrote:Vincent,

It's obviously a bug. I'm submitting it to tracker on SF.

Selden,

Actually, this bug doesn't occure with a version of Celestia built against Lua 5.0. It only happens with Celestia built against Lua 5.1. I'll continue this discussion on the Sourceforge tracker...
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 20 years
Location: Nancy, France

Post #15by Vincent » 04.03.2008, 17:27

selden wrote:Vincent,

It's obviously a bug. I'm submitting it to tracker on SF.

I've posted a fix on the SourceForge bug tracker.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 20 years
Location: Nancy, France

Post #16by Vincent » 05.03.2008, 12:18

chris wrote:In celx, I think we should add a method called getsystemtime() that returns a Julian date for the current system time.

I've added the new celestia:getsystemtime() celx method to SVN.
This method returns the current system time as a TDB Julian Date.

As an example, one can set Celestia simulation time to the current system time using:

Code: Select all

sysTime = celestia:getsystemtime()
celestia:settime(sysTime)
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 20 years
Location: Nancy, France

Post #17by Vincent » 05.03.2008, 13:35

chris wrote:The lack of a celx function to get the current system time seems like a significant omission to me, as does the lack of a cel script command to set the simulation time to the current system time.

I'm not sure about how the cel command to set the simulation time to the current system time should look like...

The 'time' cel command currently accepts either a Julian Date or a UTC calendar Date:

Code: Select all

time { jd 2454531.00075 }
or

Code: Select all

time { utc "2008-03-05T12:00:0.0000" }


So what about simply using

Code: Select all

 time { system }
or

Code: Select all

 time { system "now"}
?

Other suggestions ?
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3


Return to “Scripting”