Home Technical Talk

Array of IMGTAGs - How to sort, find and delete items?

polycounter lvl 14
Offline / Send Message
miauu polycounter lvl 14
How to store items in array of IMGTAGs, so I can sort, find ana delete items in this array?

First i define the bitmaps:

bm_blue = bitmap 4 50 color:blue
bm_white = bitmap 4 50 color:white

then the ImgTags and the array:

imgtag b1 "imgtag" bitmap:bm_white
imgtag b2 "imgtag" bitmap:bm_white
imgtag b3 "imgtag" bitmap:bm_white
imgtag b4 "imgtag" bitmap:bm_white

arrImgTag = #() as array


Starts collecting data in arrImgTag:

append arrImgTag b2
append arrImgTag b4
append arrImgTag b1
append arrImgTag b5
append arrImgTag b3

If I want to change the color of ImgTags I use this code:

for i = 1 to arrImgTag.count do
arrImgTag.bitmap = bm_blue


and it works

But, if I want to sort or find item in arrImgTag - the problem appears

sort arrImgTag
Error: -- No "">"" function for ImgTag:b3

findItem arrImgTag <what to type here>

because non of this is work:
findItem arrImgTag ImgTag:b3
findItem arrImgTag (ImgTag:b3)
findItem arrImgTag (b3
)

If I use findItem arrImgTag 2
the answer of maxlistener is always 0.

When I print arrImgTag, maxListener shows this:

#(ImgTag:b2, ImgTag:b4, ImgTag:b1, ImgTag:b5, ImgTag:b3)

I can use only

deleteitem arrImgTag 2
but this will delete the second item in array, but I want to delete "ImgTag:b2", not "ImgTag:b4"

How to store data in arrImgTag, so later I can sort the array, find and delete specific items, and change color of all ImgTag with code like this

for i = 1 to arrImgTag.count do
arrImgTag.bitmap = bm_blue

P.S. Sory for my bad english

Replies

  • SyncViewS
    Options
    Offline / Send Message
    SyncViewS polycounter lvl 13
    Hi, if I get it right you're looking for the imgTag name. FindItem looks for the elements not their properties. You need to write a custom function to do that, which runs through the whole image tag array. Here is a working code sample.
    rollout rolTest "test"
    (
        local bm_blue = bitmap 4 50 color:blue
        local bm_white = bitmap 4 50 color:white
    
        imgtag b1 "imgtag" bitmap:bm_white
        imgtag b2 "imgtag" bitmap:bm_white
        imgtag b3 "imgtag" bitmap:bm_white
        imgtag b4 "imgtag" bitmap:bm_white
        imgtag b5 "imgtag" bitmap:bm_white
    
        -- function to find first match in the ImageTag array
        -- runs through the whole array in reverse to avoid using
        -- the very slow "exit" command
        function findImgItem aImgTag sTagToFind =
        (
            local iIndexFound = 0
            for i = aImgTag.count to 1 by -1 \
                where (aImgTag[i].name == sTagToFind) do ( iIndexFound = i )
    
            return iIndexFound
        )
    
        function runTheTest =
        (
            local arrImgTag = #()
    
            append arrImgTag b2
            append arrImgTag b4
            append arrImgTag b1
            append arrImgTag b5
            append arrImgTag b1
            append arrImgTag b3
    
            format "Image \"b1\" is in position %\n" (findImgItem arrImgTag "b1")
        )
    )
    
    rolTest.runThetest()
    
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    SyncViewS, Thank you very much. :)
Sign In or Register to comment.