Quote:
Originally Posted by Olenn
I think there is a basic key understanding of Lua that I am missing. Here is the error;
And thanks for the help once again DU.
|
First of all, I think you're not quite understanding classes in Lua.
SetupWindow and SatchelWindow are classes, and as such do nothing unless an instance is made of them. eg:
Code:
--in Main.lua
setup=SetupWindow();
satchel = SatchelWindow();
Now, you can do whatever you want to each instance of the class in Main.lua, but you can't do anything to the SetupWindow class in SatchelWindow, nor vice versa. Classes are essentially blueprints, containing code that describes their appearance and behavior. Just like you can't walk into a blueprint of a house and sit down and watch TV, you can't do anything with a Class, unless you actually build yourself a copy of it by declaring an instance.
Ever see one of those suburban neighborhoods where it's obvious that all the houses were built off the same blueprints, and the only thing really different about them is the changes the owners made to them (i.e. paint color)? If that were a program, each house would be an instance of the same class. eg:
Code:
myhouse = House();
yourhouse = House();
bobshouse = House();
crazyguyshouse = House();
...
Now from there, you could change any instance - using any function/property available to you in that class, or any class House inherits. eg:
Code:
myhouse:Paint(red);
yourhouse:Paint(blue);
You could even add a pool if you wanted
Now let's say you wanted to oh...I dunno, put in a pool light in your pool. Now that could be done quite easily here, by doing something like:
However, if you tried to do this in the House class itself...
Code:
House = class( Entertainment.Outside );
function House:Constructor()
Entertainment.Outside.Constructor( self );
function self:Paint(color)
--code here paints the house at the specified color
end
--wait, what?
if (Pool.isAboveGround() == true)then
self.Paint(blue)
else
self.Paint(yellow)
end
end
Well, that would get a big error - a House has nothing to do with a Pool, and even if it knew exactly what a Pool was (i.e. by importing the class), it wouldn't know which pool to check to see if it was AboveGround or not.
On the other hand, doing something like this, in the same class/file as you created instances of houses
would work
Code:
if (myPool:isAboveGround()==true)then
myHouse:Paint(blue)
else
myHouse:Paint(yellow)
end
Now, if you somehow really needed to make sure every house was painted blue or yellow based on whether the pool was above ground or not, then..you could just create an instance within House(), and that way every house would come with a pool eg:
Code:
House = class( Entertainment.Outside );
function House:Constructor()
Entertainment.Outside.Constructor( self );
function self:Paint(color)
--code here paints the house at the specified color
end
--A pool for every house!
self.zePool=Pool();
if (self.zePool.isAboveGround() == true)then
self.Paint(blue)
else
self.Paint(yellow)
end
end
See if you notice, we're still not checking for the class itself (i.e. Pool) but rather an instance we created inside that class. But unlike before, we can now decide how to make a House based on what the properties of its pool are. It's important to note that either the House class, or the Pool class would need to have a constructor that sets whether the pool is above ground or not, otherwise the answer will always be what the default value of that property is.
Now that we have a declaration of Pool inside House, we can still access it from outside of House as well eg:
Code:
myHouse.zePool:AddLight();
While this doesn't specifically fix your code, I hope it was informative enough for you to get a better understanding how classes work, and how to use them - not only inside Lua, but in other languages as well. If you can now see where your problem is, then I've accomplished my goal. If you have any questions, please feel free to ask!