PDA

View Full Version : [Programming] Limit windowlist entries?



pr6i6e6st
November 6th, 2019, 19:47
hey guys! so i wanted to add careers to my Alien RPG ruleset, and i'm having an issue. I figured i could use a windowlist and just make it delete the old entries when a new one is dropped in, but i'm struggling.

i've tried in the script of the windowlist:



function onListChanged()
Total = getWindowCount();
if Total > 1 then
for _,w in pairs(getWindows()) do
w.destroy(self);
end
end
end


and if i do that as just "destroy()" or "destroy(w)" instead of "w.destroy()" it crashes fantasy grounds.

i can't find a way to simply limit it. what am i missing? what else could i do to have a single "career" record on a character sheet?

Trenloe
November 6th, 2019, 21:31
and if i do that as just "destroy()" or "destroy(w)" instead of "w.destroy()" it crashes fantasy grounds.
Calling destroy without a reference object means that the API function will be executed on the currently in scope object/control - which I'm guessing is the windowlist (https://www.fantasygrounds.com/refdoc/windowlist.xcp)control.

As you would then be destroying the control that you were running code against, this causes an exception.

Calling w.destroy means you're destroying a specific control within the windowlist.

Info on <control>.destroy here: https://www.fantasygrounds.com/refdoc/windowcontrol.xcp#destroy

The best practice for doing anything like this is to operate against the underlying database records - which the windowlist is anchored on. When a new record is added, remove the old record.

I'm not familiar with your ruleset, so not sure why you're using a windowlist to display one record. Most other rulesets just display the title for something like career with a link to open the database record for more information. A drag/drop of a new career record would be coded to replace the previous name and record link.

Moon Wizard
November 6th, 2019, 23:58
I would either manage completely through the database (and thus not mess with any windowlist APIs for addition/creation);
OR manage all window creation and deletion through the APIs and not tie it to the database.

If you want to close all windows in a sourceless windowlist (i.e. not connected to database), use windowlist.closeAll()
If you want to create a window in a sourceless windowlist, use windowlist.createWindow(record) or windowlist.createWindowWithClass(class, record)
If you want to close a single window, use windowinstance.close()

Regards,
JPG