ramadash Posted August 15, 2006 Share Posted August 15, 2006 Hello, let's say I have 3 scripts: -scriptMAIN loads: -scriptSUB1 -scriptSUB2 now how would I go about transfering variables to/from each of them. Actually I only need to get data to main from sub's, and to sub's from main. I tough about object, using a custom made program made to only hold values (I only need a few hex values and id be all set up). But im unsure how object works, can you instanciate an object with scripMAIN and use objGet to retrieve a reference to the object created with scriptMAIN on scriptSUB's? if this would work then it would be amazing because I only need 2 functions: GetValue() and SetValue(). at first I tough EnvVars would be doing it but it's only acessible from child process's so I couldnt retrieve any info on scriptSUB's (let's say the thread state for example). thanks! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 15, 2006 Moderators Share Posted August 15, 2006 If they aren't as larry said, you'll need to look at Ini/Registry/File writes and parsing information that way. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
ramadash Posted August 15, 2006 Author Share Posted August 15, 2006 If they aren't as larry said, you'll need to look at Ini/Registry/File writes and parsing information that way.are you serious? So youre telling me you can't do it with COM? I can do this using text in 5 minutes but it is just soooo ugly there must be a better/proper way of doing it. (with the new autoit version that just got out) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 15, 2006 Moderators Share Posted August 15, 2006 (with the new autoit version that just got out)Not so new for those of us that use(d) beta... so yeah, I'm serious. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
ramadash Posted August 15, 2006 Author Share Posted August 15, 2006 what is the difference btw ObjGet and ObjCreate then? Link to comment Share on other sites More sharing options...
lod3n Posted August 15, 2006 Share Posted August 15, 2006 Well, this might sound silly, but why not use a hidden Notepad, and use ControlSetText to set it's contents with one AutoIt script, and ControlGetText inside the main loop to get it from the other. Or, if you have multiple variables you need to pass, set up a gui on the main app with inputboxes for each, and do the same. The gui could just remain hidden until you have the bugs worked out. Does that make sense? What are you trying to do that you actually need two scripts running at the same time and interacting with each other? Sounds interesting. [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font] Link to comment Share on other sites More sharing options...
Oxin8 Posted August 17, 2006 Share Posted August 17, 2006 Well, I'm helping ramadash with this on another forum and I ran into a problem. When you use GUIRegisterMsg to call a function remotely from another script, the other script can't continue to run until the function(that was remotely called) ends. Maybe the scripts would explain better. Here's the script that calls the function in the other script remotely: $CMD_Msgbox_stats = 10000 $CMD_Quit = 10001 $CMDWindow = WinGetHandle("mmBotCommander") $life = 34735 $mana = 1345 RemoteFunc($CMDWindow, $CMD_Msgbox_stats, $life, $mana) MsgBox(0,"Hey","blah") RemoteFunc($CMDWindow, $CMD_Quit) Func RemoteFunc($window, $functionID, $wparam = 0, $lparam = 0) $dll = DllOpen("user32.dll") DllCall($dll, "none", "SendMessage","hwnd", $window, _ "int", $functionID, "long", $wparam, "long", $lparam) EndFunc This is the main script. This is how I'd like it to be but it doesn't function like I want: #include <GUIConstants.au3> $CMD_Msgbox_stats = 10000 $CMD_Quit = 10001 Global $s = 0, $l, $m $mygui = GuiCreate("mmBotCommander",1,1) GUIRegisterMsg($CMD_Msgbox_stats, "Msgboxstats") GUIRegisterMsg($CMD_Quit, "Quit") While 1 Sleep(10) WEnd Func Msgboxstats($hWndGUI, $MsgID, $life, $mana) MsgBox(0,"mmBot","Health: " & Number($life) & " Mana: " & Number($mana)) EndFunc Func Quit() Exit EndFunc This is want I ended up doing to get the functionality I wanted but to have more than one function would be more than just a little sloppy: #include <GUIConstants.au3> $CMD_Msgbox_stats = 10000 $CMD_Quit = 10001 Global $s = 0, $l, $m $mygui = GuiCreate("mmBotCommander",1,1) GUIRegisterMsg($CMD_Msgbox_stats, "Msgboxstats") GUIRegisterMsg($CMD_Quit, "Quit") While 1 Sleep(10) If $s = 1 Then $s = 0 MsgBox(0,"mmBot","Health: " & Number($l) & " Mana: " & Number($m)) EndIf WEnd Func Msgboxstats($hWndGUI, $MsgID, $life, $mana) $s = 1 $l = $life $m = $mana ;MsgBox(0,"mmBot","Health: " & Number($life) & " Mana: " & Number($mana)) EndFunc Func Quit() Exit EndFunc Maybe that makes enough sense. If not, ask away. Keep in mind, this is more of a proof of concept of what we want to do, it's not a portion of the finished product. ~My Scripts~ *********_XInput UDF for Xbox 360 ControllerSprayPaint_MouseMovePlus Link to comment Share on other sites More sharing options...
ramadash Posted August 17, 2006 Author Share Posted August 17, 2006 thanks everyone that replyed, I should have time to look at this tomorrow, but I think we can do this using ObjCreate from the main script and by getting a reference of the same object using ObjGet from the sub scripts. Ok I don't have more time I should have internet tomorrow so let's meet on irc maby Link to comment Share on other sites More sharing options...
Richard Robertson Posted August 17, 2006 Share Posted August 17, 2006 You could look up DDE. I think it may be limited, but it may solve the problem without a lot of weird problems. Link to comment Share on other sites More sharing options...
ramadash Posted August 18, 2006 Author Share Posted August 18, 2006 After doing some reading I think this can be achieved by implenting a 3rd party com "singleton", well I will post results here when I test it Link to comment Share on other sites More sharing options...
Oxin8 Posted August 18, 2006 Share Posted August 18, 2006 Turns out my problem was in the nature of the API call and not AutoIt. Using PostMessage instead of SendMessage fixes it all up. ~My Scripts~ *********_XInput UDF for Xbox 360 ControllerSprayPaint_MouseMovePlus Link to comment Share on other sites More sharing options...
Smorg Posted August 19, 2006 Share Posted August 19, 2006 Thanks for the feedback guys. Oxin's method should work okay, I'm just wondering if you feel its really the best way to do this since its really sorta jury-rigging a function to work for a differant purpose. What we really need isn't so much a way to set variables, but to dynamically call a function from a remote process, without the need to continuously poll a data pool for a command in either script. I'm talking something similar to HotKeySet except responding to some other system command from another script besides a keypress. What do you feel would be the best way to go about doing this? Ex. Script A & Script B both run independantly performing their actions until an event occurs in script A which calls a function in Script B... without script B having to 'wait' for or 'look' for the event. Script b's normal operation then get interrupted to carry out the function. Moving variables between the two would also be nice, this would be needed to designate paramaters for the functions. Although this can get read from somewhere such as the regestry once one of the scripts knows that it needs to be doing something. (although dynamic variable setting would also be much much more efficient) Link to comment Share on other sites More sharing options...
ivan Posted August 19, 2006 Share Posted August 19, 2006 at first I tough EnvVars would be doing it but it's only acessible from child process's so I couldnt retrieve any info on scriptSUB's (let's say the thread state for example).talking scripts... you can indeed send and receive information, i did something on this and needs cleaning because i've suggested using it to others. You can find the topic in input/outputand i provided some source code examples and their compiled counterparts. (I figured they needed compilation because the pid was required.the files are in i_o_console.ziphope this helps, and it's easier than creating the objects.IVAN Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
Smorg Posted August 19, 2006 Share Posted August 19, 2006 Well are there any other non-gui functions that can respond to events other than hotkeyset? Link to comment Share on other sites More sharing options...
ramadash Posted September 3, 2006 Author Share Posted September 3, 2006 something that could be usefull in cross-script remote function calling: set_Struct( "Function Name" , [param1...param20] ) will: -set a structure with the passed func name and param's (0 to 20 param) call_Struct($ptr) will: -use a pointer to a dll struct and call the function with the passed params you can try it as-is itl show you the values entered in the first function after making a struct and passing his pointer to the call function expandcollapse popupglobal $ptrSTRUCT,$_params set_Struct( "myfunc" , 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ) call_Struct( DllStructGetPtr( $ptrSTRUCT ) ) kill_Struct() func set_Struct($funcNAME, $PARAM1 = 0, $PARAM2 = 0, $PARAM3 = 0, $PARAM4 = 0, $PARAM5 = 0, $PARAM6 = 0, $PARAM7 = 0, $PARAM8 = 0 _ , $PARAM9 = 0, $PARAM10 = 0, $PARAM11 = 0, $PARAM12 = 0, $PARAM13 = 0, $PARAM14 = 0, $PARAM15 = 0, $PARAM16 = 0, $PARAM17 = 0 _ , $PARAM18 = 0, $PARAM19 = 0, $PARAM20 = 0 ) $_params = @NumParams switch @NumParams case 1 $ptrSTRUCT = DllStructCreate ( "char[128]" ) DllStructSetData( $ptrSTRUCT, 1, $funcNAME ) case 2 $ptrSTRUCT = DllStructCreate( "char[128];char[128]" ) DllStructSetData( $ptrSTRUCT, 1, $funcNAME ) DllStructSetData( $ptrSTRUCT, 2, $param1 ) case 3 to 23 $ptrSTRUCT = DllStructCreate( "char[128];int[" & @NumParams & "]" ) DllStructSetData( $ptrSTRUCT, 1, $funcNAME ) for $i=1 to @NumParams DllStructSetData( $ptrSTRUCT, 2, eval( "PARAM" & $i ), $i ) Next endswitch EndFunc func call_Struct($ptr) switch $_params case 1 $pointer = DllStructCreate( "char[128]", $ptr ) call ( DllStructGetData( $pointer, 1 ) ) case 2 $pointer = DllStructCreate( "char[128];char[128]", $ptr ) call ( DllStructGetData( $pointer, 1 ), DllStructGetData( $pointer, 2 ) ) case 3 to 23 $pointer = DllStructCreate( "char[128];int[" & $_params & "]" , $ptr) dim $CallArg[ $_params ] $CallArg[0] = "CallArgArray" for $i = 3 to $_params +1 $CallArg[ $i-2 ] = DllStructGetData( $pointer, 2, $i-2 ) Next call ( DllStructGetData( $pointer, 1 ), $CallArg ) endswitch EndFunc func kill_Struct() $ptrSTRUCT = 0 EndFunc func myfunc( $PARAM1 = 0, $PARAM2 = 0, $PARAM3 = 0, $PARAM4 = 0, $PARAM5 = 0, $PARAM6 = 0, $PARAM7 = 0, $PARAM8 = 0 _ , $PARAM9 = 0, $PARAM10 = 0, $PARAM11 = 0, $PARAM12 = 0, $PARAM13 = 0, $PARAM14 = 0, $PARAM15 = 0, $PARAM16 = 0, $PARAM17 = 0 _ , $PARAM18 = 0, $PARAM19 = 0, $PARAM20 = 0 ) for $i = 1 to @NumParams MsgBox( 0, "", eval ( "PARAM" & $i ) ) Next EndFunc Link to comment Share on other sites More sharing options...
jvanegmond Posted September 3, 2006 Share Posted September 3, 2006 Here is the registry solution which i like to use: $a = 16 $b = "Hello" StoreVar("$a") StoreVar("$b") $c = LoadVar("$a") $d = LoadVar("$b") MsgBox(0,"$a",$c) MsgBox(0,"$b",$d) ClearBuffer() Func StoreVar($VarName) RegWrite("HKEY_CURRENT_USER\Software\AutoIt v3\VarBuffer",$VarName,"REG_SZ",Execute($VarName)) EndFunc Func LoadVar($VarName) Return RegRead("HKEY_CURRENT_USER\Software\AutoIt v3\VarBuffer",$VarName) EndFunc Func ClearBuffer() RegDelete("HKEY_CURRENT_USER\Software\AutoIt v3\VarBuffer") EndFunc This only works locally ofcourse. github.com/jvanegmond 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