Jump to content

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


Recommended Posts

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

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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:

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...