globals startKey and stopKey - accesor and mutator functions

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
zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

globals startKey and stopKey - accesor and mutator functions

#1 Post by zer0 » Tue Jan 06, 2009 2:01 am

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

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: globals startKey and stopKey - accesor and mutator functions

#2 Post by Administrator » Tue Jan 06, 2009 7:06 am

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.

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: globals startKey and stopKey - accesor and mutator functions

#3 Post by zer0 » Tue Jan 06, 2009 9:54 pm

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

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: globals startKey and stopKey - accesor and mutator functions

#4 Post by Administrator » Tue Jan 06, 2009 10:22 pm

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.

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: globals startKey and stopKey - accesor and mutator functions

#5 Post by zer0 » Tue Jan 06, 2009 11:35 pm

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests