I use something similar. These 3 small functions are in most windows we have. Each has comments to help explain why they are used.
// separate from the toggle function, this can be used to make sure it is open
public function Start()
var win = getInventoryWindowClass() // get our new window
if win != None
destroynode(win) // if its made, remove old to keep from duplicates
.
win = CreateNodeFromPrototype( "InventoryWindow" ) // make it
win.build = true
.
// can be used with key press to open and close
public function toggleInventoryWindow()
var win = getInventoryWindowClass()
if win == None
Start() // build it
else
destroynode(win) // remove it
.
.
// this might be used in many areas, defined in one place
// by having its own class (instead of GUIControl), it can support variables (which can hold temp values)
function getInventoryWindowClass() as NodeRef of Class InventoryWindow
return FindGuiControlByName(None, "game.InventoryWindow")
.