findWindow and class weirdness

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
Forum rules
This is a sub-forum for things specific to MicroMacro.

This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Post Reply
Message
Author
vIndie
Posts: 9
Joined: Thu Mar 29, 2012 12:35 am

findWindow and class weirdness

#1 Post by vIndie » Sun Apr 01, 2012 2:54 pm

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

BillDoorNZ
Posts: 446
Joined: Wed Aug 03, 2011 7:37 pm

Re: findWindow and class weirdness

#2 Post by BillDoorNZ » Sun Apr 01, 2012 3:47 pm

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);

vIndie
Posts: 9
Joined: Thu Mar 29, 2012 12:35 am

Re: findWindow and class weirdness

#3 Post by vIndie » Sun Apr 01, 2012 3:52 pm

danke! that was it. I think it is a sign I need to go to bed tonight

BillDoorNZ
Posts: 446
Joined: Wed Aug 03, 2011 7:37 pm

Re: findWindow and class weirdness

#4 Post by BillDoorNZ » Sun Apr 01, 2012 4:19 pm

lol...I would imagine so - have written a lot of crap code late at night :)

at least its morning here :) 9am :)

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests