Sign in to follow this  
Followers 0
xanathos

Need help for some kind of "meter"

14 posts in this topic

Hello there, I'm new to AutoIt scripting

I'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.

Share this post


Link to post
Share on other sites



I was maybe thinking to store the first value in an invisible label, what do you guys think?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 hint

Now 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 by xanathos

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

xanathos,

Perhaps it might work this way: ;)

$calc = GUICtrlRead($label1) - GUICtrlRead($label2)

M23

Indeed it does!

Thanks!

Edited by xanathos

Share this post


Link to post
Share on other sites

#9 ·  Posted (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 by xanathos

Share this post


Link to post
Share on other sites

#10 ·  Posted

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by xanathos

Share this post


Link to post
Share on other sites

#12 ·  Posted

Bump, anyone could provide me a sample ?

Share this post


Link to post
Share on other sites

#13 ·  Posted (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 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

Share this post


Link to post
Share on other sites

#14 ·  Posted

I don't know why I didn't think about it...Thanks for the hint

Heh, 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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0