More CELX newbie incomprehension

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 1 month
Location: Norway

More CELX newbie incomprehension

Post #1by rthorvald » 27.07.2007, 18:40

Can someone please show me why this simple snippet does not work? I am probably handicapped by my meagre knowledge of other scripting languages, because i am totally unable to see where this breaks down; it _should_ look like this.

Code: Select all

mydate = celestia:gettime()
if (mydate)  > "2454296.5"
celestia:flash(mydate)
else
celestia:flash("2454296.5")
end

... As you can see, this should print the current date to screen if the date is later than july 15th, and print the july 15th date if it is not. But it won??t print anything at all...

Thanks for any input,
- rthorvald
Image

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

Post #2by selden » 27.07.2007, 19:07

Which version of Celestia are you running on your Mac?

Under XP with Celestia v1.5.0 from cvs, I get a popup message which complains that a "then" is missing.
[edit]
And after that's fixed it complains that you're trying to compare a number with a string: delete all of the quotes.
[/edit]
Selden

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

Post #3by selden » 27.07.2007, 19:14

This works for me:

Code: Select all

mydate = celestia:gettime()

if (mydate  > 2454296.5 )
then
s = string.format(" mydate = %f",mydate)
celestia:print(s,5)
else
celestia:print(" mydate <= 2454296.5",5)
end
Selden

Topic author
rthorvald
Posts: 1223
Joined: 20.10.2003
With us: 21 years 1 month
Location: Norway

Post #4by rthorvald » 27.07.2007, 19:55

Thank you, Selden!
Great help in learning the syntax.

- rthorvald
Image


Return to “Scripting”