Jump to content
Sign in to follow this  
Scriptie

Variable ain't declared? code ain't working, why?

Recommended Posts

Scriptie

Hello, I been using AutoIT for several years ago, got some basic knowledge in the basic programming.

I just want this code to work, the mouse is going to click 10 times, each time will be a minus 35 pixels on width.

To do this, my code is this:

sleep(5000)

reset()

Func reset()
$startX = 857
$startY = 675
$count = 0
start1()
EndFunc

start1()
Func start1()
If $count =< 10 Then
Mouseclick("left",$startX,$startY)
$startX = $startX - 35
$count = $count + 1
start1()
Else

Exit

EndIf
EndFunc

I don't understand what the fault is?

At first I put a sleep.

Then I tell it to go to reset function, right?

In reset function I reclare my variables. It end the function with going to the start1 function, where it simply just watches so the count is 10 or smaller, and if it is, it will click on a location. After that it will minus the width with 35 px, and the count will make an addition of 1.

Then it will loop this, until it's up on 11 at count, at that time it will exit the script.

So, what is really wrong here? I even tried to put the variables on top of the sleep but nothing really happends then.

Thanks in advance.

Edited by Scriptie

Share this post


Link to post
Share on other sites
FireFox

Hi,

The variables declared in your reset function are Local (without declaration scope).

Either declare them in the global scope or add Global before them in the function (but in the last case be sure that you call the reset function first).

And secondly, it's <= and not =<.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
mikell

Why don't you use a For/Next loop ?

Global $startX, $startY

reset()
start1()

Func reset()
   $startX = 857
   $startY = 675
EndFunc

Func start1()
   For $i = 0 to 10
      $startX -= $i*35
      Mouseclick("left", $startX, $startY)
      Sleep(100)
   Next
EndFunc

Share this post


Link to post
Share on other sites
TechCoder

Like any new adventure, the LAST thing you should do is 'sleep'!  (think of visiting a new place, new city, new country!)

First thing you would want to do is 'look around' a bit and see what might be 'interesting' - if nothing else, at least set some bearings and/or 'rules'..........

So, what 

mikell

suggested is quite valid - first, set up some 'rules' (i.e., parameters) and THEN do some 'looking around' - in this case, check out "from 1 to 10" - and, possibly, then (maybe even AS you are counting, if it makes sense...) do some 'sleep'

but, IMHO, a program should NEVER begin with SLEEP!

Share this post


Link to post
Share on other sites
mikell

 

but, IMHO, a program should NEVER begin with SLEEP!

This can be useful sometimes, for instance when the program 'starts with Windows' and you want to delay a little its execution

Share this post


Link to post
Share on other sites
TechCoder

Granted, waiting for Windows to start is a great example of 'a good time to have a long sleep'.........   :ermm:

However, instead of sleep(), I would rather consider alternatives like WinWait - i.e., watch some 'trigger'.  

You might use a sleep(x) (some small number) in a loop if that is what you need (for instance, you require Internet to be active, so do a "While $not_connected" or something), I just prefer to be more pro-active and look for the event, not just sleep() as a first command.

But, that is why there are many options in the code - each person has their own preference - none 'wrong', just different ways of looking at things.

Share this post


Link to post
Share on other sites
BrewManNH

I rewrote a tool that when it was updated needed to be restarted. It also used _Singleton because it wouldn't work if there were more than one instance running. Occasionally when you exited the first instance it would restart before the first instance had time to shutdown completely. I put a small sleep at the start of the script so that the first instance would be sure to be closed by the time the _Singleton function was accessed. It may have been hacky to do it that way, but it works and it works well.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
mikell

TechCoder,

The only reason I can see why you should put a heading loop instead of a Sleep is when you are in a hurry and want your program to start as soon as possible

Otherwise I don't understand why using Sleep in such conditions would be a bad practice :blink:

Share this post


Link to post
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
Sign in to follow this  

×