ID:2226106
 
As you can see I have stat panels set to refresh every 2 seconds. BUT I also want them to INSTANTLY refresh if the player changes tabs (on-tab). But the problem I'm seeing is that this duplicates what is being displayed in the tab. For example if I have 2 apples in my inventory then when changing to that tab it will show FOUR apples (those 2 apples duplicated). How can I make sure the statpanel is clear before sending new information to it? I want to clear it. Thanks.
mob/Stat()
RefreshOpenTabs()
sleep(20)

mob/proc/OnTab() //called by statpanels.tabs.on-tab
RefreshOpenTabs()
src << "You changed tabs, so tabs have now been instantly refreshed"

mob/proc/RefreshOpenTabs()
set waitfor=0
if(statpanel("Example Tab"))
for(var/obj/o in src)
stat(o)
Unless I'm going about this all wrong and you know a better way? Thanks. I want to sleep a tab for a reasonable time while the tab is open but as soon as the player changes tabs I want it to instantly refresh to the new one (stop sleeping)
BYOND will automatically refresh a statpanel when you switch to it (when the statpanel var changes it calls Stat()).

The better question is, why are you using statpanels still?
What's a better alternative? The "Tab" control that holds panes?
Also BYOND does not appear to refresh a statpanel when I switch to it. For example this code below, if I click from one tab to another, I will have to wait up to 10 seconds for that panel to show anything, til then it will be blank.
mob/Stat()
RefreshOpenTabs()
sleep(100)
When you add sleep() to Stat() it changes the behavior, as noted in the reference.

You may want to look into things like the grid control, or even moving to HUD objects.