PDA

View Full Version : OS Plugin: Timer



MicroByte
12-17-2009, 03:55 AM
well, not a plugin, thought id leave it for VIP to wrap :eek:

just a script, but im trying to show you budding plugin makers how easy it is to add real power to AMS with out externals, every thing you need is already on the system, use it!

AMSWaves Memory plugin is "The Best" plugin ever made, it opens so many doors, this timer script uses only 1 function from the plugin, so theres no excuses (im not good at code, bla bla bla)



-- declare event constants
WM_TIMER=275

-- define functions
function SetTimer(hWnd, nIDEvent, uElapse)

if tonumber(DLL.CallFunction("user32.dll", "SetTimer", hWnd..", "..nIDEvent..", "..uElapse..", 0", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL)) == 0 then
return false
else
return true
end

end

function KillTimer(hWnd, nIDEvent)

if tonumber(DLL.CallFunction("user32.dll", "KillTimer", hWnd..", "..nIDEvent, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL)) == 0 then
return false
else
return true
end

end


nACounter=0
nBCounter=0

-- define callback
function CallBack(hWnd, uMsg, wParam, lParam)

if uMsg == WM_TIMER then

local nTimerID=wParam

if nTimerID == 100 then

if nACounter == 10 then
KillTimer(hWnd, 100)
end

Label.SetText("Label1", "nTimerID = "..nTimerID.." - nCounter = "..nACounter)
nACounter=nACounter+1


else

if nBCounter == 10 then
KillTimer(hWnd, 200)
end

Label.SetText("Label2", "nTimerID = "..nTimerID.." - nCounter = "..nBCounter)
nBCounter=nBCounter+1

end

end

end

-- test
Memory.CreateWindowSubClass(Application.GetWndHand le(), 0, "CallBack");

SetTimer(Application.GetWndHandle(), 100, 1000)
SetTimer(Application.GetWndHandle(), 200, 100)


and there you have, unlimited multiple global timers for your apps (code took me 10 mins with 1 coffee break),

mystica
12-17-2009, 06:12 AM
This looks really interesting, Microbyte ... but am having a wee bit of trouble.
Any chance of an .apz example for us dummies?
http://img.loldepot.com/c16d9ffaa441da4369b5.gif

jassing
12-17-2009, 12:07 PM
Thanks for posting CODE.
I don't understand the need to make simple scripts a "plugin" -- I did a benchmark on one plugin that I was relatively certain I had code for. the lua code ran faster than the "compiled plugin" code.

I would hope that more people will stop posting .lmd's and post the source lua code instead. The exception, of course, is for commercial plugins with proprietary code and/or C code that can't be run natively.

Thanks for your posting.

Centauri Soldier
12-17-2009, 01:44 PM
That method would have its advantages, I'll grant you but speed is not always what people are after, Jassing. Most complied plugins are meant to add functionality and convenience.

I, for one, prefer the code compiled for my convenience and ease of use throughout my project (referring to Intellisense). Plus, If I had to paste all the code from all the plugins I use in a project, my globals would be unnavigable. Nor do I want all those script files in my scripts folder. Besides, if speed were a priority, I think I would prefer C++ but I am not building programs that require speed to take priority. Also, with plugins (as opposed to scripts) one usually gets a help file with a few examples available at a click and this fact helps me tremendously.

In most cases for me, logic dictates that plugins are the way to go.

MicroByte
12-17-2009, 02:03 PM
well i dont know about that, i am forced to make every effort to ensure my apps are efficient as possible, if i can make a speed improvement then i will, writing apps for a lot of old systems forces me to, AMS can be sluggish on old machines

i do use the compiler tool for my dll plugins, these seem worthy of the overhead, but just small lua scripts i would rather not have binary



Any chance of an .apz example for us dummies?

theres really nothing to it, open a new project, add the memory plugin, add 2 lables to the page, paste the code into "On Show" and run

mystica
12-18-2009, 12:20 AM
theres really nothing to it, open a new project, add the memory plugin, add 2 lables to the page, paste the code into "On Show" and run

See, that just goes to show what a dumbass I can be at times. Only had one label on the page, kept getting error messages, and couldn't figure out why. LMAO ... I'm such an idiot. http://img.loldepot.com/d6d9af8521f80cb0f052.gif Thanks Microbyte.

mystica
12-18-2009, 10:35 AM
http://img.loldepot.com/c77b281f78fe1e4f43d4.gif D'OH!
Keep getting this error message, Microbyte ... what am I doing wrong???
(Have both labels, memory plugin is ticked, and code is on PageOnShow)

http://img.loldepot.com/5e01efc01ca936aac39b.png

Benjamin
01-07-2010, 06:07 AM
Maybe you packed file AMSWMemory.lmd some PE packer? For example UPX

RizlaUK
01-07-2010, 06:20 AM
@mystica, update your memory plugin version :yes

mystica
01-07-2010, 11:57 AM
Thanks Riz. :yes

mangomel
01-15-2010, 07:53 AM
I put this code like mystica did and it works fine but when I close my app, I get message 'application' stopped working - the standard windows message it this case. Any ideas?

Benjamin
01-15-2010, 09:56 AM
Try this on close Memory.FreeWindowSubClass(ID);

RizlaUK
01-15-2010, 12:42 PM
yes, you must always free a window callback!