xanathos Posted May 6, 2012 Share Posted May 6, 2012 Hello there, I'm new to AutoIt scriptingI'm trying to make a small utility as an XP meter, so basically, I know how it should be done:1. Reading the memory address (done)2. Read the memory address x seconds later (how should I store the previous value?)3. Subtract 2nd value to 1st value and return the "average" value per x seconds (Should be doable if the previous step wouldn't be a problem)4. Multiply that value per XX (for example per 60 if I get the value every minute) to obtain an average per hour (Again I know how to multiply but the step 2. is a real problem for me)Is it the right way to do that? If so, would anyone help me? Thanks. Link to comment Share on other sites More sharing options...
xanathos Posted May 6, 2012 Author Share Posted May 6, 2012 I was maybe thinking to store the first value in an invisible label, what do you guys think? Link to comment Share on other sites More sharing options...
somdcomputerguy Posted May 6, 2012 Share Posted May 6, 2012 Variables are invisible, unless you see them in the code.. They'd be good to store data in. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
xanathos Posted May 6, 2012 Author Share Posted May 6, 2012 (edited) Variables are invisible, unless you see them in the code.. They'd be good to store data in.I don't know why I didn't think about it...Thanks for the hintNow I have another problem, when I substract my 2 values I get -1 for some reason I have tried with another operator (+), and the result is always 9 Edited May 6, 2012 by xanathos Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2012 Moderators Share Posted May 6, 2012 xanathos,At a guess you are using the ControlIDs of the controls and not their contents (you need to use GUICtrlRead to get that). Please post the code you have so we can confirm this. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
xanathos Posted May 6, 2012 Author Share Posted May 6, 2012 xanathos, At a guess you are using the ControlIDs of the controls and not their contents (you need to use GUICtrlRead to get that). Please post the code you have so we can confirm this. M23 I'm so stupid...That's right, labels contain not only numbers, but now the problem is that it always returns 0 no matter what... Func Param1() Local $p1 = MemReadDLL("Meter.dll", $offset, "dword") Local $Addy = _MemoryModuleGetBaseAddress($pid, "Meter.dll") GUICtrlSetData($Label1, $p1) EndFunc Func Param2() Local $p2= MemReadDLL("Meter.dll", $offset, "dword") Local $Addy = _MemoryModuleGetBaseAddress($pid, "Meter.dll") GUICtrlSetData($Label2, $p2) EndFunc Func MeterH() $calc = GUICtrlRead($label1 - $label2) GUICtrlSetData($Label3, Int($calc)) EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2012 Moderators Share Posted May 6, 2012 xanathos, Perhaps it might work this way: $calc = GUICtrlRead($label1) - GUICtrlRead($label2) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
xanathos Posted May 6, 2012 Author Share Posted May 6, 2012 (edited) xanathos, Perhaps it might work this way: $calc = GUICtrlRead($label1) - GUICtrlRead($label2) M23 Indeed it does! Thanks! Edited May 6, 2012 by xanathos Link to comment Share on other sites More sharing options...
xanathos Posted May 6, 2012 Author Share Posted May 6, 2012 (edited) Now comes another problem To do an average per hour, I'm a little bit confused, if anyone could give me a hand: -I have set a timer for param1 so its "updating" that value every minute -After that I substract $p2 to $p1, and multiply the result by 60 But I'm afraid the average might not be accurate, since the value changes randomly every X seconds What is the best way? Set the timer to 5 minutes, so the average gets more accurate? But problem is that I would need to wait 5 minutes everytime to see the updated meter, and if the value doesn't change for few minutes, then again it will not be accurate at all...I'm really stuck... Edited May 6, 2012 by xanathos Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2012 Moderators Share Posted May 6, 2012 xanathos,You need a "moving average". I suggest using an array to hold the last X values and then averaging them. If you have wildly fluctuating values then a "moving median" as explained in the link might be of more use. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
xanathos Posted May 6, 2012 Author Share Posted May 6, 2012 (edited) So, would it be a good way: 1-Get 10 values, 1 every 6 seconds, and store them respectively from array[1] to array[10], until all are stored. 2-10 x 6 = 60 seconds, so from that make an average per hour (((array[1]+array[2]+..[array10]) / 10) x 60) 3-Once the average from the previous 10 arrays has been made (store new ones again (repeat step 1) 4-Repeat step 2 Loop that Edited May 6, 2012 by xanathos Link to comment Share on other sites More sharing options...
xanathos Posted May 6, 2012 Author Share Posted May 6, 2012 Bump, anyone could provide me a sample ? Link to comment Share on other sites More sharing options...
Bowmore Posted May 7, 2012 Share Posted May 7, 2012 (edited) Here is an example of a simple function that will return the average of the last however many values you want. The default is 10 values While 1 $Value = Random(0, 100) ;<=== Some randome number to average $Average = _AverageLastN($Value,10) ;<=== Change the 10 to whatever you want ConsoleWrite('$Average = ' & $Average & @CRLF) Sleep(1000) WEnd Func _AverageLastN($NewValue,$n=10) Static Local $aLast10[$n] Local $nAverage = 0 For $i = 0 To $n - 2 $aLast10[$i] = $aLast10[$i + 1] $nAverage += $aLast10[$i] Next $aLast10[$n-1] = $NewValue $nAverage += $aLast10[$n-1] $nAverage /= $n Return $nAverage EndFunc ;==>_AverageLastN Edited May 7, 2012 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
somdcomputerguy Posted May 8, 2012 Share Posted May 8, 2012 I don't know why I didn't think about it...Thanks for the hintHeh, I'm glad you didn't take that too bad. I did intend it sorta smart-assed, but in a cool nature. You know? I don't really understand the project you're on, so I can't really help you there. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now