grandim Posted March 2, 2010 Share Posted March 2, 2010 (edited) I have a script that works on its own but will not work if its included into another script with its own gui. Here's the code that works on its own Global $button OtherScript() Func OtherScript() UnrelatedFunction() MakeAChoice() AnotherUnrelatedFunction() endfunc Func MakeAChoice() $Gui2 = GUICreate("Please make your choice", 200, 100) $ButtonA = GUICtrlCreateButton("A", 20, 50, 60) $ButtonB = GUICtrlCreateButton("B", 90, 50, 60) GUISetState(@SW_SHOW) GUICtrlSetOnEvent($ButtonA , "ButtonTypeA") GUICtrlSetOnEvent($ButtonB, "ButtonTypeB") While $button = "" Sleep(50) WEnd GUIDelete($Gui2) Return EndFunc Func ButtonTypeA() $button = "A" EndFunc Func ButtonTypeB() $button = "B" EndFunc And this is what calls it in the other gui $GoToOtherScript = GUICtrlCreateMenuItem("OtherScript", $toolsmenu) GUICtrlSetOnEvent($GoToOtherScript , "OtherScript") Running the script in autoit debugger shows the script idling in the while loop(never entering a button function), and entering in GUIonchangeRegister whenever I click the a button. I tried to user GuiSwitch() and various changes on the loop but I alway get the same results. Edited March 2, 2010 by grandim Link to comment Share on other sites More sharing options...
martin Posted March 2, 2010 Share Posted March 2, 2010 (edited) What you have shown looks ok except that you do not have Opt("GuiOnEventMode",1) Maybe that is the problem. Welcome to the AutoIt forums grandim Edited March 2, 2010 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
grandim Posted March 2, 2010 Author Share Posted March 2, 2010 What you have shown looks ok except that you do not have Opt("GuiOnEventMode",1) Maybe that is the problem.Welcome to the AutoIt forums grandim Thanks,Opt("GuiOnEventMode",1) is set at the top of both files so that shouldn't be the issue. Link to comment Share on other sites More sharing options...
martin Posted March 2, 2010 Share Posted March 2, 2010 (edited) Thanks, Opt("GuiOnEventMode",1) is set at the top of both files so that shouldn't be the issue. I should have noticed before but in my defence you have made it a little difficult by not posting some code we can run. This is what I think you are doing; clicking a menu item: that causes an event which runs the function OtherScript: in that function you do various things including setting new events when a button is clicked. It won't work because events are queued and the event for the button won't be actioned untill you return from OtherScript. This is what I think you need to do- ;some code to create the first gui $GoToOtherScript = GUICtrlCreateMenuItem("OtherScript", $toolsmenu) GUICtrlSetOnEvent($GoToOtherScript , "OtherScriptA") ; other stuff Global $CallOther = False while 1;your idle loop if $CallOther then $CallOther = False OtherScript() endif wend Func OtherScriptA() $CallOther = True EndFunc Edited March 2, 2010 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. 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