Page 1 of 1

text display problems (was: Unexpected behaviour in Scripts)

Posted: 26.10.2005, 18:32
by Malenfant
Does anyone else find that if they run scripts a lot then things sometimes randomly don't turn out the way you want, but then if you close Celestia down and reopen it again and run the same script it works perfectly?

Also, I'm finding that if I have several flash statements, they don't all show if I end one of them with a duration. But it does work if you separate the duration into a wait command. e.g.

Code: Select all

planet = celestia:getselection()
type = planet:type()
celestia:flash("target is a "..type)
wait(3)
celestia:flash("test")


Shows both the target type for 3 seconds and prints "test".

But:

Code: Select all

planet = celestia:getselection()
type = planet:type()
celestia:flash("target is a "..type, 3)
celestia:flash("test")


Just shows "test". If however I remove the celestia:flash("test") line, it shows the target type on the screen for 3 seconds.

Am I doing something wrong here, or is this a bug in the API itself? Or should you just always use wait statements instead of putting the duration in the flash statement itself?

Posted: 26.10.2005, 20:22
by maxim
Always use explicit 'wait()' commands.

The function itself doesn't wait. It prints the second text only some milliseconds after the first, so you don't see the first one. IMHO this is not a buggy behavior but a kind of feature. You can use it do do whatever you like during the text is displayed. For example you can start some movements meanwhile, so you can generate some quite dynamic impressions.

maxim

Posted: 26.10.2005, 20:30
by Malenfant
maxim wrote:Always use explicit 'wait()' commands.

The function itself doesn't wait. It prints the second text only some milliseconds after the first, so you don't see the first one. IMHO this is not a buggy behavior but a kind of feature. You can use it do do whatever you like during the text is displayed. For example you can start some movements meanwhile, so you can generate some quite dynamic impressions.

maxim

Ok, I'll just always use wait() commands then :).

Though Harald's summary definitely implies that putting the duration in the flash statement should cause it to show the text for that number of seconds - is that just wrong?:

2.1.2. celestia:flash(string:text [, number:duration])
Print text on screen, similar to print.
text: A string containing the message to be printed. The string can contain newlines "\n" to break lines, or many special characters encoded in UTF-8.
duration [optional]: Number of seconds the text is shown. Default is 5.

Posted: 26.10.2005, 20:47
by selden
It will show the text that long if you don't immediately overwrite it with something else. Without a WAIT statement, it immediately goes on to execute the subsequent code. In this case, that includes code to overwrite the first text string with a new text string.

Posted: 26.10.2005, 20:54
by Malenfant
selden wrote:It will show the text that long if you don't immediately overwrite it with something else. Without a WAIT statement, it immediately goes on to execute the subsequent code. In this case, that includes code to overwrite the first text string with a new text string.


Oh right. Still strikes me as being rather counterintuitive if you're being explicit about telling to display the first text for a specific duration though. But whatever, I'll just use wait statements instead ;).

Posted: 26.10.2005, 22:27
by cpotting
Malenfant wrote:Oh right. Still strikes me as being rather counterintuitive if you're being explicit about telling to display the first text for a specific duration though. But whatever, I'll just use wait statements instead ;).


Think of the duration as meaning "keep the text on the screen for a maximum of duration seconds".

It actually would be a bit of a hinderance if the duration meant "the text stays up for duration second - no matter what". You couldn't clear the screen of unwanted text and, if you think about it, the only way Celestia could make sure that text stayed on the screen would be stop processing any more commands until the duration was over, or keep processing but ignore any new prints or flash commands that try to overwrite the existing text. To me, that would be yucky (hey! there isn't an emoticon for yucky! That's yucky!)

Re: Unexpected behaviour in Scripts

Posted: 26.10.2005, 22:31
by cpotting
Malenfant wrote:Does anyone else find that if they run scripts a lot then things sometimes randomly don't turn out the way you want, but then if you close Celestia down and reopen it again and run the same script it works perfectly?


There could be any number of reasons for this. But I find the most common is that the script unwittingly relies on the observer being in either the "universal" or the "ecliptic" frame of reference (depending on your start-up script). Then, something you do in your script changes this (like specifying follow, or chase). After that, when you run the script again, it is starting in a different frame of reference, and doesn't seem to do exactly what it did before.

Posted: 26.10.2005, 22:39
by Malenfant
cpotting wrote:Think of the duration as meaning "keep the text on the screen for a maximum of duration seconds".

It actually would be a bit of a hinderance if the duration meant "the text stays up for duration second - no matter what". You couldn't clear the screen of unwanted text and, if you think about it, the only way Celestia could make sure that text stayed on the screen would be stop processing any more commands until the duration was over, or keep processing but ignore any new prints or flash commands that try to overwrite the existing text. To me, that would be yucky (hey! there isn't an emoticon for yucky! That's yucky!)


I noticed this actually, there doesn't seem to be a way to say "keep the text on the screen for X seconds" (ie long enough for me to read it!). If I flash the text then use wait, the wait seems to just tell it how long to wait before doing the next thing, not how long to keep the text visible for...

How would you just keep the text onscreen all the time then? Like, if you wanted a display (of position, or time, or whatever) to stay there til the script is cancelled?

EDIT: correction - there is a way to keep the text on screen for X seconds - it's to put the duration in the flash statement, which seems to be problematic in some places :(.

Posted: 26.10.2005, 23:55
by cpotting
Malenfant wrote:How would you just keep the text onscreen all the time then? Like, if you wanted a display (of position, or time, or whatever) to stay there til the script is cancelled?

EDIT: correction - there is a way to keep the text on screen for X seconds - it's to put the duration in the flash statement, which seems to be problematic in some places :(.


Both the flash() and print() methods can be used. To keep the text on the screen, just be sure to re-write the text in less than duration seconds (acutally, I make sure I re-write in (duration - 1) seconds, otherwise you may refresh while the text is fading away - resulting in a weird disco-like effect).

Another way, if a loop is inconvenient, is to put the text up for a ridiculously long amount of time. e.g.

Code: Select all

celestia:flash("Wow, what a lot of stars", 600)

It will stay up there until the next flash() or print() (or until 10 minutes passes by). If you do this, just remember to include a

Code: Select all

celestia:flash("")
at the end of the code. Otherwise, once the script stops, the user is stuck with this message on the screen for 7 or 8 minutes.

Posted: 27.10.2005, 19:24
by Malenfant
A few more questions:

1) How would I be able to keep the text up as a dynamically-updating display? e.g. for my planetary magnitudes script I want the apparent magnitude to stay onscreen and change depending on the phase angle and distance of the object you're looking at (like the numbers in the top-left corner of the default display do).

2) Currently the text is crammed at the bottom of the screen and I can't get more than four lines in before it goes off the bottom - how do I move the text to be printed elsewhere on the display?

3) Is there any way to change the font and size of the text that is displayed by a script? Or is it always in that big blocky white text?

Posted: 28.10.2005, 11:00
by cpotting
Malenfant wrote:A few more questions:

1) How would I be able to keep the text up as a dynamically-updating display? e.g. for my planetary magnitudes script I want the apparent magnitude to stay onscreen and change depending on the phase angle and distance of the object you're looking at (like the numbers in the top-left corner of the default display do).
Again, you could either ensure that you are inside a loop that performs the print() or flash() regularly. Each call to print() or flash() erases the previously displayed text. The nice thing is that they are so fast that you could just do the same print() or flash() over and over and you would'nt see any flickering.

Code: Select all

while true do
celestia:flash("all I can see are spots and balls...", .5)
wait(.1)
end


Malenfant wrote:2) Currently the text is crammed at the bottom of the screen and I can't get more than four lines in before it goes off the bottom - how do I move the text to be printed elsewhere on the display?
Ahh, for that you need the print() command. It is a little tricky to ge the hang of this one. The Guide has some good examples (IMHO :wink: )

Malenfant wrote:3) Is there any way to change the font and size of the text that is displayed by a script? Or is it always in that big blocky white text?

I've never played with it, but I understand that you can change the fonts. look at the Font, LabelFont and TitleFont entries in the celestia.cfg file.

Posted: 01.11.2005, 16:28
by Malenfant
cpotting wrote:Again, you could either ensure that you are inside a loop that performs the print() or flash() regularly. Each call to print() or flash() erases the previously displayed text. The nice thing is that they are so fast that you could just do the same print() or flash() over and over and you would'nt see any flickering.

Code: Select all

while true do
celestia:flash("all I can see are spots and balls...", .5)
wait(.1)
end



I can't seem to get this to work...I've put the 'while true do' bit before all the calculations in my script, but the data displayed in the flash statement doesn't change when I speed up time (the target should be moving and so the distances etc should be changing if I do this).

The flash statement does stay on screen, it's just that the data isn't updated.

Posted: 02.11.2005, 13:26
by cpotting
Malenfant wrote:I can't seem to get this to work...I've put the 'while true do' bit before all the calculations in my script, but the data displayed in the flash statement doesn't change when I speed up time (the target should be moving and so the distances etc should be changing if I do this).

The flash statement does stay on screen, it's just that the data isn't updated.


Hmmm. I would have to see the code to know what is wrong. Could you post it?

This example shows that the text does not have to be static:

Code: Select all

while true do
t = celestia:fromjulianday(celestia:gettime())
celestia:flash("The time is "..t.hour..":"..t.minute..":"..t.seconds, .5)
wait(.1)
end

Posted: 02.11.2005, 13:45
by cpotting
Malenfant wrote:I've put the 'while true do' bit before all the calculations in my script, but the data displayed in the flash statement doesn't change when I speed up time


Oh... wait a minute... I think I might know what's up. I may have confused you with the while true do.

That was only there for my example. What that does is cause Celx to repeat infinitely (read it as "as long as true means true, do the following code" - in other words, "do the following code, then do the following code, then do the following code....").

If your calculations are not inside that loop (from the while to the end is called a loop - (I'm not sure what your programming experience is, so my apologies if this sounds a little condecending))... if your calculations are not inside the loop, then nothing is changing from one iteration of the loop to the next, so you always display the same data.

Code: Select all

x=1
while x < 11 do
celestia:flash("x is " .. x, 2)
wait(2)
end

This example a) will never end, because x will always be less than 11, b) will always show the same text because x never changes from one iteration of the while...end loop to the next.

Code: Select all

x=1
while x < 11 do
celestia:flash("x is " .. x, 2)
wait(2)
x = x + 1
end

This example a) eventually ends, because x will eventually equal 11, which is not less than 11, b) show a different value for x each time the loop executes.

Does that help?