unterhunde Posted September 14, 2006 Share Posted September 14, 2006 I just installed AutiIT yesterday so im still a bit of a noob. This script has a few problems as far as I can see. 1. When sChat() is called it flies into an uncontrolable loop. 2. When sTarAtk() is called most of the clicks its control gets get lost in the void. I have to click it like mad to get it to work once. (Might be because my comp is shite and has a Celeron processor. 3. Sometimes key sends dont send the whole string. 4. I cant figure out how to dynamicly allocate new variables/memory with an array. Any Ideas on how to fix those problems? expandcollapse popup#include <Process.au3> #include <GUIConstants.au3> global $gameFile = "";Path to Shadowbane. Ex: C:\Ubisoft\Shadowbane\sb.exe global $mWinTitle = "Yrg";Just to customize what the title of the macro window is. global $sb1 = "sb1"; What you want the first title to be. global $sb2 = "sb2"; What you want the second title to be. global $username1 = "" global $userpwrd1 = "" global $username2 = "" global $userpwrd2 = "" Func getHandle($arg2);Handle getter $sbID = $arg2 $var = WinList($sbID) For $i = 1 to $var[0][0] ; Only display visble windows that have a title If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then global $hwnd = $var[$i][1] EndIf Next Return $hwnd EndFunc Func IsVisible($handle);getHandle() assist func If BitAnd( WinGetState($handle), 2 ) Then Return 1 Else Return 0 EndIf EndFunc Func sTarNear_Atk($arg4);Key Sequnces $sbID = $arg4 $ctrlHandle = getHandle($sbID) sTarNear($sbID) Sleep(1000) sTarAtk($sbID) EndFunc Func sTarNear($arg3);Key sequences $sbID = $arg3 $ctrlHandle = getHandle($sbID) ControlSend($sbID,"",$ctrlHandle,"{HOME}") EndFunc Func sTarAtk($arg1);Send target nearest monster and attack function $sbID = $arg1 $ctrlHandle = getHandle($sbID) ControlSend($sbID,"",$ctrlHandle,"^a") EndFunc Func sOpLogin();Send logins if WinExists($sb1) Then WinActivate($sb1) Send($username1) Send("{TAB}") Send($userpwrd1) Send("{ENTER}") Sleep(1000) Else MsgBox(-1,"Error,G","Window " & $sb1 & " does not exist") EndIf if WinExists($sb2) Then WinActivate($sb2) Send($username2) Send("{TAB}") Send($userpwrd2) Send("{ENTER}") Sleep(1000) Else MsgBox(-1,"Error,G","Window " & $sb2 & " does not exist") EndIf EndFunc Func runGame();Hmmm wonder what this does. I have this off by default. add "runGame()" above buildGUI to add it in. Run($gameFile) Sleep(4000) $tmpTitle = WinGetTitle("Shadowbane") WinSetTitle($tmpTitle,"",$sb1) Send("{ESC}") Sleep(500) Send("{ESC}") Sleep(500) Send("{ESC}") Sleep(5000) Run($gameFile) Sleep(4000) $tmpTitle = WinGetTitle("Shadowbane") WinSetTitle($tmpTitle,"",$sb2) Send("{ESC}") Sleep(500) Send("{ESC}") Sleep(500) Send("{ESC}") Sleep(5000) EndFunc Func buildGUI();Makes the GUI with the buttons and such GUICreate($mWinTitle,300,300,800,200) ; will create a dialog box that when displayed is centered GUICtrlCreateLabel ("Send to chat:", 5,10); create first item global $sInput = GUICtrlCreateInput("Type what to say",5,25,290,20) global $sSend = GUICtrlCreateButton("Send Command",5,50,100,20) global $sTarNear = GUICtrlCreateButton("Target Nearest",110,50,100,20) global $sTarAtk = GUICtrlCreateButton("Attack Target",110,70,100,20) global $sTarNear_Atk = GUICtrlCreateButton("Attack Nearest",110,90,100,20) global $sLogin = GUICtrlCreateButton("Login",5,270,100,20) GUISetState () EndFunc Func sChat($arg5,$arg6);Sends whats typed in the text bar. $cmd = $arg5 $sbID = $arg6 $ctrlHandle = getHandle($sbID) ControlSend($sbID,"","","{ENTER}") ControlSend($sbID,"","",$cmd) ControlSend($sbID,"","","{ENTER}") Sleep(1000) EndFunc buildGUI() Do $msg = GUIGetMsg() if $msg = $sTarNear Then if WinExists($sb1) Then sTarNear($sb1) Else MsgBox(-1,"Error,G","Window " & $sb1 & " does not exist") EndIf if WinExists($sb2) Then sTarNear($sb2) Else MsgBox(-1,"Error,G","Window " & $sb2 & " does not exist") EndIf EndIf if $msg = $sTarAtk Then if WinExists($sb1) Then sTarAtk($sb1) Else MsgBox(-1,"Error,G","Window " & $sb1 & " does not exist") EndIf if WinExists($sb2) Then sTarAtk($sb2) Else MsgBox(-1,"Error,G","Window " & $sb2 & " does not exist") EndIf EndIf if $msg = $sTarNear_Atk Then if WinExists($sb1) Then sTarNear_Atk($sb1) Else MsgBox(-1,"Error,G","Window " & $sb1 & " does not exist") EndIf if WinExists($sb2) Then sTarNear_Atk($sb2) Else MsgBox(-1,"Error,G","Window " & $sb2 & " does not exist") EndIf EndIf if $msg = $sLogin Then sOpLogin() WinActivate("SB Control") EndIf if $msg = $sSend Then $cmd = GUICtrlRead($sInput) if WinExists($sb1) Then sChat($cmd,$sb1) Else MsgBox(-1,"Error,G","Window " & $sb1 & " does not exist") EndIf if WinExists($sb2) Then sChat($cmd,$sb2) Else MsgBox(-1,"Error,G","Window " & $sb2 & " does not exist") EndIf WinActivate("SB Control") EndIf Until $msg = $GUI_EVENT_CLOSE Link to comment Share on other sites More sharing options...
Paulie Posted September 14, 2006 Share Posted September 14, 2006 If you've never used Autoit, how'd you write a proggy like that? Don't you think a program like this is a little advanced for a one day autoit user? start off by reading the helpfile and the online documentation (Link in Sig) Do some "hello world" scripts and familiarize yourself with the functions that way, you don't have to ask Link to comment Share on other sites More sharing options...
dandymcgee Posted September 14, 2006 Share Posted September 14, 2006 (edited) If you've never used Autoit, how'd you write a proggy like that?Don't you think a program like this is a little advanced for a one day autoit user? start off by reading the helpfile and the online documentation (Link in Sig)Do some "hello world" scripts and familiarize yourself with the functionsthat way, you don't have to askEither this guy has like super speed learning abilities, or knows how to copy & paste. That program is twice the size anything I've ever written, and I've been using AutoIt for almost two months now, lol. Just my opinion P.S. That script has an excellent tidy to it! Edited September 14, 2006 by dandymcgee - Dan [Website] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 14, 2006 Moderators Share Posted September 14, 2006 (edited) Read the help file?... He asked some pretty specific questions and showed his script, that deserves a tad bit of respect in my opinion, not the standard ... you're a noob, don't bother us until you RTFM response we all like to give. Questions: 1. You never change the condition, so if the windowexists after the first go around, it' going to keep going until it doesn't. 2. Try ControlFocus() before your ControlSend() 3. Be sure you're sending them correctly, if you have special characters, you may want to use Raw mode, or maybe even ControlSetText(). 4. I have no idea what your asking there to be honest. ** Things to stay away from, Declaring Global Variables within functions is considered a NO/NO ... If you need the rest of the script to use them, then declare them outside the functions global before you call them. (referring to buildgui function.) Edited September 14, 2006 by SmOke_N 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...
Paulie Posted September 14, 2006 Share Posted September 14, 2006 Read the help file?... He asked some pretty specific questions and showed his script, that deserves a tad bit of respect in my opinion, not the standard ... you're a noob, don't bother us until you RTFM response we all like to give.Questions:1. You never change the condition, so if the windowexists after the first go around, it' going to keep going until it doesn't.2. Try ControlFocus() before your ControlSend()3. Be sure you're sending them correctly, if you have special characters, you may want to use Raw mode, or maybe even ControlSetText().4. I have no idea what your asking there to be honest.**Things to stay away from, Declaring Global Variables within functions is considered a NO/NO ... If you need the rest of the script to use them, then declare them outside the functions global before you call them. (referring to buildgui function.)I never meant any disrespect, just saying that a one-day-er who openly admits to just downloading yesterday has a near fully functional rather in-depth script seems as though it is a good possibility thathe just swiped a code from somewhere changes some names and has no idea how it worksIn which case, reading a little more wouldn't hurt Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 14, 2006 Moderators Share Posted September 14, 2006 I never meant any disrespect, just saying that a one-day-er who openly admits to just downloading yesterday has a near fully functional rather in-depth script seems as though it is a good possibility thathe just swiped a code from somewhere changes some names and has no idea how it worksIn which case, reading a little more wouldn't hurtI agree, but I don't think the code is "advanced", it uses very very few functions at all, other than the fact that he's using parameters with them (don't see that often), I don't see it. Maybe he's versed in other languages, I know some super proficient people that don't post much on here, and their first scripts are 10 x's better or more thought oriented than anything I would have/or would consider. (Shuddup Gary!)...All in all, I agree that the questions don't really match the talent displayed, but ... we all miss little things every now and again.... 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...
unterhunde Posted September 14, 2006 Author Share Posted September 14, 2006 (edited) I agree, but I don't think the code is "advanced", it uses very very few functions at all, other than the fact that he's using parameters with them (don't see that often), I don't see it. Maybe he's versed in other languages, I know some super proficient people that don't post much on here, and their first scripts are 10 x's better or more thought oriented than anything I would have/or would consider. (Shuddup Gary!)...All in all, I agree that the questions don't really match the talent displayed, but ... we all miss little things every now and again....HAha thanks for your suggestions. Im familliar with most programming languages out there. I jut dont get a lot of practice. And I did copy past the getHandle() meat and IsVisible() from the help file..no point in retyping it when I dont have to lol. I fixed the global declaration inside the function after reading on the forums some. Last time I used autoIT ws v1 or v2 or something so Im not sure how similar they are. lol but enough self defense.Ill test out the things you suggested. Im still getting the hang of properly handling the GUI. I usually just write console progs. with some cout/cin type interfaces. Edited September 14, 2006 by unterhunde Link to comment Share on other sites More sharing options...
unterhunde Posted September 14, 2006 Author Share Posted September 14, 2006 (edited) 4. I have no idea what your asking there to be honest.basicaly like whats done with linked lists in c++ or other langs. I want to be able to create more variables if needed during runtime..I was pretty sleepy when i wrote the fist version of this script and tried it. And now that I just decided to be long winded and type and if for every account instead of using a recycled array function to hold the title,handle, and procID for all occuring instances of sb.exe, i dont really need it. But I would like to slim the code down if i could. recursive array would help other users be able to add more accounts to it with ease. Edited September 14, 2006 by unterhunde Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 14, 2006 Moderators Share Posted September 14, 2006 basicaly like whats done with linked lists in c++ or other langs. I want to be able to create more variables if needed during runtime..I was pretty sleepy when i wrote the fist version of this script and tried it. And now that I just decided to be long winded and type and if for every account instead of using a recycled array function to hold the title,handle, and procID for all occuring instances of sb.exe, i dont really need it. But I would like to slim the code down if i could. recursive array would help other users be able to add more accounts to it with ease.Just use an Array and ReDim when neccessary.... Or have a look at Assign() << not a big fan there personally. 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...
unterhunde Posted September 14, 2006 Author Share Posted September 14, 2006 Just use an Array and ReDim when neccessary.... Or have a look at Assign() << not a big fan there personally.Cool. I just glanced at it but I think Assign is what I needed. I forgot that in c++ i creted new $vars by grabbing adjacent memory locations and giving those names/values. Link to comment Share on other sites More sharing options...
dandymcgee Posted September 14, 2006 Share Posted September 14, 2006 (edited) @unterhunde - Hey dude, sorry if you took that disrespectiful in any way. It's just that when I see somebody with Posts: 5 under their name, I immediately conclude their a complete newbie and know nothing about programming ( mostly for the reason that this was my first scripting language ). Just from those few posts you have made already, you obviously aren't an idiot when it comes to programming languages. Maybe you'll end up teaching me a few things Anyways, hope you didn't take it the wrong way, and if I see a post that I know I can help with, I sure will. Hope you can get the most out of AutoIt, and WELCOME TO THE FORUMS!!! Edited September 14, 2006 by dandymcgee - Dan [Website] Link to comment Share on other sites More sharing options...
unterhunde Posted September 15, 2006 Author Share Posted September 15, 2006 @unterhunde - Hey dude, sorry if you took that disrespectiful in any way. It's just that when I see somebody with Posts: 5 under their name, I immediately conclude their a complete newbie and know nothing about programming ( mostly for the reason that this was my first scripting language ). Just from those few posts you have made already, you obviously aren't an idiot when it comes to programming languages. Maybe you'll end up teaching me a few things Anyways, hope you didn't take it the wrong way, and if I see a post that I know I can help with, I sure will. Hope you can get the most out of AutoIt, and WELCOME TO THE FORUMS!!!Its cool man. No hard feelings. Thanks for the welcome. 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