getinfo: how does it work?

All about writing scripts for Celestia in Lua and the .cel system
Topic author
Malenfant
Posts: 1412
Joined: 24.08.2005
With us: 19 years 3 months

getinfo: how does it work?

Post #1by Malenfant » 24.10.2005, 21:19

How does getinfo work?

I'm trying to get the albedo of the selected object in a script.

Code: Select all

KM_PER_LY = 9.46728E12
KM_PER_AU = 149600000
camera = celestia:getobserver()
planet = celestia:find("Mars") -- finds object named Mars
camera:center(planet,1)
celestia:select(planet)
cameraPosition = camera:getposition() -- gets position of observer
planetPosition = planet:getposition() -- gets position of Mars
distance = planetPosition:distanceto(cameraPosition) -- gets distance from  position of Mars to that of observer
distAU = distance/KM_PER_AU
celestia:flash("Current distance to Mars is "..distAU.. " AU")
wait(2)
albedo = planet:getinfo(albedo)
radius = planet:radius()
planmag = -26.73 - (5 * (math.log10(((math.sqrt(albedo))*radius)/149600000)))


When I run this it returns the distance with no problem, but says that:

"in line 13, no arguments expected to function object:getinfo"

So how do I tell it to extract the albedo of the planet and use that in the planmag equation?


Also, is it possible to round off the numbers shown on the screen? Currently they're shown to way too many decimal places.


BTW, I think Harald's site would be even more useful than it is if he had some actual examples of how the commands are actually used in practise, instead of just a 'general case'.

BrainDead
Posts: 238
Joined: 27.08.2005
With us: 19 years 2 months
Location: Germantown, OH

Post #2by BrainDead » 24.10.2005, 23:40

Malenfant,

From Harry's CELX Guide:

getinfo ()
Return a table containing all available information on this object. The
exact content of the table depends on what type of object it is. For
example, a table for a star will include the keys: type, catalogNumber,
stellarClass, absoluteMagnitude, luminosity, radius, temperature,
rotationPeriod, and bolometricMagnitude.
Example: info_tbl = myObject:getinfo()


Seems that you need an empty set of parens for the function, and that you
have to know what is returned based on the type of object.

Also, you're defining a variable called "albedo." You may simply wish to
flash this variable after the getinfo() is performed just to see what it
does contain.

Thoughts from the Brain-Dead. :wink:
Brain-Dead Bob

Windows XP-SP2, 256Meg 1024x768 Resolution
Intel Celeron 1400 MHz CPU
Intel 82815 Graphics Controller
OpenGL Version: 1.1.2 - Build 4.13.01.3196
Celestia 1.4.1

BrainDead
Posts: 238
Joined: 27.08.2005
With us: 19 years 2 months
Location: Germantown, OH

Post #3by BrainDead » 25.10.2005, 00:44

Malenfant wrote:Also, is it possible to round off the numbers shown on the screen? Currently they're shown to way too many decimal places.


Code: Select all

celestia:flash("TEXT"..string.format("%i",VARIABLE).." TEXT",5)

This will revise the printed value to become an integer. I've asked Hank
how he knew about this, because I certainly can't find it in anything I have
regarding documentation. See the Wikibook site for more.

The ..string.format("%i", is the integer function? Operative? Edit Code?

Thanks again Hank.
Brain-Dead Bob



Windows XP-SP2, 256Meg 1024x768 Resolution

Intel Celeron 1400 MHz CPU

Intel 82815 Graphics Controller

OpenGL Version: 1.1.2 - Build 4.13.01.3196

Celestia 1.4.1

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

Re: getinfo: how does it work?

Post #4by hank » 25.10.2005, 00:55

Malenfant wrote:So how do I tell it to extract the albedo of the planet and use that in the planmag equation?
I believe what you want is:

Code: Select all

info = object:getinfo()
albedo = info.albedo

Malenfant wrote:Also, is it possible to round off the numbers shown on the screen? Currently they're shown to way too many decimal places.
You can use, e.g.:

Code: Select all

string.format("%10.3f",albedo)

The first argument is a C-style output format control string. A %f conversion specification indicates the minimum field width (here 10) and the number of digits to the right of the decimal point (here 3).

- Hank

Topic author
Malenfant
Posts: 1412
Joined: 24.08.2005
With us: 19 years 3 months

Post #5by Malenfant » 25.10.2005, 00:56

Thanks, I'll try the integer thing.

I can't flash the albedo variable because it crashes out with the error message when I try the getinfo. I've tried it without anything in the brackets (ie planet.getinfo() ) too. So if anyone knows how that works then I'd appreciate an explanation.

BTW, should we post script questions here or on the wikibook? Personally I'd rather post my questions here.

Topic author
Malenfant
Posts: 1412
Joined: 24.08.2005
With us: 19 years 3 months

Post #6by Malenfant » 25.10.2005, 01:03

Got it - thanks Hank.

So if I wanted other parts of the info as well as the albedo, would I have to write info = planet:getinfo() more than once for each time? Or is it something you only type in once and it keeps the data in memory to refer to, so I'd just have to type period=info.OrbitPeriod after the albedo=info.albedo if I wanted the orbital period too) ?

And what if you want info on more than one body in a script? Do you have to clear the memory somehow?

Code: Select all

KM_PER_LY = 9.46728E12
KM_PER_AU = 149600000
camera = celestia:getobserver()
planet = celestia:find("Mars") -- finds object named Mars
camera:center(planet,1)
celestia:select(planet)
cameraPosition = camera:getposition() -- gets position of observer
planetPosition = planet:getposition() -- gets position of Mars
distance = planetPosition:distanceto(cameraPosition) -- gets distance from  position of Mars to that of observer
distAU = distance/KM_PER_AU
celestia:flash("Current distance to Mars is "..distAU.. " AU")
wait(2)
info = planet:getinfo()
albedo = info.albedo
celestia:flash("Mars albedo is "..albedo)
wait(2)
radius = planet:radius()
planmag = -26.73 - (5 * (math.log10(((math.sqrt(albedo))*radius)/149600000)))
celestia:flash("Absolute magnitude of Mars is "..planmag)

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

Post #7by selden » 25.10.2005, 17:41

At the request of the person who started this thread (Malenfant) I attempted to split this thread into two parts. Unfortunately, contrary to the documentation, it split the thread *before* the selected post instead of after it. *grump*

Here's the answer by Hank that should have been left in this thread:
Hank wrote:Posted: Mon Oct 24, 2005 9:14 pm
Malenfant wrote:So if I wanted other parts of the info as well as the albedo, would I have to write info = planet:getinfo() more than once for each time? Or is it something you only type in once and it keeps the data in memory to refer to, so I'd just have to type period=info.OrbitPeriod after the albedo=info.albedo if I wanted the orbital period too) ?

And what if you want info on more than one body in a script? Do you have to clear the memory somehow?

You call getinfo once for each object and it returns a table with entries for each parameter. You store the result in a variable (e.g. "info") and then access the individual entries by name. (But be sure to get the capitalization right, as indicated in harry's CELX documentation.)

- Hank
Selden

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

Post #8by hank » 25.10.2005, 18:00

(post deleted)
Last edited by hank on 25.10.2005, 21:50, edited 1 time in total.

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

Post #9by hank » 25.10.2005, 18:07

(post deleted)
Last edited by hank on 25.10.2005, 18:27, edited 2 times in total.

Topic author
Malenfant
Posts: 1412
Joined: 24.08.2005
With us: 19 years 3 months

Post #10by Malenfant » 25.10.2005, 18:10

hank wrote:Unfortunately, you split the thread while I was in the middle of an edit. You'lll need to move my post above to the other thread. Is it now going to be your policy to splt a thread whenever an off-topic discussion develops? That would actually be a very good thing, but you're going to be busy.

- Hank


Actually I asked him to split it myself. I figured The wiki/forum discussion was too important to have lost in a 'getinfo' thread :).

I think it's probably easier all round if you just go to edit your post, copy all your text (paste it on a notepad first perhaps, just to be safe), delete that post, and then repost the text on the other thread yourself. And then we can continue the discussion there.


Return to “Scripting”