Sign in to follow this  
Followers 0
Myicq

Named arguments in function call - any ideas

3 posts in this topic

I have a project where I wish to create a layout file for a drawing program using AutoIT.

The format for this program is simple: header, objects (1..n), properties. Most of it, I have in control.

But I need an idea about how best to add the objects. Here, an object has some properties such as coordinate, font etc. My idea is to call a function like add_object() which will add with default parameters.

Now to my question: how can I "override" parameters in the function call ? I do not know which parameters will be overridden, this depends on user choices. So thereby I do not know the number of parameters in my function call.

Do anyone have an idea about how to do achieve something like this, which is inspired from Perl

; pseudocode function call:
add_object(
    'xpos' => '123',
    'font' => 'Arial',
    'rotation' => '90' )   ; the remaining parameters will be default

; pseudo code
func add_object(byref $paramsettings)
  $original = get_default_object()   ; first load a default object type
   for each $key ($paramsettings)
       $original[$key] = $paramsettings[$key]   ; override default here
   next
   write_out_object($original)   ; now with modified original
endfunc

I have looked at but I am not 100% sure how to pass as an argument and (specifically) how to check which keys are passed ? (as in "for each $keys in $passed_array")

Any help welcomed.


I am just a hobby programmer, and nothing great to publish right now.

Share this post


Link to post
Share on other sites



Your post makes me think that you'd be better looking at AutoIt object for your objects manipulations and towards SQLite for storage/query. Of course this is an out of the blue wild guess unless more requirements/constraints are thrown.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

i love this UDF too, its minimalistic and straight.

So what about defining a func which fills an AssoArray with standard values.

Then if you want to make an custom object you call the function, then change the values you want, then call the "make Object" function.

You dont event need to pass arguments as the AssoArray is global accessible.

#include <AssoArrays.au3>

_SetDefault()
x("obj.xpos",123)
x("obj.font",'Arial')
x("obj.rotation",90)
x_display()

write_out_object()

Func _SetDefault()
    x("obj.xpos",0)
    x("obj.ypos",0)
    x("obj.font",'Arial')
    x("obj.rotation",0)
    x("obj.edge",10)
EndFunc


Func write_out_object()
    DrawObj(x("obj.xpos"),x("obj.ypos"))
    RotateObj(x("obj.rotation"))
    ....
EndFunc

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

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

  • Similar Content

    • therms
      By therms
      If you don't like dealing with Scripting.dictionary you might want to try out this thing I whipped up yesterday evening and this morning.
      Basically just a simple wrapper around Scripting.dictionary to make the API a little bit less stupid.  By "stupid" I mean "not like the awesome Python dict API".
      Created for the following reasons..
      Wanted to get a basic understanding of AutoItObject. Wanted to get a basic understanding of the Micro unit test framework. As of 11/4/2014 AutoIt Stable has no native dict or associative array type.  A >Map type is in the current AutoIt beta. It's laborious to use Scripting.dictionary all the time. The Python dict API is better than Scripting.dictionary's I thought about writing my own hash table implementation in AutoIt, but on balance I decided it wasn't worth the effort and just stuck to Scripting.dictionary to save time/effort.
      As you can see I've got a decent number of unit tests for such a simple implementation, so it should be quite robust.
      #include <Dict2.au3> #include <Array.au3> $dict = _DictCreate() ConsoleWrite($dict.len()) ; Outputs 0 $dict.set("key1", "value1") $dict.set("key2", "value2") $dict.set("key3", "value3") $dict.set("key4", 1) ConsoleWrite($dict.get("key2")) ; Outputs 'value2' ConsoleWrite($dict.len()) ; Outputs 3 ConsoleWrite($dict.contains("key2") ; Outputs True $dict.set("key4", $dict.get("key4") + 1) ConsoleWrite($dict.get("key4")) ; Outputs 2 $dict.del("key4") ConsoleWrite($dict.contains("key4")) ; Outputs False $aPairs = $dict.pairs() _ArrayDisplay($aPairs) ; Displays 2d array with column one contains keys, and column two ; containing associated values $aKeys = $dict.keys() _ArrayDisplay($aKeys) ; Displays array containing all keys $aValues = $dict.values() _ArrayDisplay($aValues) ; Displays array of all values $aDesiredKeys = ["key1", "key3"] $aValues = $dict.values($aDesiredKeys) _ArrayDisplay($aValues) ; Displays array of values for key1 and key3 GET IT HERE
    • b47chguru
      By b47chguru
      Few days back i made an associative array UDF for a project as autoit does not have associative array/PHP style array support.it does not keep up to the quality of the example scripts posted in this forum.
      I hope it may be useful to other amateur developers like me.
       
       
      Main UDF file:
      associative_arrays.au3
       
       


       




       
      CHM help file:
       
      associativearray_chm.zip
       
       
      list of main functions:
      _SetAssociativeArray() _AddAssociativeArray() _AssociativeArray() print_r() array2json() Json2Array() example script:

      #include <associative_arrays.au3> $datas = '' ; creates a variable ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; Associative_array exmples ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;first example: seting an array value $value = _SetAssociativeArray($datas, 'roger->royal->datar', '','changedatata=>>inprogressd', True) ConsoleWrite(@CR&'first example: seting an array value'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf $value = _AddAssociativeArray($datas, 'roger->royal->datar->0', -1, 'changedatata=>>inprogress', True) ;makes a sub array ConsoleWrite(@CR&'creating a non existent array path roger->royal->datar->0'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf ;second example: pushing an element to the end of an array $value = _AddAssociativeArray($datas, 'roger->royal->datar', -1, 'changedatata=>>inpro', True) ConsoleWrite(@CR&'second example: pushing an element to the end of an array'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf ;third example: adding an element to the 2nd index position in the associative array $value = _AddAssociativeArray($datas, 'roger->royal->datar', 2, 'added element to 2nd position', True) ConsoleWrite(@CR&'third example: adding an element to the 2nd index position in the associative array'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf ;fourth example: changing the element in the 2nd index position in the associative array $value = _SetAssociativeArray($datas, 'roger->royal->datar', 2, '2nd element changed') ConsoleWrite(@CR&'fourth example: changing the element in the 2nd index position in the associative array'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf ;fifth example: changing the element in the first index position in the associative array $value = _SetAssociativeArray($datas, 'roger->royal->datar', 1, 'first element changed') ConsoleWrite(@CR&'fifth example: changing the element in the first index position in the associative array'&@CR) If $value > -1 Then print_r($datas) Else ConsoleWrite("Failed: " & $value) EndIf _SetAssociativeArray($datas, 'list', '', 'echo', True);makes another array in the root $value = _AssociativeArray($datas, 'roger->royal->datar') _ArrayDisplay($value, 'sixth example: reading an array at the position roger->royal->datar') ConsoleWrite(@CR & 'seventh example: reading the second element of an array'& @CR &_AssociativeArray($datas, 'roger->royal->datar', 2)) $value = _AssociativeArray($datas, 'roger->royal->data') _ArrayDisplay($value, 'eighth example: trying to read an array which doesnt exist') ;print_r($datas) $test_json = '{"0":"again0","1":"again1","5":{"0":"test1","male":["asf","s:dfs,f"," boo\r\n hoo"],"1":"test2","2":"test\t3","3":"dgdg \\n fdgd"},"6":"test4","7":"test5"}' $json_test_array = '' $value = Json2Array($json_test_array, $test_json) ConsoleWrite(@CR&'Converting a json to an associative array'&@CR) If $value > -1 Then print_r($json_test_array) Else ConsoleWrite("Failed: " & $value) EndIf ConsoleWrite(@crlf&'Converting an associative array to json'&@CR& array2json($json_test_array)&@CRLF) ConsoleWrite(Get_Ass_Array($json_test_array, '0', 0, True)&@CR)  Do let me know if there are any bugs..
      Thank you..