Jump to content
Sign in to follow this  
Sc1

Array Problem

Recommended Posts

Sc1

Hey, I just started looking into AutoIt and I can't seem to get this right. Could someone please tell me why the below script returns an error of ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$var[1] = $pos[1] + 10

^ ERROR

CODE
#include <Array.au3>

_Main()

Func _Main()

Local $pos = MouseGetPos()

Local $var[1]

$var[0] = $pos[0] + 10

$var[1] = $pos[1] + 10

$var[2] = $pos[2] + 10

$var[3] = $pos[3] + 10

While 1

_MouseTrap($var[0], $var[1], $var[0] + $var [2], $var[1] + $var[3])

sleep ( 10000 )

WEnd

_MouseTrap()

Exit

EndFunc

I also tried the below variation and added the arrays later but that didn't work either. The one below returns an error of:

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

_ArrayAdd($var, $pos[2] + 10)

_ArrayAdd($var, ^ ERROR

CODE
#include <Array.au3>

_Main()

Func _Main()

Local $pos = MouseGetPos()

Local $var[1]

$var[0] = $pos[0] + 10

_ArrayAdd($var, $pos[1] + 10)

_ArrayAdd($var, $pos[2] + 10)

_ArrayAdd($var, $pos[3] + 10)

While 1

_MouseTrap($var[0], $var[1], $var[0] + $var [2], $var[1] + $var[3])

sleep ( 10000 )

WEnd

_MouseTrap()

Exit

EndFunc

Thanks for your help.

Share this post


Link to post
Share on other sites
Xantioss

CODE

#include <Array.au3>

_Main()

Func _Main()

Local $pos = MouseGetPos()

Local $var[4]

$var[0] = $pos[0] + 10

$var[1] = $pos[1] + 10

$var[2] = $pos[2] + 10

$var[3] = $pos[3] + 10

While 1

_MouseTrap($var[0], $var[1], $var[0] + $var [2], $var[1] + $var[3])

sleep ( 10000 )

WEnd

_MouseTrap()

Exit

EndFunc

This schould do the trick?

Share this post


Link to post
Share on other sites
Sc1

I realized after I posted that I was meant to change that to a 4, but it hasn't changed anything. Still erroring.

Share this post


Link to post
Share on other sites
Xantioss

I realized after I posted that I was meant to change that to a 4, but it hasn't changed anything. Still erroring.

ah,you forget a include :P

#include <Array.au3>
#Include <Misc.au3>

_Main()

Func _Main()
Local $pos = MouseGetPos()
Local $var[4]

$var[0] = $pos[0] + 10
$var[1] = $pos[1] + 10
$var[2] = $pos[2] + 10
$var[3] = $pos[3] + 10

While 1
_MouseTrap($var[0], $var[1], $var[0] + $var [2], $var[1] + $var[3])
sleep ( 10000 )
WEnd
_MouseTrap()
Exit
EndFunc

this schould work :)

edit: one litle thingy,the MouseGetPos only returns 2 arguments :P so have a look at the help file :D

Edited by Xantioss

Share this post


Link to post
Share on other sites
Xantioss

#include <Array.au3>
#Include <Misc.au3>

_Main()

Func _Main()
Local $pos = MouseGetPos()
Local $var[4]

$var[0] = $pos[0] + 10
$var[1] = $pos[1] + 10
$var[2] = $pos[0] + 10
$var[3] = $pos[1] + 10

While 1
_MouseTrap($var[0], $var[1], $var[0] + $var [2], $var[1] + $var[3])
sleep ( 10000 )
WEnd
_MouseTrap()
Exit
EndFunc

try this :)

i think this is your goal?

Share this post


Link to post
Share on other sites
Sc1

Didn't know that MouseGetPos only returned 2 arguements so that would be a problem.

It creates the box to trap the mouse in, however I would like to it wait for 10 seconds (sleep ( 10000 )), and then evaluate the mouse position and set another box. How would I get it to do that since they removed Gotos.

Share this post


Link to post
Share on other sites
Xantioss

Didn't know that MouseGetPos only returned 2 arguements so that would be a problem.

It creates the box to trap the mouse in, however I would like to it wait for 10 seconds (sleep ( 10000 )), and then evaluate the mouse position and set another box. How would I get it to do that since they removed Gotos.

uh,you could do that by checking the position of the mouse by mousegetpos() and evaluate it with something like

if $pos[0] < 200 and $pos[1] > 200 then 
    mousetrap()
endif

that might be usefull?

Share this post


Link to post
Share on other sites
Sc1

It is helpful but not really what i'm lookin for. I want more of a

CODE
MouseGetPos()

While 1

_MouseTrap($var[0], $var[1], $var[0] + $var [2], $var[1] + $var[3])

Wend

sleep ( 10000 )

Goto While 1

So that after creatin the MouseTrap, it waits for a little while, then evaluates where the mouse is now, then creates another box around it.

Share this post


Link to post
Share on other sites
Sc1

I tried putting a While loop in a while loop, but my knowledge is limited and it doesn't seem to be working =\

CODE
While 1

While 2

_MouseTrap($var[0], $var[1], $var[0] + $var [2], $var[1] + $var[3])

sleep ( 5000 )

WEnd

sleep ( 5000 )

WEnd

Share this post


Link to post
Share on other sites
SxyfrG

Didn't know that MouseGetPos only returned 2 arguements so that would be a problem.

It creates the box to trap the mouse in, however I would like to it wait for 10 seconds (sleep ( 10000 )), and then evaluate the mouse position and set another box. How would I get it to do that since they removed Gotos.

#include <Misc.au3>

$Pos = MouseGetPos()
_MouseTrap($Pos[0]-50, $Pos[1]-50, $Pos[0]+50, $Pos[1]+50)

While 1
    Sleep(10000)
    $NewPos = MouseGetPos()
    If ... Then;add your conditional statements here, i.e. If $NewPos[0] < $Pos[0] And $NewPos[1] > $Pos[1] Then ...
;It'd be best to split up the conditional statements so that 4 quadrants in the virtual square you have created 
;are checked to see if the mouse is in there, then change the boundary accordingly.
    ElseIf ... Then
;More Code
    EndIf
WEnd

That should help you :)

*EDIT*

Instead of goto, you must call a function.

For example

If 1 = 1 Then
      _My1Equals1Function() ;Call the '_My1Equals1Function'.
EndIf
Edited by SxyfrG

My scripts:AppLauncherTRAY - Awesome app launcher that runs from the system tray NEW VERSION! | Run Length Encoding - VERY simple compression in pure autoit | Simple Minesweeper Game - Fun little game :)My website

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  

×