Jump to content

Triblade

Active Members
  • Posts

    392
  • Joined

  • Last visited

Everything posted by Triblade

  1. GaryFrost once helped me with this in my script. Please do note that the script I link to is from 2007 and not updated anymore. I think most would still work though, From this you should be able to extract the bits you need. Especially this bit: " Local $hping = Run(@ComSpec & " /c ping -n 1 -w 10 " & $sLocation, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($hping) If @error Then ExitLoop $sData &= $line WEnd " The 'Local' line replaces your '$DOS =SEND' line. The While 1 loop reads all output and stitches them together in the $sData variable. Now you should be able to extract the output you seek with StringInStr, StringMid etc. Edit: oh, and don't forget to replace the ping command/parameters with the command you want. Good luck, Regards, Tri.
  2. Thanks! I now made a reset button, a new label for a bit more show-and-tell and some minor GUI tweaks. When I convert this in a fully usable UDF, I'll add-in a start and finish location, in both border modes. At the moment it's too much GUI integrated for my liking.
  3. Hi folks! First off, yeah this may be the lamest title. But it made you look anyway! Edit: Now updated! With step-counter, reset button and a few GUI-tweaks. (the step-counter is cheating! It's calculated in advance...) I recently thought a screenshot of a finished maze may be smart to show, instead of only my long story and code. o=path, x=wall. Here it is: I started making my own implementation of the A* pathing script in a larger project, inspired by Toady's work. (But made one from scratch myself anyway ) After the A* pathing script was working (not cleaned up yet) I wanted to test it. Unfortunately I got no good, randomized, maze lying around that also had the format I needed. So I made my own maze generator! I did a few hours of research on the matter and then a few evenings of scripting. For the people who are interested, one of my problems was that I needed 'one-cell' thick walls. Most maze generation have 1 pixel thick walls drawn by a line, that could be opened if a path is needed. The solution is so simple, I needed this guy to tell me. Click here for my inspiration source. This generator can be used with different sizes maze, even uneven ones! Just set the width and height settings. FYI, it must be odd numbers for this maze to work with it's containment walls. It's the 'simple' Depth-First Search, with backtracking. And without further ado; my a-maze-ing generator!: #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: A-maze-ing generator Script Function: Generates a maze. In the $xy[$i][4] is the maze in array form. Don't forget to take the size with it, else it's just a string of o's and x's It does not generate an entrance or exit! #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <Array.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> ; Set various variables ; width and height must be odd numbers to have a closed, functioning maze. Global $height = 27 ; demo height = 27 Global $width = 43; demo width = 43 ; Check if width & height are an odd number (to get the outer edge an odd number is required) If mod($height, 2) = 0 Or $height < 5 Then msgbox(0,"","Height is not an odd number or a minimum of 5 tall !") Exit ElseIf mod($width, 2) = 0 Or $width < 5 Then msgbox(0,"","Width is not an odd number of a minimum of 5 wide !") Exit EndIf ; Set various variables when script is not exited Global $grid_size = $height * $width Global $numberofsteps = (Ceiling(($height-2) / 2) * (($width-2) - Ceiling(($width-2) / 2))) + (($height-2) - Ceiling(($height-2) / 2)) ; long formula to check the number of steps this maze will take, this is a mathematical given with a fixed number of cells. And yes, I am aware I'm taking a shortcut in this formula. ;) Global $curpos Global $backtrack[1] Global $bt = 0 Local $grid_pixel = 20 ;How many pixels per square ; Initialize main array with all grid data Global $xy[$grid_size + 1][5] Global $reset_xy = $xy ; set the reset array $xy[0][0] = $grid_size ; first entry is the total number of nodes, rest is set with a header name for easy reference in _ArrayDisplay if needed. $xy[0][1] = "ID" $xy[0][2] = "Row" $xy[0][3] = "Column" $xy[0][4] = "Type" ; Fill the grid array with 'walls' For $i = 1 To $xy[0][0] $xy[$i][4] = "x" Next ; Start GUI and create standard buttons Local $gui = GUICreate("A-maze-ing generator", 180 + ($width * $grid_pixel), 80 + ($height * $grid_pixel)) ; Set the main window to the minimum width (IF) needed for the msgbox Local $aPos = WinGetPos($gui) If $aPos[2] < 696 Then $aPos[2] = 696 WinMove($gui, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3]) EndIf GUICtrlCreateLabel("This is a-maze-ing!", 30, 19) Global $progress = GUICtrlCreateLabel("Standing by... " & $numberofsteps & " steps to go.", 150, 15, 550, 30) Local $iOKButton = GUICtrlCreateButton("Start", 45, 50, 60) Local $iResetButton = GUICtrlCreateButton("Reset", 45, 90, 60) Local $iExitButton = GUICtrlCreateButton("Exit", 45, 130, 60) GUICtrlSetFont($progress, 15) GUICtrlSetColor($progress, 0x00AA00) GUICtrlSetState($iResetButton, $GUI_DISABLE) ; Create label-grid and fill the xy array with the positions Local $squarenr = 0 For $i = 0 To ($height * $grid_pixel) - $grid_pixel Step $grid_pixel ; Row For $j = 0 To ($width * $grid_pixel) - $grid_pixel Step $grid_pixel ; Column $squarenr = $squarenr + 1 $xy[$squarenr][0] = GUICtrlCreateLabel('x', 150 + $j, 50 + $i, $grid_pixel, $grid_pixel, BitOr($SS_SUNKEN, $SS_CENTER)) ; if you want debugging numbers, replace 'x' with $squarenr GUICtrlSetBkColor($xy[$squarenr][0], 0x5E87C9) ; lightblue-ish $xy[$squarenr][1] = $squarenr $xy[$squarenr][2] = ($i / $grid_pixel) + 1 $xy[$squarenr][3] = ($j / $grid_pixel) + 1 Next Next $reset_xy = $xy ; Show GUI GUISwitch($gui) GUISetState(@SW_SHOW) ; Start looping and waiting for input Local $aMsg = 0 While 1 $aMsg = GUIGetMsg(1) Select Case $aMsg[0] = $iOKButton GUICtrlSetState($iOKButton, $GUI_DISABLE) GUICtrlSetState($iResetButton, $GUI_DISABLE) GUICtrlSetState($iExitButton, $GUI_DISABLE) GUICtrlSetColor($progress, 0xFF8C00) ; orange GUICtrlSetData($progress, "Running - Creating maze. Please stand by... " & $numberofsteps & " steps to go.") make_maze() GUICtrlSetColor($progress, 0xFF0000) ; red GUICtrlSetData($progress, "Maze complete!") Sleep(1000) ; Just a small sleep for dramatic effect GUICtrlSetColor($progress, 0x00AA00) ; green-ish GUICtrlSetData($progress, "Maze completed in " & $numberofsteps & " steps.") GUICtrlSetState($iResetButton, $GUI_ENABLE) GUICtrlSetState($iExitButton, $GUI_ENABLE) Case $aMsg[0] = $iResetButton GUICtrlSetData($progress, "Resetting maze...") reset_maze() GUICtrlSetState($iResetButton, $GUI_DISABLE) GUICtrlSetState($iOKButton, $GUI_ENABLE) GUICtrlSetData($progress, "Maze reset!") Sleep(1000) ; Just a small sleep for dramatic effect GUICtrlSetData($progress, "Standing by...") Case $aMsg[0] = $GUI_EVENT_CLOSE Or $aMsg[0] = $iExitButton ExitLoop EndSelect WEnd Exit ; Resetting the maze to default state Func reset_maze() $xy = $reset_xy ; Set the $xy array back to it first-run values For $i = 1 To $xy[0][0] $xy[$i][4] = "x" ; set everything to 'x' GUICtrlSetBkColor($xy[$i][0], 0x5E87C9) ; reset the background color GUICtrlSetData($xy[$i][0], "x") ; (re)set the label to 'x' Next EndFunc ; Main function Func make_maze() Local $heading Local $stepcount = $numberofsteps ; Reset the step counter. Local $timed = TimerInit() ; Start the timer to see how long the maze generation took. $backtrack[0] = 0 $curpos = $width + 2 ; This is the starting position, second row, second column - aka top-left, one in from the sides. open_maze($curpos) ; Set the starter cell to 'open / white' ; Main maze generation loop While 1 Do $heading = direction($curpos) Until $heading <> 0 If $bt = 1 Then $bt = 0 ; reset backtracking-tracker, else the backtracking array keeps adding the current position GUICtrlSetData($progress, "Running - Creating maze. Please stand by... " & $stepcount & " steps to go.") Sleep(50) ; Slow maze creation down to look at it - relax! (or don't and comment out the sleep) If $heading = -1 Then ExitLoop $stepcount -= 1 ; Count down the steps to finish. ; We got the heading - now which way do we go? After that, set the current position to the last known heading. Switch $heading Case 1 ; north open_maze($curpos - $width) open_maze($curpos - ($width * 2)) $curpos = $curpos - ($width * 2) Case 2 ; east open_maze($curpos + 1) open_maze($curpos + 2) $curpos = $curpos + 2 Case 3 ; south open_maze($curpos + $width) open_maze($curpos + ($width * 2)) $curpos = $curpos + ($width * 2) Case 4 ; west open_maze($curpos - 1) open_maze($curpos - 2) $curpos = $curpos - 2 EndSwitch ;msgbox(0,"","Turn pause") ; for debugging, click every turn. WEnd ConsoleWrite("Maze completed in " & Round(TimerDiff($timed) / 1000, 1) & " seconds." & @CRLF) ; Show the generation time in seconds, rounded up with one decimal Return EndFunc Func open_maze($dest) ; Function set inputted cells to 'open' instead of being an uncool wall. $xy[$dest][4] = "o" GUICtrlSetData($xy[$dest][0], 'o') ; If you want debugging numbers, replace 'o' with $dest GUICtrlSetBkColor($xy[$dest][0], 0xEEEEEE) EndFunc Func direction(ByRef $curpos) ; Insert current position, output next heading for path generation. Local $nesw Local $open_directions[5][2] $open_directions[0][0] = 0 $nesw = $curpos - ($width * 2) ; north side checking If $nesw > $width + 1 Then fill_open_dir($nesw, 1, $open_directions) $nesw = $curpos + 2 ; east side checking If mod($nesw - 1, $width) <> 0 Then fill_open_dir($nesw, 2, $open_directions) $nesw = $curpos + ($width * 2) ; south side checking If $nesw < $grid_size - $width Then fill_open_dir($nesw, 3, $open_directions) $nesw = $curpos - 2 ; west side checking If mod($nesw, $width) <> 0 Then fill_open_dir($nesw, 4, $open_directions) ; Check which (if any) direction(s) are already opened, if so, discard them from the results-array For $i = $open_directions[0][0] To 1 Step -1 If $xy[$open_directions[$i][1]][4] = "o" Then $open_directions[0][0] -= 1 _ArrayDelete($open_directions, $i) EndIf Next ; If there are any results left... If $open_directions[0][0] > 0 Then If $open_directions[0][0] = 1 Then Return $open_directions[1][0] ; Random does not work with min 1 and max 1 (output = 0), so in this case, return only with the only one result. Else If $bt = 0 Then ; If there is not backtracking active, add this crossroad to the backtrack-array. This is only needed if there are two or three possible sides. $backtrack[0] += 1 _ArrayAdd($backtrack, $curpos) EndIf Return $open_directions[Random(1, $open_directions[0][0], 1)][0] ; Random choose between all possible directions and return with the outcome direction. EndIf ElseIf $backtrack[0] > 0 Then ; If there are no results ánd there are entries in the backtrack list, then visit those entries to see if there still is a path possible. $curpos = $backtrack[$backtrack[0]] _ArrayDelete($backtrack, $backtrack[0]) $backtrack[0] -= 1 $bt = 1 Return 0 ; Return with a new current direction ($curpos), from the backtrack array. Else Return -1 ; If there are no paths to explorer, in the pathing, or backtracking, then return with the message that we are finished. EndIf EndFunc Func fill_open_dir($nesw, $direction, ByRef $open_directions) ; Fill the $open_directions array with a new possible way $open_directions[0][0] += 1 $open_directions[$open_directions[0][0]][1] = $nesw $open_directions[$open_directions[0][0]][0] = $direction Return EndFunc P.S. The 'slow' generation is intended because it looks cool. Comment out the Sleep line on line 157 for a fast generation.
  4. It works I'll love to see a bot included in the game for single-player! I can see you've got the Function-thing sorted! I did not do that in my first script. First real thing you'd really have to improve on is your use of spaces, enters and lack of tabs. It looks so much cleaner when the structure is... structured. It's kind of a mess now, and I don't mean your code. Codes comes later when you learn. And maybe include an icon command, instead of borrowing it from an .exe that could not be there. Read about it here: https://www.autoitscript.com/forum/topic/82936-change-autoit-exe-icon/
  5. Could it be that the title or text changed in the mean time? I personally wouldn't love to use (but I did in my early AutoIt days, as you do) window titles for handle references. There is an API in AutoIt you can call to make sure you get the same window whatever happens: "#include <WinAPIProc.au3>" then use this "_WinAPI_EnumProcessWindows($PID)" function to get the windows handle to reference to. (it's in the help file!) In any case, if you use the above to get the handle, you don't even need to activate the windows Just use: ControlSend() (ControlSend() works in a similar way to Send() but it can send key strokes directly to a window/control, rather than just to the active window.) Good luck. Edit: I'm not really in AutoIt-shape anymore I guess... Could it be you send the keys to the window-itself, instead of the button?
  6. I understand the principle now at last, that principle is the important takeaway. My script/arrays is probably never going to be big enough to have to stay in RAM I think, but now I know that because of this thread I do think the test could be useful in my specific case, because I intend my script to reset the array and then run again when needed. So, thanks again for the confirmation and interesting material!
  7. Thanks for the test setup! It seems to gives a small advantage to the read of the variable. See the answer of jvanegmond for a probable cause. (I did move the setting of the variable before the timestart btw.) * I've cut out a lot of text in the quote because of saving space, and my answers/questions are directly related to the left over sentences. I absolutely did not skip anything. It may be an interesting question, but an even much more interesting explanation! Thank you for the trouble! If I understand the gist of it, a variable or an array with integers are both handled the same in that they reside in RAM and get moved for processing to the CPU caches if they are not too large. This means that the slice of CPU that processes the lot have the same amount of cycles needed to get either variable or array cell since they occupy the same cache environment. The only thing that could explain the 'slower' array speed in the example spudw2k made is the multiplying the CPU has to do to put the array in the cache in the format it needs. I'm 70% sure I've figured this out by dissecting your explanation. I understand the need for dumbing this down, I had to read this a few times over to process. Is the gist I wrote about correct?
  8. Hi all, I was pondering over a question with regards to the speeds of reading something and did not see this kind of question in a forum search. The question: What is (technically) faster? Multiple reads from the same 3d array cell, or only once make a 'temp' variable from that cell and read the value from this? I don't know if either has any real impact at all anyway, but just wanted to ask anyway. :-) There may be a difference if the value holds an integer or a string (or something else) but in my case, is a simple integer. To hopefully clarify with a small bit of code: $process = $start - 15 If $xy[$process][3] <> "x" Then If _ArraySearch($open, $process, 1, $open[0][0], 0, 0, 1, 1) <> -1 Then UpdateOpen($xy[$process][5], $closed[0][0]) ElseIf $start > 0 And _ArraySearch($closed, $process, 1, $closed[0][0], 0, 0, 1, 0) = -1 Then Add_open($start, $closed[0][0], $counter, $process) EndIf EndIf You can read from this, that the array $closed[0][0] is being read 3 times. And this goes on further in the code I did not show. My question boils down to this, should I make a 'temp' variable to hold that $closed[0][0] value until the function is done? It may not have a real impact on my small script, but I really am interested in the answer at least. Regards, Tri.
  9. I know this topic is _very_ old, but I am trying to use this fantastic path finding algorithm right now and it doesn't work anymore. I have tried to hack it to make it work, but my brain seems too limited to grasp the whole thing to fix it... There are two things: 1) I edited out the _ArrayCreate with: Local $var[1] = ["empty"] or things like: $closedList_Str = "" 2) It works great now, except when having multiple routes to the goal... With only one route, it does it well, but when I add two routes I get: "C:\Users\Admin\Desktop\test.au3" (253) : ==> Subscript used on non-accessible variable.: $closedList_Str &= $current_node[0] & "_" $closedList_Str &= $current_node^ ERROR Has anyone an updates version? There are not many (I could find none) other path finding scripts out there... Edit: Finally! Just before Newyear I found something which works! I added +1 to the $i. Somehow it pushed the goal coord as plain text in the wong place Func _Insert_PQ(ByRef $openlist, $node) ;Local $obj ;Unneeded For $i = 1 To UBound($openlist) - 1 Local $obj = $openlist[$i] If $node[2] < $obj[2] Then _ArrayInsert($openlist, $i + 1, $node) Return EndIf Next _Add_List($openlist, $node) EndFunc ;==>_Insert_PQ
  10. Hey mate, I could type a full page of information, but it is easier to just read the AutoIt help file. In SciTE (the editor) press F1. In the help go to: Auto It -> GUI Reference -> GUI MessageLoop Mode. I find it the most easy way to make it work.
  11. Odd, and if you use _ instead of spaces in the shortcut? (just to try things out)
  12. If you don't mind using other people's code instead of inventing your own:
  13. Know the feeling In the AutoIt help file FileCopy is done with a trailing slash in the destination path. Try that please.
  14. Just to save a lot of time: why not via Group Policies?
  15. Sounds like you need a combination between array's and the random() function. Edit: Didn't read the post well... But post an example first! We won't help otherwise. I know you haven't said anything in the likes of bots and game automatisation, but this script sure sounds like that. In that case, read this! http://www.autoitscript.com/forum/forum-2/announcement-12-game-bots-and-automation/
  16. Two things: 1) The script isn't working on my computer. That is to be expected since it excludes files I don't have. Not that I want them, but it would be easier if you'd remove or replace them in you example 2) I am a little unclear on what the second problem is. Could you state them per problem? Could it be the programs you run after eachother be the source of the script seeming slow?
  17. If you really searched the forum you would've come across: Then click the link in the second post. Next time, please show something you typed and tried yourself before asking!
  18. Try this site: http://www.appdeploy.com/ If your application isn't in there, they have a lot of tips as well for different types of installations.
  19. Search the help for "FileFindFirstFile" and, well, program your search to look wherever you want. Ow, and no, it's not recursive. (as far as I know) Another method, I cannot help with, is to do a search in the Windows DOS box and capture the output. Then use regular expressions to look for the location.
  20. I would just simply bind the x-key to set the flag to 1 when pressed and then use If $interrupt_flag = 1 Then Exit in the begin of every function (or ExitLoop or something) Edit: typo
  21. You could read a text file and StringSplit it. Then use the output array in a loop to check against. Edit: I had time to waste If check_symbol() = True Then msgBox(48, "Yay", "It's true!") EndIf Func check_symbol($input) If $input = "" Then Return False ; simple error check $outcome = "" $symbol_file = ;<open text file with read access here> $symbols = StringSplit($symbol_file, ",") For $i = 1 To $symbols[0] ; or add +1 after [0] of count isn't correct If $input = $symbols[$i] Then Return True Next FileClose($symbol_file) ;<close text file read access> If $outcome = "" Return False EndFunc Didn't run it because it's NOT complete! May contain some errors, this is just a little something to help.
  22. Ice, Ice baby! Anyway, search is your friend. It's not the UDF you quoted, but it give's an idea.
  23. We usually don't code out of nothing for anyone. Please make an coding of our own and try it first. If you hit a wall, then come here and ask for help. Step 1) Open the AutoIt editor (SciTE) Step 2) Press F1 to open help Step 3) Read help Step 4) Code your own script Step 5) Run script and be happy Step 6) ... Step 7) Make money
  24. I don't know exacly what you want, but try this: $white = 16777215 ; 15791353 $ch = 16711680 $ch2 = 16646144 While 1 $color = PixelGetColor(@DesktopWidth / 2, @DesktopHeight / 2) ; Yes, this could be out of the loop, but I kept it in here in case the resolution changes. $b8 = PixelGetColor(1087,820) If $b8 = $white Then Sleep(500) if $color = $ch or $ch2 Then MouseClick("left") Send("{LALT}") Sleep(30) Send("{O}") Sleep(270) ExitLoop EndIf ElseIf $color = $ch Or $color = $ch2 Then Sleep(500) If $color = $ch or $ch2 Then Mouseclick("left") Send("{LALT}") Sleep(30) Send("{P}") Sleep(590) ExitLoop EndIf EndIf Sleep(100) WEnd Exit Note!! The colour's you use are not the real colour codes. For example: 15791353 is NOT white. My script above got the right white code. I don't know what other colour's you'd like to use, so I can't correct them if needed. I also added an ExitLoop statement so that the script will exit when the colour is detected and the menubuttons are pushed. Get rid of that line if you want the script to loop or do another action. Edit: Mod's sorry if I disturbed the force... according to:
  25. The script works fine here.. Edit: excel 2010 x64 and AutoIt v3.3.6.1
×
×
  • Create New...