Page 1 of 2

One button for showing constellation scheme and name

Posted: 05.01.2008, 09:47
by Imy
Hello,

Would not be interesting having cycle buttons for showing constellation schemes and constellation names?
For instance, I press a first time '/' button from keyboard, and then constellation schemes become visible, I press a second time and then is added the names of these constellations, a third press for showing only names and the last one to hide names and schemes of constellation, and you restart...
It would be quicker than always playing with panels. It may free also some letters for other functions. What do you think about that?

Thanks in advance.

Posted: 05.01.2008, 10:13
by ElChristou
Not a bad idea...

Posted: 05.01.2008, 11:05
by ANDREA
I agree absolutely, it's a good idea.
Bye

Andrea :D

Posted: 07.01.2008, 15:39
by Imy
I post a piece of script to test yourself how cycle commands could be. This is about only constellations. Pay attention, it seems (i don't know why :roll: ) that keypresses callback function doesn't allow to continue to use normal keymap...

Code: Select all

CommandCycleIndexConst=0
-- Callback for keypresses (name is hardcoded in celestia)
function celestia_keyboard_callback(str)


--About constellations
   if str == "\047" then
   
      CommandCycleIndexConst=CommandCycleIndexConst+1
   
   
      if CommandCycleIndexConst>4 then
      CommandCycleIndexConst=1
   end
 
      if CommandCycleIndexConst==1 then
         celestia:show("constellations")
         celestia:hidelabel("constellations")
      elseif CommandCycleIndexConst==2 then
      celestia:show("constellations")
         celestia:showlabel("constellations")
      elseif CommandCycleIndexConst==3 then
      celestia:hide("constellations")
         celestia:showlabel("constellations")
      elseif CommandCycleIndexConst==4 then
      celestia:hide("constellations")
         celestia:hidelabel("constellations")
      end
  return true
end

-- enable keyboard-callback:
celestia:requestkeyboard(true)
celestia:flash("Command cycle example start")

-- and do nothing...
while true do
  wait(0)
end



I've tried to extend the principle for showing names and orbits of different objects as planets (p button), moons (m), asteroids(a), spacecraft(s). I'm quite a beginner in celestia scripting and this next piece of script doesn't run totally (specially for orbits :x ) :

Code: Select all

CommandCycleIndexConst=0
CommandCycleIndexPlanet=0
CommandCycleIndexAster=0
CommandCycleIndexMoon=0
CommandCycleIndexSpc=0
-- Callback for keypresses (name is hardcoded in celestia)
function celestia_keyboard_callback(str)


--About constellations
   if str == "\047" then
   
      CommandCycleIndexConst=CommandCycleIndexConst+1
   
   
      if CommandCycleIndexConst>4 then
      CommandCycleIndexConst=1
   end
 
      if CommandCycleIndexConst==1 then
         celestia:show("constellations")
         celestia:hidelabel("constellations")
      elseif CommandCycleIndexConst==2 then
      celestia:show("constellations")
         celestia:showlabel("constellations")
      elseif CommandCycleIndexConst==3 then
      celestia:hide("constellations")
         celestia:showlabel("constellations")
      elseif CommandCycleIndexConst==4 then
      celestia:hide("constellations")
         celestia:hidelabel("constellations")
      end

--About planets   
   elseif str == "\112" then
   
      CommandCycleIndexPlanet=CommandCycleIndexPlanet+1
   
   
      if CommandCycleIndexPlanet>4 then
      CommandCycleIndexPlanet=1
   end
 
      if CommandCycleIndexPlanet==1 then
         celestia:setorbitflags {planet=true}
         celestia:hidelabel("planets")
      elseif CommandCycleIndexPlanet==2 then
      celestia:setorbitflags {planet=true}
         celestia:showlabel("planets")
      elseif CommandCycleIndexPlanet==3 then
      celestia:setorbitflags {planet=false}
         celestia:showlabel("planets")
      elseif CommandCycleIndexPlanet==4 then
      celestia:setorbitflags {planet=false}
         celestia:hidelabel("planets")
      end
   
--About asteroids   
   elseif str == "\97" then
   
      CommandCycleIndexAster=CommandCycleIndexAster+1
   
   
      if CommandCycleIndexAster>4 then
      CommandCycleIndexAster=1
   end
 
      if CommandCycleIndexAster==1 then
         celestia:setorbitflags {Asteroids=true}
         celestia:hidelabel("asteroids")
      elseif CommandCycleIndexAster==2 then
      celestia:setorbitflags {Asteroid=true}
         celestia:showlabel("asteroids")
      elseif CommandCycleIndexAster==3 then
      celestia:setorbitflags {Asteroid=false}
         celestia:showlabel("asteroids")
      elseif CommandCycleIndexAster==4 then
      celestia:setorbitflags {Asteroid=false}
         celestia:hidelabel("asteroids")
      end

--About moons
elseif str == "\109" then
   
      CommandCycleIndexMoon=CommandCycleIndexMoon+1
   
   
      if CommandCycleIndexMoon>4 then
      CommandCycleIndexMoon=1
   end
 
      if CommandCycleIndexMoon==1 then
         celestia:setorbitflags {Moon=true}
         celestia:hidelabel("Moons")
      elseif CommandCycleIndexMoon==2 then
      celestia:setorbitflags {Moon=true}
         celestia:showlabel("Moons")
      elseif CommandCycleIndexMoon==3 then
      celestia:setorbitflags {Moon=false}
         celestia:showlabel("Moons")
      elseif CommandCycleIndexMoon==4 then
      celestia:setorbitflags {Moon=false}
         celestia:hidelabel("Moons")
      end


--About spacecrafts
elseif str == "\115" then
   
      CommandCycleIndexSpc=CommandCycleIndexSpc+1
   
   
      if CommandCycleIndexSpc>4 then
      CommandCycleIndexSpc=1
   end
 
      if CommandCycleIndexSpc==1 then
         celestia:setorbitflags {Spacecraft=true}
         celestia:hidelabel("spacecrafts")
      elseif CommandCycleIndexSpc==2 then
      celestia:setorbitflags {Spacecraft=true}
         celestia:showlabel("spacecrafts")
      elseif CommandCycleIndexSpc==3 then
      celestia:setorbitflags {Spacecraft=false}
         celestia:showlabel("spacecrafts")
      elseif CommandCycleIndexSpc==4 then
      celestia:setorbitflags {Spacecraft=false}
         celestia:hidelabel("spacecrafts")
      end

   
 
 
  end 
  return true
end

-- enable keyboard-callback:
celestia:requestkeyboard(true)
celestia:flash("Command cycle example start")

-- and do nothing...
while true do
  wait(0)
end

Posted: 10.01.2008, 08:58
by Imy
I don't why setorbitflags don't show orbits altough I turn the value on true?

Posted: 10.01.2008, 11:52
by Vincent
Imy wrote:I don't why setorbitflags don't show orbits altough I turn the value on true?

Have you also set orbits renderflag to true ?

Code: Select all

celestia:setrenderflags { orbits = true }

Posted: 11.01.2008, 10:33
by Imy
Exact : if you add this line in keypresses callback orbits appear for asteroids but problems still exist for planets... I have no more moon or spacecraft labels anymore!
What does mean exactly setrenderflags and setorbitflag? What is the difference please?

Posted: 11.01.2008, 11:44
by Vincent
Imy wrote:What does mean exactly setrenderflags and setorbitflag? What is the difference please?

You may want to have a look at Harald Schmidt celx page:
http://celestia.h-schmidt.net/celx-summary-latest.html

Posted: 11.01.2008, 13:36
by Imy
Thanks for the link. Setrenderflag allows orbits and setorbitflag selects objects whose orbit is wanted to be shown, doesn't it?

But this doesn't explain why i can show asteroid orbits im my last script and planet orbits are still hidden...

Posted: 11.01.2008, 16:41
by Vincent
Imy wrote:Thanks for the link. Setrenderflag allows orbits and setorbitflag selects objects whose orbit is wanted to be shown, doesn't it?
Yep, that's it.

Imy wrote:But this doesn't explain why i can show asteroid orbits im my last script and planet orbits are still hidden...

Object class names in get/setorbitlflags methods must be capitalized.
So the issue should be fixed by replacing (in the 'Planets' block):

Code: Select all

if CommandCycleIndexPlanet==1 then
         celestia:setorbitflags {planet=true}

with

Code: Select all

if CommandCycleIndexPlanet==1 then
         celestia:setorbitflags {Planet=true}

Posted: 14.01.2008, 08:40
by Imy
Hummm... I capitalized words in setorbitflags function and I don't in showlabel and hidelabel function. It runs better surely. However, I still have troubles!
When I use setorbitflags for planet, it seems that selected orbit is still visible although I've decided to hide them...
In Spacecraft Hidelabel and Showlabel function I have had to write in singular spacecraft word although for the others (like planet or moon) plural form run correctly.
I've still problems with spacecraft. All is hidden at the beginning of the script except spacecraft labels, why?

I post a second version of the script where all seems to be good except for spacecraft. I initialise in hidding objects at the beginning:

Code: Select all


celestia:setrenderflags {orbits =false, labels=false, constellations=false}

CommandCycleIndexConst=0
CommandCycleIndexPlanet=0
CommandCycleIndexAster=0
CommandCycleIndexMoon=0
CommandCycleIndexSpc=0
-- Callback for keypresses (name is hardcoded in celestia)
function celestia_keyboard_callback(str)

celestia:setrenderflags {orbits =true, labels=true}

--About constellations
   if str == "\047" then
   
      CommandCycleIndexConst=CommandCycleIndexConst+1
   
   
      if CommandCycleIndexConst>4 then
      CommandCycleIndexConst=1
   end
 
      if CommandCycleIndexConst==1 then
         celestia:show("constellations")
         celestia:hidelabel("constellations")
      elseif CommandCycleIndexConst==2 then
      celestia:show("constellations")
         celestia:showlabel("constellations")
      elseif CommandCycleIndexConst==3 then
      celestia:hide("constellations")
         celestia:showlabel("constellations")
      elseif CommandCycleIndexConst==4 then
      celestia:hide("constellations")
         celestia:hidelabel("constellations")
      end

--About planets   
   elseif str == "\112" then
   
      CommandCycleIndexPlanet=CommandCycleIndexPlanet+1
   
   
      if CommandCycleIndexPlanet>4 then
      CommandCycleIndexPlanet=1
   end
 
      if CommandCycleIndexPlanet==1 then
         celestia:setorbitflags {Planet=true}
         celestia:hidelabel("planets")
      elseif CommandCycleIndexPlanet==2 then
      celestia:setorbitflags {Planet=true}
         celestia:showlabel("planets")
      elseif CommandCycleIndexPlanet==3 then
      celestia:setorbitflags {Planet=false}
         celestia:showlabel("planets")
      elseif CommandCycleIndexPlanet==4 then
      celestia:setorbitflags {Planet=false}
         celestia:hidelabel("planets")
      end
   
--About asteroids   
   elseif str == "\97" then
   
      CommandCycleIndexAster=CommandCycleIndexAster+1
   
   
      if CommandCycleIndexAster>4 then
      CommandCycleIndexAster=1
   end
 
      if CommandCycleIndexAster==1 then
         celestia:setorbitflags {Asteroid=true}
         celestia:hidelabel("asteroids")
      elseif CommandCycleIndexAster==2 then
      celestia:setorbitflags {Asteroid=true}
         celestia:showlabel("asteroids")
      elseif CommandCycleIndexAster==3 then
      celestia:setorbitflags {Asteroid=false}
         celestia:showlabel("asteroids")
      elseif CommandCycleIndexAster==4 then
      celestia:setorbitflags {Asteroid=false}
         celestia:hidelabel("asteroids")
      end

--About moons
elseif str == "\109" then
   
      CommandCycleIndexMoon=CommandCycleIndexMoon+1
   
   
      if CommandCycleIndexMoon>4 then
      CommandCycleIndexMoon=1
   end
 
      if CommandCycleIndexMoon==1 then
         celestia:setorbitflags {Moon=true}
         celestia:hidelabel("moons")
      elseif CommandCycleIndexMoon==2 then
      celestia:setorbitflags {Moon=true}
         celestia:showlabel("moons")
      elseif CommandCycleIndexMoon==3 then
      celestia:setorbitflags {Moon=false}
         celestia:showlabel("moons")
      elseif CommandCycleIndexMoon==4 then
      celestia:setorbitflags {Moon=false}
         celestia:hidelabel("moons")
      end


--About spacecrafts
elseif str == "\115" then
   
      CommandCycleIndexSpc=CommandCycleIndexSpc+1
   
   
      if CommandCycleIndexSpc>4 then
      CommandCycleIndexSpc=1
   end
 
      if CommandCycleIndexSpc==1 then
         celestia:setorbitflags {Spacecraft=true}
         celestia:hidelabel("spacecraft")
      elseif CommandCycleIndexSpc==2 then
      celestia:setorbitflags {Spacecraft=true}
         celestia:showlabel("spacecraft")
      elseif CommandCycleIndexSpc==3 then
      celestia:setorbitflags {Spacecraft=false}
         celestia:showlabel("spacecraft")
      elseif CommandCycleIndexSpc==4 then
      celestia:setorbitflags {Spacecraft=false}
         celestia:hidelabel("spacecraft")
      end

   
 
 
  end 
  return true
end

-- enable keyboard-callback:
celestia:requestkeyboard(true)
celestia:flash("Command cycle example start")

-- and do nothing...
while true do
  wait(0)
end
[/code]

Posted: 14.01.2008, 11:57
by Vincent
Imy wrote:When I use setorbitflags for planet, it seems that selected orbit is still visible although I've decided to hide them...
This is the expected behaviour. The current selection's orbit is always displayed unless you disable orbits rendeflag.

Imy wrote:In Spacecraft Hidelabel and Showlabel function I have had to write in singular spacecraft word although for the others (like planet or moon) plural form run correctly.
This is because the plural for 'spacecraft' is... 'spacecraft'.

Imy wrote:I've still problems with spacecraft. All is hidden at the beginning of the script except spacecraft labels, why?

I think that this is simply because you have spacecraft labels enabled before running the script. Your script works fine for me.

Posted: 15.01.2008, 10:32
by Imy
Thanks. Finally Shall I change all setorbitflags by setrenderflag about orbit? Is not easier?

This is because the plural for 'spacecraft' is... 'spacecraft'.
I didn't search in this way why spacecraft option didn't run as they would... :?

Imy wrote:
I've still problems with spacecraft. All is hidden at the beginning of the script except spacecraft labels, why?

I think that this is simply because you have spacecraft labels enabled before running the script. Your script works fine for me.


But I ask to hide all labels at the beginning of the script. Spacecraft labels are included also, aren't they?

I'm beginning to wonder if it would not be interesting to use a special shift button too. When you've selected Earth, if you play with P button in my script, well all orbits disapear ; but if you press SHIFT + P, only Earth orbit would be hidden. This could be useful to select orbits, to show for example, only mercury and earth orbit to compare them... or to show only spacecraft orbiting around earth...
But Celestia can do that? First how to say SHIFT+P? And Above all, can we show orbits for one object and not for a class of object?

Posted: 15.01.2008, 12:18
by Vincent
Imy wrote:But I ask to hide all labels at the beginning of the script. Spacecraft labels are included also, aren't they?
'labels' is not a valid renderflag. You must disable all labels using celestia:setlabelflags.
You can also write your own function that enable/disable all labels:

Code: Select all

setLabelRenderflag = function (b)
  t = celestia:getlabelflags()
  for class, flag in pairs(t) do
    t[class] = b
    celestia:setlabelflags(t)
  end
end

Then, just call:

Code: Select all

setLabelRenderflag(true)
or

Code: Select all

setLabelRenderflag(false)


Imy wrote:First how to say SHIFT+P?

Code: Select all

if str == "P"


Imy wrote:And Above all, can we show orbits for one object and not for a class of object?

No, this is not possible, yet.

Posted: 16.01.2008, 12:38
by Imy
'labels' is not a valid renderflag
What does that mean exactly? Is a bugged function?

Imy wrote:
And Above all, can we show orbits for one object and not for a class of object?

No, this is not possible, yet.


So my selective option will be for a next time ...

Why keypress callback function doesn't continue to use the basic keymap? When I execute my script, enter or g buttons don't run although I haven't used them in the function.

Posted: 23.01.2008, 14:21
by Vincent
Imy wrote:
'labels' is not a valid renderflag
What does that mean exactly? Is a bugged function?
It's not a bug. The labels renderflag doesn't exist. Each label must be turned on/off separately with the 'setlabelflags' method.

Imy wrote:Why keypress callback function doesn't continue to use the basic keymap? When I execute my script, enter or g buttons don't run although I haven't used them in the function.

Just tell your celestia_keyboard_callback function to return false instead of true.

One small suggestion: you should add comments to precise to which char corresponds each ASCII code you're using in your script. Not everybody knows that '\047' corresponds to '/', '\112' to 'p', etc.

Posted: 25.01.2008, 09:55
by Imy
if CommandCycleIndexMoon==1 then
celestia:setorbitflags {Moon=true}
celestia:hidelabel("Moons")
elseif CommandCycleIndexMoon==2 then
celestia:setorbitflags {Moon=true}
celestia:showlabel("Moons")
elseif CommandCycleIndexMoon==3 then
celestia:setorbitflags {Moon=false}
celestia:showlabel("Moons")
elseif CommandCycleIndexMoon==4 then
celestia:setorbitflags {Moon=false}
celestia:hidelabel("Moons")
end


I was improving code in including a more general function and I found that my variable CommandCycleIndexMoon (and probably others) hasn't done what I ordered : when the variable is 1 then, 2 is done, when it is 2 this is 1, 3 for 4 and 4 for 3:evil: :roll: !! What's the problem? From me or a subtility from celestia scripting?

Posted: 25.01.2008, 11:21
by selden
You need to replace the braces {} by parentheses ().

Lua uses parentheses () to delimit function arguments.

Braces {} delimit tables.

Posted: 25.01.2008, 17:45
by Vincent
The problem is not related to the use of braces; braces must be used here since orbitflags are defined as a table; as for parentheses, they would be superfluous here.

The problem is that since we told the callback function to return false, the 'M' key is still toggling the Moons labels. So, you can solve this issue by adding a return true at the end of the 'm' char test (and also at the end of all char tests) to block the default 'M' key function:

Code: Select all

--About moons
elseif str == "\109" then

    CommandCycleIndexMoon=CommandCycleIndexMoon+1

    if CommandCycleIndexMoon>4 then
      CommandCycleIndexMoon=1
    end

    if CommandCycleIndexMoon==1 then
      celestia:setorbitflags {Moon=true}
      celestia:hidelabel("moons")
    elseif CommandCycleIndexMoon==2 then
      celestia:setorbitflags {Moon=true}
      celestia:showlabel("moons")
    elseif CommandCycleIndexMoon==3 then
      celestia:setorbitflags {Moon=false}
      celestia:showlabel("moons")
    elseif CommandCycleIndexMoon==4 then
       celestia:setorbitflags {Moon=false}
       celestia:hidelabel("moons")
    end

    return true

--About spacecrafts
elseif str == "\115" then

Posted: 26.01.2008, 11:13
by Imy
I've still problems please:? :

-How to desactivate keypress callback when enter panel is shown (where you tape your destination)

-What about setlabelflags? I've changed hidelabel and showlabel functions with setlabelflags as suggested so that I can use table instead of strings in its parameters. But when I've written celestia:setlabelflags {Planet=true}, well nothing, no planet labels although these ones can be shown with classic showlabel...

-I'm often coding with VB language: in this you have lcase/ucase function, i suppose these kind of functions exists also in Lua. These functions change case of a string : you have "HeLLo", and then this string with lcase become "hello". What is the equivalent in lua language please?