Celx error trace

All about writing scripts for Celestia in Lua and the .cel system
Topic author
hharris
Posts: 79
Joined: 23.02.2006
With us: 18 years 8 months
Location: Pasadena, CA 91104

Celx error trace

Post #1by hharris » 23.02.2006, 00:14

I'm sure this must have come up before so I apologize in advance. I'm new to Celx programming (although I'm an experienced programmer in C, C++, Fortran, Pascal etc.) I have a very simple question:

Are there any built-in error trace functions that I can use? I'm writing a fairly complex program and simply observing when the program doesn't work isn't very productive, especially when flash or print comments may or may not reveal what has failed. I'm sure there must be a simple answer to this, I just haven't found it in the Celx or Lua online documentation yet. Any suggestions would be appreciated.

Cheers,

Henry

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

Post #2by selden » 23.02.2006, 12:45

# summary of Lua-support in Celestia
http://www.h-schmidt.net/celestia/
by Harald Schmidt

# Documentation for the Lua language
http://www.lua.org/docs.html
http://lua-users.org/wiki/

# LUA IDE
http://www.gorlice.net.pl/~rybak/luaide/

If debugging support isn't described there, I don't know where it might be.
Selden

Topic author
hharris
Posts: 79
Joined: 23.02.2006
With us: 18 years 8 months
Location: Pasadena, CA 91104

Post #3by hharris » 24.02.2006, 19:32

I've gone through every document I could find including those. Perhaps my problem is that I've been using compiled languages for the last 30 years and I just don't understand the methodology of programming interpreters. Let me rephrase:

My current way of programming in Celx is to do it icrementally and notice when the program fails. A failure usually either means that my syntax is wrong or (and this is the hard part) I'm asking Celx to do something it was not designed to do. Compared to a compiler this is very time consuming.

For example I'm currently trying to figure out to access moons of a planet . I know that this information is contained in a table, but when I access the table with an index the program simply exits (I think). I'm thinking that the moon tables are keyed by something else besides an index. (??)

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

Post #4by selden » 24.02.2006, 20:46

The IDE might help (IDE=Integrated Development Environment).
Selden

Topic author
hharris
Posts: 79
Joined: 23.02.2006
With us: 18 years 8 months
Location: Pasadena, CA 91104

Post #5by hharris » 26.02.2006, 06:36

There are IDE's for creating scripts? I use an IDE for compiling Xcode but it never occured to me there an IDE for creatng an interpretive script.

Actually, I've solved all of problems except one and I'd be most appreciative if someone could give me a clue.

The lua manual leads me to believe that if I make the statement:
gSolMoonsAtmTable = { Titan = "N2/Ar/CH4", Moon = "rocky", Europa = "icey", Io = "ice/volcanic", Callisto = "icey" }
I can make the statement

gSolMoonsAtmTable["Titan"] and get "N2/Ar/CH4"
But it doesn't work. (???)

Henry :?

hank
Developer
Posts: 645
Joined: 03.02.2002
With us: 22 years 9 months
Location: Seattle, WA USA

Post #6by hank » 26.02.2006, 07:11

hharris wrote:There are IDE's for creating scripts? I use an IDE for compiling Xcode but it never occured to me there an IDE for creatng an interpretive script.

Actually, I've solved all of problems except one and I'd be most appreciative if someone could give me a clue.

The lua manual leads me to believe that if I make the statement:
gSolMoonsAtmTable = { Titan = "N2/Ar/CH4", Moon = "rocky", Europa = "icey", Io = "ice/volcanic", Callisto = "icey" }
I can make the statement

gSolMoonsAtmTable["Titan"] and get "N2/Ar/CH4"
But it doesn't work. (???)

Henry :?

It works for me.

Code: Select all

gSolMoonsAtmTable = { Titan = "N2/Ar/CH4", Moon = "rocky", Europa = "icey", Io = "ice/volcanic", Callisto = "icey" }
msg = gSolMoonsAtmTable["Titan"]
celestia:flash(msg,2)
wait(2)
- Hank

Topic author
hharris
Posts: 79
Joined: 23.02.2006
With us: 18 years 8 months
Location: Pasadena, CA 91104

Post #7by hharris » 27.02.2006, 01:27

Thanks Hank (I like your name BTW)!

Chalk this down to confusion from a newbie. I've only been using celx/lua for a few days and there's a lot to learn for someone who's last interpretive language was BASIC, right after it was invented in the sixties by a couple of guys from Dartmouth.

The way Celx/lua handles arrays is my favorite feature. Since the kind of programs I usually write require associative arrays anyway, having it built-in saves me a lot of time.

Cheers,

Henry :P

Topic author
hharris
Posts: 79
Joined: 23.02.2006
With us: 18 years 8 months
Location: Pasadena, CA 91104

Not so fast....

Post #8by hharris » 27.02.2006, 03:35

After a little expermentation I found that my problem with arrays turned out to be something different than I thought. The problem turned out to be in the expression

if(atmstr = gSolPlanetsAtmTable [ "Titan" ]) then
(more code)
else
atmstr = "rocky"
end

which will cause the program to refuse to run but the following will interpret just fine. Apparently the first expression is not part of the celx/lua lexicon.

if(gSolPlanetsAtmTable [ "Titan" ]) then
atmstr = gSolPlanetsAtmTable [ "Titan" ]
(more code)
else
atmstr = "rocky"
end

Henry
:roll:

hank
Developer
Posts: 645
Joined: 03.02.2002
With us: 22 years 9 months
Location: Seattle, WA USA

Re: Not so fast....

Post #9by hank » 27.02.2006, 16:22

hharris wrote:After a little expermentation I found that my problem with arrays turned out to be something different than I thought. The problem turned out to be in the expression

if(atmstr = gSolPlanetsAtmTable [ "Titan" ]) then
(more code)
else
atmstr = "rocky"
end

which will cause the program to refuse to run but the following will interpret just fine. Apparently the first expression is not part of the celx/lua lexicon.

if(gSolPlanetsAtmTable [ "Titan" ]) then
atmstr = gSolPlanetsAtmTable [ "Titan" ]
(more code)
else
atmstr = "rocky"
end

Henry
:roll:


In Lua (unlike C) an assignment is not an expression, so it can't be used as the condition in an if statement. But you could write:

Code: Select all

atmstr = gSolPlanetsAtmTable [ "Titan" ]
if (atmstr) then
     (more code)
else
   atmstr = "rocky"
end

-Hank

Topic author
hharris
Posts: 79
Joined: 23.02.2006
With us: 18 years 8 months
Location: Pasadena, CA 91104

Post #10by hharris » 28.02.2006, 20:07

Hank,

That works fine with an "if" but how would you handle it with an "elseif"? In a complicated expression with many elseifs, would I have to precalculate every possible parameter just in case I needed it? Perhaps there is a better way to handle this situation in celx?

Henry

hank
Developer
Posts: 645
Joined: 03.02.2002
With us: 22 years 9 months
Location: Seattle, WA USA

Post #11by hank » 01.03.2006, 05:49

hharris wrote:Hank,

That works fine with an "if" but how would you handle it with an "elseif"? In a complicated expression with many elseifs, would I have to precalculate every possible parameter just in case I needed it? Perhaps there is a better way to handle this situation in celx?

Henry

I don't understand what you're trying to do. Can you give an example?

- Hank

Topic author
hharris
Posts: 79
Joined: 23.02.2006
With us: 18 years 8 months
Location: Pasadena, CA 91104

Post #12by hharris » 01.03.2006, 07:42

Hi!

Well, consider the snippet below. Note that I called the function "PlanetClass" twice. True, I could avoid doing this by substituting an "else" for "elseif" but it demands a lot of messy extra logic beyond what C++ code would need?€”unless you have an easier way. (I'll probably end up winding adding the extra logic because that's probably faster than calling the function twice.)

Anyway, the good news is I've about finished my program. I can now smoothly explore the Celestia universe with simulated sensors that detect what is around me as I explore "out there". I came down with the flu a week ago and since I couldn't go anywhere, I decided to spend the time learning a new language and creating an exploration script for Celestia. I'm just about well now so it worked out pretty good.

Thanks! Let me know if you have a better way.

Henry

if( objtable) then
atm = objtable.atmosphereHeight
if(atm) then
if(atm > 0) then
atmstr = "atmos"
else
atmstr = "rocky"
end
else
atmstr = "rocky"
end
elseif (PlanetClass(radius, p_distance )) then
atmstr = PlanetClass( radius, p_distance )
else
atmstr = "rocky"
end

cpotting
Posts: 164
Joined: 18.03.2004
Age: 63
With us: 20 years 8 months
Location: Victoria, BC Canada

Post #13by cpotting » 01.03.2006, 13:18

hharris wrote:if( objtable) then
atm = objtable.atmosphereHeight
if(atm) then
if(atm > 0) then
atmstr = "atmos"
else
atmstr = "rocky"
end
else
atmstr = "rocky"
end
elseif (PlanetClass(radius, p_distance )) then
atmstr = PlanetClass( radius, p_distance )
else
atmstr = "rocky"
end


This can be expressed as

Code: Select all

if (objtable) then
   atmstr = ((objtable.atmosphereHeight > 0) and "atmos") or "rocky"
else
   atmstr = (PlanetClass(radius, p_pdistance) or "rocky")
end
It could be collapsed to one line, but that would be more confusing to read.
The conditional operators and & or offer a great "shortcut" ability in Lua.

Code: Select all

A and B
returns B if A is true and A if A is false

Code: Select all

A or B
returns A if A is true and B if A is false
This allows you to (almost) recreate the C conditional assignment

Code: Select all

x = A ? B : C
by using

Code: Select all

x = (A and B) or C


You may want to check out this online book
Last edited by cpotting on 01.03.2006, 13:33, edited 1 time in total.
Clive Pottinger
Victoria, BC Canada

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

Post #14by selden » 01.03.2006, 13:25

My more traditional (i.e. ancient) programming training would expect that to produce a bitwise Logical result (individual bits set to 1 or 0) rather than a string assignment.
Selden

cpotting
Posts: 164
Joined: 18.03.2004
Age: 63
With us: 20 years 8 months
Location: Victoria, BC Canada

Post #15by cpotting » 01.03.2006, 13:42

selden wrote:My more traditional (i.e. ancient) programming training would expect that to produce a bitwise Logical result (individual bits set to 1 or 0) rather than a string assignment.

When I first saw it I thought it would operate on purely boolean results, so that A or "text" would give always give you true because "text" is non-zero and so always true.
Clive Pottinger
Victoria, BC Canada

Topic author
hharris
Posts: 79
Joined: 23.02.2006
With us: 18 years 8 months
Location: Pasadena, CA 91104

Post #16by hharris » 01.03.2006, 20:05

Lua symbol logic is unexpected but very cool.

At first blush I was thinking that Lua was just another limited interpretive language like BASIC, but I can see now, besides being robust and fast, it has a lot of substance and subtly to it, a good choice for Celestia programming.

I want to thank everyone for their generous support on this forum. BTW, If anyone knows someone who is doing planet generation, I?€™d like to talk to them. I was doing something like that for NASA many years ago and Celestia has rekindled my interest in that subject.

Henry 8)

cpotting
Posts: 164
Joined: 18.03.2004
Age: 63
With us: 20 years 8 months
Location: Victoria, BC Canada

Post #17by cpotting » 02.03.2006, 12:57

hharris wrote:LAt first blush I was thinking that Lua was just another limited interpretive language like BASIC, but I can see now, besides being robust and fast, it has a lot of substance and subtly to it, a good choice for Celestia programming.


My impression was that Lua was a very powerful scripting language, but limited as a programming language. Then I read Roberto Ierusalimschy's book and found out the many interesting things that you can get up to in Lua.

At the moment, I am in the process of creating libraries of routines and objects for CELX.

BTW: the Lua site has a list of applications using Lua. Celestia is conspicuously missing from that list.
Clive Pottinger
Victoria, BC Canada

GlobeMaker
Posts: 216
Joined: 30.10.2005
With us: 19 years

Post #18by GlobeMaker » 05.03.2006, 18:19

Hello hharris,

You asked for someone who is active in planet generation. That is me.
What do you want to do with planets? Here is my latest work on Mars 3D.
This picture shows 3 levels of resolution from left to right :
8 points per degree, 4, and 2 points per degree.
Image

That is Valles Marineris. I am also in California, so we can have a phone call
to plan possible collaboration. See my website, linked below as w w w

You can describe your ideas here, or send me an email on the link below :
Your wish is my command line.

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

Post #19by selden » 05.03.2006, 18:48

GM,

I suspect Henry meant the production of planetary types from first principles, as is done in Accrete. I don't think he meant creating 3D models.

For example, Jim Burns' program StarGen will generate planetary systems and can output their parameters in SSC format for use with Celestia. See
http://home.comcast.net/~brons/NerdCorn ... arGen.html

StarGen and the similar programs that I've found seem to be based primarily on relatively old theories of planetary formation, dating from the mid-'80s. I haven't seen anything that incorporates the most recent theories of gravitational collapse in protoplanetary nebulas, but I haven't been looking for them, either.
Selden

Topic author
hharris
Posts: 79
Joined: 23.02.2006
With us: 18 years 8 months
Location: Pasadena, CA 91104

Post #20by hharris » 05.03.2006, 22:41

What is Accrete?

On the subject of Celestia modeling and accuracy, I have a slightly different viewpoint (I think) from the mainstream. I'd be very interested in any disagreements or agreements with the following opinion.

The following argues that dynamic modeling is at least as important as real data in a universe where most objects are invisible.

Consider a cube 20 ly on a side, centered at Sol. From statistics of the nearby interstellar enviornment, we can guess there should be approximately 144 stars in this cube. The star database that came with Celestia has 40 stars. As you travel into adjacent cubes and beyond the number rapidly drops of to a few stars/cube, in some cases zero.

The reason for this is obvious. Most stars are dim red dwarfs. The statistical probablity of a star being in any cube is inversely proportional to its mass. But except for the nearby environment the stars are unlikely to show up on any database because they're so dim, and finally invisible as you go out.

So why is this important? For two reasons. One, it means that traveling in our simulated galaxy is completely unrealistic because most stars are not there. Most people don't notice because Celestia treats objects in the universe as only existing if you can see them?€”from Earth. However if you write a script to detect nearby objects, not just ones you can see, one starts to realize how unrealistic this situation is.

But I said there was a second reason. Recently we have detected a planet (using gravity lensing) around a red dwarf. Many scientists, including myself, have come to a startling conclusion from this data point. Planets around red dwarfs are probably very common, and since red dwarfs are much more prevalent than G type stars and have stable lifetimes hundreds of times that of a G type star, we should expect , statistically speaking, that most life comes from planets around these types of stars. One might expect this to be especially true of intelligent life. However we have to invoke Fermi's Paradox here. The lower mass of the protoplanetary nebula would suggest that, on average, gas giants would be rare and terrestrial planets would be smaller. This would seem to indicate that the average extrasolar intelligent life form would have a spindly body with an out-of-proportion head with very large eyes that evolved in the spectrum of a red dwarf. Also, since such a creature wouldn't need protection from the UV spectrum, its skin would not need pigment so it would probably be gray in color. Since red dwarfs are so common we would expect to be overun with creatures like these, but since we haven't seem them, we must invoke Fermi's Paradox and conclude we must be wrong.

Henry


Return to “Scripting”