Jump to content
UBot Underground

[Guide] Duplicate Single List Item Many Times


Recommended Posts

As a non-programmer and Ubot newbie (1 week) this is my first attempt at a 'guide' so please be gentle...

-------------------

 

I've been trying to build a bot to do some tasks for me and I needed to duplicate a single list item to create a final list that was the same length as another list I have. Sending the item to a table repeatedly seemed to take quite some time, so I came up with an alternate solution that, in my case, dramatically reduced the time to process the data.

 

The script takes the desired final list size (#x) and begins dividing the number by 2 (#y) and counting (#count) until the result is less than 2. This count is then used to add the list item to the given list (%k2) and then add %k2 to itself #count times. The list is stored in %ktemp while the loop is run against the remainder of the list (#left), repeating, until #y is < 2. The list item is added to the list a final time. The final list is stored in %k.

 

For my purposes, I actually had to loop THIS script because I had a list of items that needed to expanded and then add upon each other. Using this script instead of the 'add to table' method on a list size of around 11k, the data is processed in less than a second.

 

Thanks!

 

define addList {
    set(#left, 99, "Global")
    set(#count, 0, "Global")
    set(#z#totalGRow"Global")
    set(#x#z"Global")
    set(#y#z"Global")
    clear list(%k2)
    loop while($comparison(#left"!=", 1)) {
        loop while($comparison(#y">", 2)) {
            set(#y$divide(#x, 2), "Global")
            set(#x#y"Global")
            increment(#count)
            }
        set(#counter, 1, "Global")
        loop($add(#count, 1)) {
            if($comparison(#counter"=", 1)) {
                then {
                    add item to list(%k2$table cell(&kFile#rowTable, 0), "Don\'t Delete""Global")
                    increment(#counter)
                }
                else {
                    add list to list(%k2%k2"Don\'t Delete""Global")
                }
            }
        }
        add list to list(%kTemp%k2"Don\'t Delete""Global")
        set(#left$subtract(#z$list total(%kTemp)), "Global")
        set(#count, 0, "Global")
        set(#x#left"Global")
        set(#y, 99, "Global")
        clear list(%k2)
    }
    add item to list(%kTemp$table cell(&kFile#rowTable, 0), "Don\'t Delete""Global")
    add list to list(%k%kTemp"Don\'t Delete""Global")
    clear list(%k2)
    clear list(%kTemp)
}

  • Like 1
Link to post
Share on other sites

That is awesome you stuck with it and solved your problem!!

Now refactor it and make it less code and simplified.

 

Homer above gave you a hint...

but if I understood what u are doing I'd show u in code.

 

But great job and thanks for sharing!

 

CD

Link to post
Share on other sites

here is a couple ways to repeat

 

comment("one way")
clear list(%a)
add list to list(%a,$list from text($repeat text("repeat,",100),","),"Don\'t Delete","Global")
 

 

comment("another way")
loop(100) {
    add item to list(%b,"repeat2","Don\'t Delete","Global")
}

 

notice "don't delete"

 

it is in advance of the node
press advance inside add list to list and u will see it

 

this makes it so u can have duplicates in a list

 

Now what?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...