Page 1 of 1

findWindow and class weirdness

Posted: Sun Apr 01, 2012 2:54 pm
by vIndie
I was making a class to wrap the window related functions:

Code: Select all

CWindow = class(
	function(self, windowTitle)
		self.win = nil;
		print(self);
		print(windowTitle);
		self.title = windowTitle;
		print(self.title);
	end
);

function CWindow:getWin()
	print(self);
	print(self.win);
    print(self.title);
	if(self.win == nil) then
  		self.win = findWindow(self.title);
	end
	
	if (self.win == 0) then
		cprintf_ex("|red|ERROR:|white| Unable to find the |yellow|%s|white| window.\n", self.title);
		cprintf_ex("|white|Launch the game and press |yellow|%s|white| restart the macro.\n", getKeyName(getStartKey()));
		cprintf_ex("|red|Macro paused.\n");
		stopPE();
		-- getWin();
	end
	
	return self.win;
end

function CWindow:showWindow(state)
	print("showWindow");
	showWindow(CWindow:getWin(), state);
end
Then I call like this:

Code: Select all

	window2 = CWindow("SomeProgram");
	print(window2);
	window2:showWindow(sw.show);
And I get an error:
table: 009A7F80
SomeProgram
SomeProgram
table: 009A7F80
showWindow
table: 02395AB8 <--
nil
nil
9:45pm - .../micromacro/scripts/window.lua:16: bad argument #1 to 'findWindow' (string expected, got nil)
For some reason, when I call window:showWindow() I'm getting a new instance of CWindow that is empty, see "<--" above

Re: findWindow and class weirdness

Posted: Sun Apr 01, 2012 3:47 pm
by BillDoorNZ

Code: Select all

function CWindow:showWindow(state)
   print("showWindow");
   showWindow(CWindow:getWin(), state);
end
The second to last line creates a new version. Should be:

Code: Select all

  showWindow(self:getWin(), state);

Re: findWindow and class weirdness

Posted: Sun Apr 01, 2012 3:52 pm
by vIndie
danke! that was it. I think it is a sign I need to go to bed tonight

Re: findWindow and class weirdness

Posted: Sun Apr 01, 2012 4:19 pm
by BillDoorNZ
lol...I would imagine so - have written a lot of crap code late at night :)

at least its morning here :) 9am :)