burners Posted September 22, 2010 Share Posted September 22, 2010 How would I map a low - high variable to a set range Example MAP (0,$n,5,1134) This would theoretically map anything between 0 & $n to 5 - 1134 Thanks ~~--Feel Free to Steal my Sigs --~~FLAT LOOK____________________________________ROUNDED LOOK Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 22, 2010 Moderators Share Posted September 22, 2010 burners,Could you please explain a little more clearly what exactly you are trying to achieve? At the moment I am afraid I have no idea of the context in which you wish to use this "MAP" command. 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...
Smorg Posted September 22, 2010 Share Posted September 22, 2010 I asked about this a few days ago. Apparently autoit doesn't have a native associative array, but since you're just dealing with ints you can use ordinary arrays to map one value to another.This would theoretically map anything between 0 & $n to 5 - 1134My best guess at what you mean by this is "map ints from 0 to n to a corresponding value between 5 and 1134". This would require the cardinality of "0 to $n" to be 1129 so that doesn't make sense. If what you're really asking about is the "map" function of Scheme, Haskell, Javascript, Python, etc - Autoit can do neither anonymous functions nor any real first-class function, so a higher-order map would be very limited if it existed. About the only thing I've found autoit can do with function objects is the "for...in ..." keyword. (though I haven't used autoit in years so there could be others I haven't found yet) Link to comment Share on other sites More sharing options...
burners Posted September 22, 2010 Author Share Posted September 22, 2010 OK, Well I have an idea, will post back in a few minutes. ~~--Feel Free to Steal my Sigs --~~FLAT LOOK____________________________________ROUNDED LOOK Link to comment Share on other sites More sharing options...
burners Posted September 22, 2010 Author Share Posted September 22, 2010 burners,Could you please explain a little more clearly what exactly you are trying to achieve? At the moment I am afraid I have no idea of the context in which you wish to use this "MAP" command. M23This is the best way I can explain it and where I got the ideahttp://www.arduino.cc/en/Reference/Map ~~--Feel Free to Steal my Sigs --~~FLAT LOOK____________________________________ROUNDED LOOK Link to comment Share on other sites More sharing options...
burners Posted September 22, 2010 Author Share Posted September 22, 2010 OK I have some simple math to do the max, working on getting the min into the equation, hopefully without created an array ;Desired min max 0 - 360 ;Actual min max 0 - 1024 ;Example 0=0, 512=180 ,1024=360 $exampleinput = 512 $actualmin = 0 $actualmax = 1024 $adjustedmin = 0 $adjustedmax = 360 $difference = $actualmax / $adjustedmax $adjustedinput = $exampleinput / $difference $adjustedinput = Round($adjustedinput, 1) MsgBox(4096, "Adjusted Difference", $adjustedinput , 10) ~~--Feel Free to Steal my Sigs --~~FLAT LOOK____________________________________ROUNDED LOOK Link to comment Share on other sites More sharing options...
burners Posted September 22, 2010 Author Share Posted September 22, 2010 OK I worked on the min and the problem is that simple math wont do, the math would need to change on a sliding scale as the input changes. Example would be if you have 20-380 as your input and the desired output is 0-360 then we know 20 = 0 and 380 = 360. I can do the math to get either but anything inbetween is hopeless. The issue also comes in when there is a 0, this kills the math dead in its tracks, the last thing I know wouldnt be easy is if the values are swapped and now the input is 0-360 and the output is 20-380. The problems go on and on, the only other thing I can think of is somehow creating an array maybe with the Enum function and use something like for blah blah $actualmax = 1024 $adjustedmax = 360 $n = $actualmax / $adjustedmax Enum Step $n $valueforarray write variable got me ~~--Feel Free to Steal my Sigs --~~FLAT LOOK____________________________________ROUNDED LOOK Link to comment Share on other sites More sharing options...
AlmarM Posted September 23, 2010 Share Posted September 23, 2010 Map value? Func Map($iValue, $iFromLow, $iFromHigh, $iToLow, $iToHigh) Return ($iValue - $iFromLow) * ($iToHigh - $iToLow) / ($iFromHigh - $iFromLow) + $iTolow EndFunc Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. 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