Chat window cache flush

I have two buttons in the The Burning Blue module that start processes that take very long time - on my laptop about 20 seconds. They save the player 5 to 15 minutes, so that’s OK, but when the button is pressed, nothing happens for along time, even though my processes write a lot to the chat window. It is apparently cached, and only written to the chat window at end.

Is it possible to flush the cache at intervals so that the players can see that the module isn’t dead, but is still working?

Just to be able to write “Hang on, this will take some time” would be helpful.

I saw that the sleep function should update the screen, and I tried sleeping for 0-10 milliseconds, but the chat cache was not flushed.

Unfortunately, not. One option for immediate output is Alert(), but as you’ve discovered, that doesn’t flush chat or make anything else happen, it just displays a popup box - and processing stops until the box is dismissed.

Another way to signal ongoing processing is to generate a sound (Play Sound trait).

There is also a new Alert box with timer that remains on screen for a time which you nominate. Not sure if it would useful here but would probably be better than the standard alert. I have used the Alert (text, ms) before and it works.


That does not sound good. I might consider making my buttons bigger so that I write on them “Might take some time …”

The description of the sleep command mentions something about a “screen update”. What exactly is updated here?

Vassal V3 is implemented in Java Swing and in Swing, there is no way to force anything to refresh ‘right now’. You can only ask Swing to refresh it sometime later when it feels like it.

However, we can trick Swing into thinking it’s really important to refresh everything right now. The new Sleep() function does this, so you can use it to force the UI to be refreshed up to it’s latest state before the Sleep period starts.

So Sleep(0) should refresh all pending updates to the UI (e.g. any outstanding dynamic label or button text changes) without sleeping at all.


I think I did try that without success, but maybe I did something wrong. I’ll give it another try.

You will need to include multiple Sleep(0), after each process that writes stuff to the chat window.

Interesting to learn about what Sleep(0) does. From my own attempt to exploit this, I can see it works for the display image on a map. However, I am pretty sure that the chat window does not receive any associated output until the end of the action (ie sleep has no effect on this).

Also, I am convinced that my Sleep(0) added a delay of somewhere in the range 500ms - 1s. The actual image refresh was a card play to the map, which without the sleep would not have displayed in the same place, as the action immediately discards it.

See if Sleep(1) makes a difference. There may be an internal default somewhere that says 0 is illegal, so use a larger value.

1 Like

During my time consuming process, counters are also moved about with the Send To Location trait, so I thought that even if sleep does not refresh the chat window, it might refresh the map, but I have no success.
What is the best way of experimenting with sleep()? I tried with string expressions like in the Report trait, but that didn’t work. Then I tried to have sleep(1) as the boolean expression in a Trigger trait, but that also didn’t work.

Could there be another trait where I can put sleep(1) with possible success?

Apologies, I thought I’d come back on this after trying @Brent_Easton 's suggestion of Sleep(1)… here’s my belated update:

Sleep(1) makes no difference. I suspect in my case, the delay is largely occurring in processing the functional traits prior to get to the point at which I am triggering the Sleep().

Nonetheless, I have found a useful application for Sleep() that demonstrates that it does indeed force a screen refresh. In my case, Sleep() lets me do a screen animation for a card that is presented to the board and then automatically discarded. Without Sleep(), the card never appears on the board, it appears to go straight to its discard pile.

However, @steenkh the bad news is that as far as I can tell, the screen refresh does nothing to “flush” the chat buffer midway through a composite action. Given that Sleep() doesn’t work, I don’t think there is any alternative that will. I’d love to know if its even possible with custom code - from my little knowledge & experimentation with Vassal internals, I suspect not.

I did understood that the chat window would not refresh, but as I said, I also moved counters around, and still the sleep() command does not let me see the moves. They just all move to their right place when the process has ended.

So how do you implement the sleep() command?

Just after the action has reached the interim state that I want to display, I’ve put a Trigger that includes Sleep(1) in the expression.

In the simplest case the “Trigger when properties match” field might contain {Sleep(1) > 0}
This condition assumes that the Trigger is not intended to perform any Key Commands - Sleep(1) evaluates to null. However, the Sleep(1) would execute and this is all that is needed to force the refresh.

The important thing is to make sure you are doing the Sleep after the action that you want to display. If the action is very near to the end - in execution time - then you might want to increase the Sleep() time until the pause is long enough for you to notice the animation.

This example, specific to a module, will sleep/refresh on 3 different Key Commands, but only if some other criteria are met. If the preceding criteria fail, the Sleep(1) is triggered:

Nope, doesn’t work for me!

I changed my trigger command from {sleep(1)} to {sleep(1)>0} but there is no change. you do not see the counters move until the end. I use Send To Location to move the counters. What do you use to do the card action?

I am using Send to Location at the first step and Return to Deck at the second.

The Sleep is put in between the two.

{sleep(1)} I think would have given you a data error but still have performed the sleep / refresh.

Have you got the sleep after your first counter movement?

How about if you increase it to sleep(1000), does that make a difference?

Problem solved :smiley:

I had made two errors: Having been on holiday for three weeks, I had forgotten about the basic routine of refreshing predefined setups. When this was done, I could see an error message telling med that I had misspelled Sleep() as sleep().

With the correct Sleep(), The cache is refreshed as it should, including the chat window!

Now everything I wanted is accomplished. I am sure it helped that I used Trigger to, eh, trigger the Sleep() command, because it certainly didn’t work in a string expression.

1 Like

Oh, and Sleep(0) works fine :+1:

1 Like

I’ll have to look at that again then, I was convinced that chat only appeared at the end of my actions, even with a Sleep(1000) in the middle.