Jump to content

cycling arrays in the same script


bald1
 Share

Recommended Posts

Hey ppl :D

FIrst off ill start by introducing myself. Im completely new to autoit and the world of writing code and scripts, and I must say, ive been sucked into this world of absolute statements and variables quite quickly. I've been lurking these forums for some time now, looking for inspiration and help.

I, as many before me, got attracted to the world of automated actions in the shadow of a MMO. Even tho it seems fairly easy to make a basic bot that can do a wide variety of hunting and farming, ive decided against that and decided to go with something less offensive and more useful to the common player: A tradeskilling automation. Bear in mind that in my MMO (AO) u cannot gain credit or exp by tradeskilling. It's just a long and boring process that from the views of a "new-age" mmo gamer would seem a broken game mechanic.

So, i been writing on it for some time now, and i actually only need one crucial bit to finish it. Is there a way to cycle or swap arrays ?

I need to feed my code 3 sets of variables for each data input. I decided to use arrays for simplicity sake for these 3 variables. I use pixelsearch to locate the items in inv, and the 3 variables i use to ensure that i get the right item. So 3 times not @error means i got the right item. I feed pixelsearch with my array as such: $item1[0] = 0xsomecolorcode, $items1[1] = 0xsomecolorcode and $items1[2] = 0xsomecolorcode... Now i need to do this with all my arrays of $items in order for my script to figure out where and if all items are present to complete a given tradeskilling process. How do i easiet go about doing this task? _ArraySwap seems to only swap the information contained within one array..

I know there's some super easy way to this, but i just cant seem to locate it, and judging from all the other questions posed in this forum, this one strikes me as dumb ><

I can post the code if what im asking is too unclear, but im not at tmy staionary at this moment :D

Thanks in advance!

Link to comment
Share on other sites

A unique feature is to create an entire copy of a array like this:

#include <Array.au3>

Dim $a[2] = [1, 2]
Dim $b[2] = [3, 4]

_SwapEntireArray($a, $b)

_ArrayDisplay($a)
_ArrayDisplay($b)


Func _SwapEntireArray(ByRef $aArray1, ByRef $aArray2)
   Dim $aCopy = $aArray1
   $aArray1 = $aArray2
   $aArray2 = $aCopy
EndFunc

:D At times like this I love AutoIt intensely.

Link to comment
Share on other sites

A unique feature is to create an entire copy of a array like this:

#include <Array.au3>

Dim $a[2] = [1, 2]
Dim $b[2] = [3, 4]

_SwapEntireArray($a, $b)

_ArrayDisplay($a)
_ArrayDisplay($b)


Func _SwapEntireArray(ByRef $aArray1, ByRef $aArray2)
   Dim $aCopy = $aArray1
   $aArray1 = $aArray2
   $aArray2 = $aCopy
EndFunc

:D At times like this I love AutoIt intensely.

This looks fairly easy, thanks!

Omikron, could u elaborate on that? I'm always open to learn alternative routes and ways to go about things :D

While i have your attention im gonna throw a bonus noob question in there for ya; I noticed you/Manadar used the "Dim" scope to declare your variables. Could u explain in few words the difference between the 3 scopes? As i've read several times that global and local should be the the scopes used, but i guess this is not true for scripts made to run besides games?

thanks!

Link to comment
Share on other sites

I use Dim because I'm an oldie, but we should both use Local or Global scope.

Explanation of the three scopes:

- Dim scope uses the local scope, unless the variable was previously declared in the Global scope.

- Local scope is simple. It's local and can only be used in the current scope and other scopes that exist in the current scope.

- Global scope can be used anywhere in your script (same as a local being declared on the root scope), but global can be declared anywhere in your script.

Local example (as with many other programming languages):

_foo()
MsgBox(0, "", $bar) ; errors out

Func _foo()
   Local $bar = 3
EndFunc

Global example (uncommon):

_foo()
MsgBox(0, "", $bar) ; shows 3

Func _foo()
   Global $bar = 3
EndFunc
Link to comment
Share on other sites

It's been a few busy days, and so i've just gotten around to look at this now and i can't quite seem to get it working :D

is there a chance that u or anyone could expand on that swap example?

#include <Array.au3>

Dim $a[2] = [1, 2]
Dim $b[2] = [3, 4]

_SwapEntireArray($a, $b)

_ArrayDisplay($a)
_ArrayDisplay($b)


Func _SwapEntireArray(ByRef $aArray1, ByRef $aArray2)
   Dim $aCopy = $aArray1
   $aArray1 = $aArray2
   $aArray2 = $aCopy
EndFunc

This is the code, and i see how this works for swapping between two arrays, but what if i wanna cycle down a line of arrays like these:

global Const $aItem01[3] = [0x5995EC, 0xE2FEFF, 0x415769]

global Const $aItem02[3] = [0xDBD194, 0x6EB7F0, 0x252723]

global Const $aItem03[3] = [0xA64542, 0xFEECD3, 0xB45B55]

global Const $aItem04[3] = [0xA95A5D, 0xFE7C84, 0xFFBCD3] (and many more)

Bear with this noob :/

Link to comment
Share on other sites

You should make a two dimensional array.

global Const $aItem[$n][3]
global Const $aItem[0][3] = [0x5995EC, 0xE2FEFF, 0x415769]
global Const $aItem[1][3] = [0xDBD194, 0x6EB7F0, 0x252723]
global Const $aItem[2][3] = [0xA64542, 0xFEECD3, 0xB45B55]
global Const $aItem[3][3] = [0xA95A5D, 0xFE7C84, 0xFFBCD3] (and many more)

For $i = 0 To $n - 1
    For $j = 0 To 2
        PixelSearch( 0, 0, 20, 300, $aItem[$i][$j])
        If @error Then ExitLoop
    Next
Next

Not sure if the declaration is allowed since I've never tried declaring a constant array, but you should get the idea.

Edited by omikron48
Link to comment
Share on other sites

Currently at work, so ill check it out when i get home some time. However, if ya happen to know an "advanced" tutorial for autoit, i'd be happy to read it (while im at work anyway :D). I went through the basic thingy, which mentions two dimensional arrays, but said it had no place in a basic tutorial, and therefor i know nothing about it.

Thanks for your reply!

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