[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: A question of scoping (I think)
- From: Ryan Leigh <ryan@...>
- Date: Mon, 12 Apr 2004 19:00:03 -0700
Hello everyone,
So I have a question. I just bet it has been answered somewhere, but I
don't have a succinct way to phrase it for a search. I'm creating a
scripting engine for a game and in this script I define an object
(which is of course really just a table) as well as some member values
a la:
myObj = {}
myObj.xPos = 10;
myObj.someVal = 100;
Now, I would like it if I could write a function:
function myObj.update()
--some code
someVal = xPos * 10
--remaining code
end
The way I see it right now is I have to write the function like this:
function myObj.update()
--some code
myObj.someVal = myObj.xPos * 10
--remaining code
end
Which is a pain and error prone (because I'm a lousy typist). So, to
finally get to the point, is there something I can do where when I
call a function that is in some object and I reference a variable, is
there someway I can force it to look in the object's table first
before going global? I guess this is similar to having a C++ class and
I want to scope to member variables in a member function. Or am I just
not envisioning all the possibilities of Lua and there exists a much
better way of doing things.
Whew, I hope that made sense.
Thanks for any help,
Ryan Leigh