Log in

View Full Version : Why does openCharacter() trigger old charsheet windows in onWindowOpen()?



SilentRuin
July 20th, 2020, 18:33
I have a printstack() used in trying to debug weird stuff I'm seeing that is causing me some grief. I'm the host, I click the PC button to bring up my list of PC's, I Click on a PC and I get a stack that looks like this..

[C]: in function 'openWindow'
[string "campaign/scripts/charselect_host_entry.lua"]:52: in function 'openCharacter'
[string "base"]:3: in function <[string "base"]:2>

Where (for example) the onWindowOpen() I have catching charsheet stuff shows the following node...

DATABASENODE = { charsheet.id-00001 }


YES! Good stuff. All working.

I then close that node and open another PC sheet (this is all after initial startup of host) and I get...

[C]: in function 'openWindow'
[string "campaign/scripts/charselect_host_entry.lua"]:52: in function 'openCharacter'
[string "base"]:3: in function <[string "base"]:2>

with

DATABASENODE = { charsheet.id-00001 }

(above was the old closed PC sheet) and

[C]: in function 'openWindow'
[string "campaign/scripts/charselect_host_entry.lua"]:52: in function 'openCharacter'
[string "base"]:3: in function <[string "base"]:2>

with

DATABASENODE = { charsheet.id-00002 }

the new opened PC sheet.

In fact, as I open and close PC sheets they seem to be in memory and any time I trigger "openCharacter" I will get a hit on onWindowOpened() for every charsheet no longer opened.

What is going on here?

I'm not entirely sure its onWindowOpened() triggering these recalls but will try and determine that next. Just trying to figure out how stack shows this trace to openWindow on all my closed sheets.

SilentRuin
July 20th, 2020, 18:54
Really weird.

My onWindowOpened(w) is called twice in a row on the very first call with

w = charsheet.id-00001
self = charsheet.id-00001

and then

w = charsheet.id-00001
self = charsheet.id-00001

On the second call to other PC sheet in my first post above it also calls onWindowOpened(w) twice in a row with the first time having...

w = charsheet.id-00002;
self = charsheet.id-00002;

and the second time has

w = charsheet.id-00002;
self = charsheet.id-00001;

I think I need to look over what is going on before I bother the community on this one. Something I'm not understanding about when onWindowOpened(w) is triggered as it seems its being triggered more than I thought it would. I figured the only thing that could trigger it would be a call to OpenWindow but maybe that is not true.

SilentRuin
July 20th, 2020, 19:02
I figured it out - but I still don't understand it - but I guess I can "kludge it" now that I understand what is going on.

The onWindowOpened(w) is being called more than I thought it would be (maybe resizing the window triggers it?)

And somehow I'm processing the wrong thing. I'll see if I can work around what I'm doing wrong or what is happening on this more than I thought would be called function.

SilentRuin
July 20th, 2020, 19:14
Solved. I'm an idiot.

onWindowOpened(w) is called more than once. And as I'm inside a subclass windowclass when i'm doing this onWindowOpened(w) I can't just look at the self node. I have to first filter out calls I'm not interested in by doing...



local sClass = w.getClass() or "";
if sClass ~= "char_mynewstuff" then
return;
end


I have no idea why self would be an old version and not nil when one of these comes in - but I suppose I should be grateful as it showed me I was triggering code to often without guarding against the wrong class calling me (my parent or something).