Page 1 of 1
globals startKey and stopKey - accesor and mutator functions
Posted: Tue Jan 06, 2009 2:01 am
by zer0
Not sure if u wan't to do this Elv, I guess it's entirely up to you ^_^.
but I've noticed that I have needed to change the start and stop key, and by doing so you have to open lib.lua and look for the variables.
It would be handy just to have accesor & mutator functions instead so it's more obvious, anyway here are the functions:
Code: Select all
function setStartKey(val)
startKey = val
end
function getStartKey()
return startKey
end
function setStopKey(val)
stopKey = val
end
function getStopKey()
return stopKey
end
Re: globals startKey and stopKey - accesor and mutator functions
Posted: Tue Jan 06, 2009 7:06 am
by Administrator
Well, I
could do that. Or you could just modify the variable.
Code: Select all
startKey = key.VK_F9;
stopKey = key.VK_F10;
printf("The start key is %s\n", getKeyName(startKey));
printf("The stop key is %s\n", getKeyName(stopKey));
It's ok. I often overlook the simplest solution, too.
Re: globals startKey and stopKey - accesor and mutator functions
Posted: Tue Jan 06, 2009 9:54 pm
by zer0
No, I know it's a global and you can just modify the variable.
However, if your newish to programming, the only way you'll know how to change it is by looking at the implementation of "lib.lua" and finding the variable name. Actually it would be a pretty good idea to make the start/stop variables local, and not global at all so the programmer doesn't accidentilly overwrite it's value.
A better design would be to make it local, and have mutator/accessor functions so it's encapsulated. And if you have the functions listed in the manual it would make it easier to access/change without having to look through the library code.
You sometimes underestimate my knowledge in programming.

Re: globals startKey and stopKey - accesor and mutator functions
Posted: Tue Jan 06, 2009 10:22 pm
by Administrator
I guess it couldn't really hurt any. Other than breaking compatibility, anyways, but that's been done countless times before for the better. I'll have to take a close look at how Lua handles local variables that are not inside any functions or other containers to make sure it won't cause any problems. lib.lua needs to be rewritten, anyways.
Re: globals startKey and stopKey - accesor and mutator functions
Posted: Tue Jan 06, 2009 11:35 pm
by zer0
I don't think you'd be able to encapsulate it using Lua as all registered variable outside of local are registered as globals.
I guess you would have to hard code it and make the variables private in C++.
And one more thing, is it possible it's made to work with one key to start/stop. Just like a toggle on/off button would. I tried to do it just by setting startKey and stopKey the same values but it didn't work.