Jump to content

Why does this basic script not work right


Recommended Posts

ok i got it working sorta its very weird but hard to explain how, lemme know if theres anything wrong or something i can change to make it faster.

HotKeySet("{PAUSE}", "Pause" )
HotKeySet("{f1}", "Driver" )
HotKeySet("{f2}", "Iron" )
;HotKeySet("{f3}", "PDriver" )
HotKeySet("{f5}", "Quit" )

Func Pause()
exit
endfunc

Opt("SendKeyDelay", "1")
AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("PixelCoordMode", 0)

sleep(3000)

While 1
sleep(1)
Wend

Func Driver()
While 1
If PixelGetColor(370, 702) = 10790050 then
Send("{space}")
sleep(200)
endif
Wend
EndFunc

Func PDriver()                                           ----------
While 1                                                                
If PixelGetColor(370, 702) = 10790050 then
Send("{space}")                                                   
sleep(200)                                                             
PDriver2()                                                             
endif
Wend                                                                       
EndFunc                                                                                
                                                                                               
Func PDriver2()                                                                     
While 1                                                                   I cant get these to func to work together right             
If PixelGetColor(631, 702) = 10790050 then                            
Send("{space}")                                                                
sleep(200)                                                            
PDriver()                                                              
endif                                                                     
EndFunc                                                 -----------

It would also work if it ran the 2 funcs together (Pdriver and Pdriver2) off of the F3 key but i didnt know how to do that. The most important thing is that it checks the pixel very fast.

if u need me to explain something just ask me

Edited by kevilay
Link to comment
Share on other sites

Well, HotKeySet intecepts the specified key, interrupts the current script and runs the function you defined. Now, with your script, this will be a problem, as your functions Driver, PDriver, etc. will never end (due to the While 1). So, your program starts. You press F1, and Driver will be called and runs forever!! Now, you press F3 and Driver will be interrupted and PDriver will be called. PDriver itself calls PDriver2, which again calls PDriver or run forever doing nothing (due to while 1)

You will have to restructure your whole desgin, to get this working.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Well, HotKeySet intecepts the specified key, interrupts the current script and runs the  function you defined. Now, with your script, this will be a problem, as your functions Driver, PDriver, etc. will never end (due to the While 1). So, your program starts. You press F1, and Driver will be called and runs forever!! Now, you press F3 and Driver will be interrupted and PDriver will be called. PDriver itself calls PDriver2, which again calls PDriver or run forever doing nothing (due to while 1)

You will have to restructure your whole desgin, to get this working.

Cheers

Kurt

<{POST_SNAPBACK}>

thats what f5 is for so when i want them to stop it restarts script

Edit: theres probally a better way of formatting this script but i have no idea how im new think you could help me out?

Edited by kevilay
Link to comment
Share on other sites

well if that wend didnt help (which is about the most of my programming skill) then i dont know.  where is the quit function?

<{POST_SNAPBACK}>

it got cutoff oops lol

its at very bottem of script

Func Quit()
Run("Golf Perf")
Exit
EndFunc
Edited by kevilay
Link to comment
Share on other sites

thats what f5 is for so when i want them to stop it restarts script

There is not Quit function in your script. And even if it was there, it would not help. How are you going to restart the script automatically?

EDIT: Forget this. I was typing while you submitted your last post.

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

There is not Quit function in your script. And even if it was there, it would not help. How are you going to restart the script automatically?

EDIT: Forget this. I was typing while you submitted your last post.

Cheers

Kurt

<{POST_SNAPBACK}>

then how can i do sumthing :( ?
Link to comment
Share on other sites

Edit: theres probally a better way of formatting this script but i have no idea how im new think you could help me out?

maybe you should explain what you would like to achieve!??! Based on the code I can only say there is something wrong. Without any further information I cannot say how to do it right....

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

maybe you should explain what you would like to achieve!??! Based on the code I can only say there is something wrong. Without any further information I cannot say how to do it right....

Cheers

Kurt

<{POST_SNAPBACK}>

ok its for a golf game. What happens is this is used for achieving a perfect shot.

For the Driver functions i hit space to start drive bar fills up and i stop it at what ever % power i want. Then it comes back down and you stop it at 0% again for a *perfect* accuracy shot.

Its like how hotshotsgolf is if u ever played it.

For the PDrive funcs i hit space bar and its supposed to stop it when it reaches 100% instead of me doing it, then when it comes back down stop it at 0% like before.

If u dont understand let me know i can try rephrasing it or sumthing

Edit: an attempted expample

0% <----> 100%

l l l l l l l l l l l

that would represent the bar it first filles to the right then i stop it and it goes back to the left

0% <----> 100%

llllllllllllllllllllllllllllllllllllllllllllllllllllll l

------------------------------>

0% <----> 100%

llllllllllllllllllllllllllllllllllllllllllllllllllllll l

<------------------------------

Edited by kevilay
Link to comment
Share on other sites

here is the problem

PDriver()                                                             
endif

your calling that function from an infinite loop.

and the function you call (PDriver) is also an infinite loop.

maybe your computer is freezing up...

try adding exitloop or use a different type of loop statement.

your script is not "continuing" its stuck in a loop. 2 loops.. heh

you know what? give me 5 minutes.... ill fix it

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

HotKeySet("{PAUSE}", "Pause" )
HotKeySet("{f1}", "Driver" )
HotKeySet("{f2}", "Iron" )
HotKeySet("{f5}", "Quit" )

splashtexton("golfprov1.1","press the pause key to pause" & @crlf &_
"press f1 for driver" & @crlf & "press f2 for iron" & @crlf &_
 "press f5 to quit",300,100,300,0)



Opt("SendKeyDelay", "1")
AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("PixelCoordMode", 0)

sleep(3000)

While 1
Wend

Func Driver()
for $x = 1 to 1
If PixelGetColor(370, 702) = 10790050 then
Send("{space}")
sleep(200)
endif
next
EndFunc

Func PDriver() 
for $x = 1 to 1                                                              
If PixelGetColor(370, 702) = 10790050 then
Send("{space}")                                                   
sleep(200)                                                            
PDriver2()                                                            
endif
next                                                                    
EndFunc                                                                               
                                                                                              
Func PDriver2()                                                                     
for $x = 1 to 1    
If PixelGetColor(631, 702) = 10790050 then                            
Send("{space}")                                                               
sleep(200)                                                            
PDriver()                                                             
endif 
next                                                                     
EndFunc 

func pause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

func quit()
exit
endfunc

i didnt even try to run this code yet..., but it looks fine.

as you can see, it looks as if you didnt post the whole code.

just do like i did, with the rest of your code. you should be fine.

also, if you want to run these together....

Func PDriver()
for $x = 1 to 1                                                             
If PixelGetColor(370, 702) = 10790050 then
Send("{space}")                                                   
sleep(200)                                                            
PDriver2()                                                            
endif
next                                                                    
EndFunc                                                                               
                                                                                              
Func PDriver2()                                                                     
for $x = 1 to 1   
If PixelGetColor(631, 702) = 10790050 then                            
Send("{space}")                                                               
sleep(200)                                                            
PDriver()                                                             
endif
next                                                                    
EndFunc

why not...

Func PDriver()                                                            
If PixelGetColor(370, 702) = 10790050 then
Send("{space}")                                                   
sleep(200)                                                            
endif                                                                                              
If PixelGetColor(631, 702) = 10790050 then                            
Send("{space}")                                                               
sleep(200)                                                            
PDriver()                                                             
endif                                                                
EndFunc
Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

For the Driver functions i hit space to start drive bar fills up and i stop it at what ever % power i want. Then it comes back down and you stop it at 0% again for a *perfect* accuracy shot.

O.K. Did I get you right? The color you are checking is the "empty bar" color. As long as the color is, lets say "white", you send a SPACE. If thats true, then the following might solve the problem. Same for the other functions.

Func Driver()
While 1
   If PixelGetColor(370, 702) = 10790050 then
       Send("{space}")
       sleep(200)
   else ; <=== Changed this !!
       return
   endif
Wend
EndFunc

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

ok i used the script toddie but there is no hotkey for PDriver() so ill just make it f3 also it gave error on pause about variable declaration

edit: found huge error go to page two of this topic

Edited by kevilay
Link to comment
Share on other sites

ok i got a problem.

Func Driver()

for $x = 1 to 2

If PixelGetColor(370, 702) = 10790050 then

Send("{space}")

sleep(200)

endif

next

EndFunc

i need to to hit it twice because once to start then i hit space at w/e% then it comes back down to 0% again

EDIT: found huge error, i just notice while i have it on while1 wend because it has to check over and over for the pixel, because it moves back and forth. you have it checking at a particular instant. know what i mean?

Edited by kevilay
Link to comment
Share on other sites

hotkeyset("f6","start")
hotkeyset("f7","stop")

global $var
$var = 0

while 1
if $var = 1 then
_driver
endif
wend


func start()
$var = 1
endfunc

func stop()
$var = 0
endfunc

theres a few different ways you could loop it. heres just one example.

i just edited it, but i had 2 while loops nested. now i have an if loop nested in a while loop. if you want to use one key to start/stop instead of 2, then use the pause function, and while paused... _driver. while not paused... do nothing. get it?

should get you by.

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...