Page 1 of 1

CEL date today?

Posted: 01.03.2008, 16:31
by rthorvald
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

Posted: 01.03.2008, 17:06
by Chuft-Captain
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 )

Posted: 01.03.2008, 17:59
by rthorvald
Aha! Many thanks :-D

- rthorvald

Re: CEL date today?

Posted: 01.03.2008, 19:00
by Fenerit
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.

Posted: 02.03.2008, 15:51
by Vincent
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))

Posted: 03.03.2008, 05:07
by LordFerret
There's no access to "os.date ([format [, time]])" or "os.time ([table])" ?

Posted: 03.03.2008, 05:32
by chris
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

Posted: 03.03.2008, 17:22
by Vincent
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...

Posted: 03.03.2008, 19:59
by selden
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"

Posted: 03.03.2008, 21:30
by Vincent
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.

Posted: 04.03.2008, 11:43
by selden
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.

Posted: 04.03.2008, 12:12
by Vincent
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 ?

Posted: 04.03.2008, 12:30
by selden
Vincent,

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

Posted: 04.03.2008, 17:01
by Vincent
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...

Posted: 04.03.2008, 17:27
by Vincent
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.

Posted: 05.03.2008, 12:18
by Vincent
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)

Posted: 05.03.2008, 13:35
by Vincent
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 ?