Thread

From UBot Studio
Jump to: navigation, search

This command is a Flow Command. This command runs the contained commands in a separate thread from the main script allowing multiple commands to run at the same time. (Professional and Developer Editions Only)


Contents

Example 1

thread {
    in new browser {
        navigate("http://www.google.com", "Wait")
        wait(3)
    }
}
navigate("http://www.bing.com", "Wait")


Running the script will open a new browser window and navigate to google, while simultaneously navigating to bing in the main browser.

The thread command makes the simultaneous running of each command possible.


Thread.jpg



Example 2

This example demonstrates how multiple tasks can be run in different windows within UBot Studio.

Place this define command in a separate tab. The define simply clears the lists within it whenever its command is run.

define clear lists {
    clear list(%ha)
    clear list(%ho)
    clear list(%hee)
    clear list(%har)
}


In a separate tab, the loop commands for each list being displayed in the browser is placed within a thread command.


clear lists()
thread {
    loop(5) {
        add item to list(%ha, "ha", "Don\'t Delete", "Global")
        load html($text from list(%ha, "<br />"))
        wait($rand(1, 3))
    }
}
thread {
    in new browser {
        loop(5) {
            add item to list(%ho, "ho", "Don\'t Delete", "Global")
            load html($text from list(%ho, "<br />"))
            wait($rand(1, 3))
        }
    }
}
thread {
    in new browser {
        loop(5) {
            add item to list(%hee, "hee", "Don\'t Delete", "Global")
            load html($text from list(%hee, "<br />"))
            wait($rand(1, 3))
        }
    }
}
thread {
    in new browser {
        loop(5) {
            add item to list(%har, "har", "Don\'t Delete", "Global")
            load html($text from list(%har, "<br />"))
            wait($rand(1, 3))
        }
    }
}


When the script is run, notice that multiple windows open, and each list displays its items simultaneously and individually within each window.


Threading.gif


Example 3

This example has local lists set for each specific define command. Notice that the list called %mylist is present in every define command. To keep the words from ending up mixed together in the same list, we set the list scope in the add item to list command to Local to the define command it is in.

ui text box("Word One:", #TextBox0)
ui text box("Word Two:", #TextBox1)
ui text box("Word Three:", #TextBox2)
ui text box("Word Four:", #TextBox3)
zero()
one()
two()
three()
define zero {
    thread {
        loop(5) {
            add item to list(%mylist, #TextBox0, "Don\'t Delete", "Local")
            load html($text from list(%mylist, "<br />"))
            wait($rand(1, 3))
        }
    }
}
define one {
    thread {
        in new browser {
            loop(5) {
                add item to list(%mylist, #TextBox1, "Don\'t Delete", "Local")
                load html($text from list(%mylist, "<br />"))
                wait($rand(1, 3))
            }
        }
    }
}
define two {
    thread {
        in new browser {
            loop(5) {
                add item to list(%mylist, #TextBox2, "Don\'t Delete", "Local")
                load html($text from list(%mylist, "<br />"))
                wait($rand(1, 3))
            }
        }
    }
}
define three {
    thread {
        in new browser {
            loop(5) {
                add item to list(%mylist, #TextBox3, "Don\'t Delete", "Local")
                load html($text from list(%mylist, "<br />"))
                wait($rand(1, 3))
            }
        }
    }
}

Running the script, notice that the lists are not mixing together. The value Lychee appears in its own window, and so does the other values in the ui text box.


Threadlocallists.gif



Example 4

This example uses the add list to list command and sets the scope of the list to Local.

The example functions the same way as it did in example 3.

The windows open and display their values individually in each open new window.

ui text box("Word One:", #TextBox0)
ui text box("Word Two:", #TextBox1)
ui text box("Word Three:", #TextBox2)
ui text box("Word Four:", #TextBox3)
zero()
one()
two()
three()
define zero {
    thread {
        loop(5) {
            add list to list(%mylist, $list from text(#TextBox0, ""), "Don\'t Delete", "Local")
            load html($text from list(%mylist, "<br />"))
            wait($rand(1, 3))
        }
    }
}
define one {
    thread {
        in new browser {
            loop(5) {
                add list to list(%mylist, $list from text(#TextBox1, ""), "Don\'t Delete", "Local")
                load html($text from list(%mylist, "<br />"))
                wait($rand(1, 3))
            }
        }
    }
}
define two {
    thread {
        in new browser {
            loop(5) {
                add list to list(%mylist, $list from text(#TextBox2, ""), "Don\'t Delete", "Local")
                load html($text from list(%mylist, "<br />"))
                wait($rand(1, 3))
            }
        }
    }
}
define three {
    thread {
        in new browser {
            loop(5) {
                add list to list(%mylist, $list from text(#TextBox3, ""), "Don\'t Delete", "Local")
                load html($text from list(%mylist, "<br />"))
                wait($rand(1, 3))
            }
        }
    }
}


Addl2l.gif


Example 5: Multithreading with Tables

For this example, we create a table containing five table items:

Absybane,yats%#$g
Yannatersa,Bg$^VBv
AngelBArnes,HFA4^&*
YesterdayBay,NSts&%*
BarneySim,CA@Sv$S

The threading process has been placed within a defined command.

Notice that the table cells have been passed directly into the define command. This allows for cleaner interaction between the process and the table data.


clear table(&test)
create table from file("C:\\Users\\Desktop\\test.txt", &test)
set(#a, 0, "Global")
loop(5) {
    website login($table cell(&test, #a, 0), $table cell(&test, #a, 1))
    increment(#a)
}
define website login(#id, #pass) {
    thread {
        in new browser {
            navigate("http://ubotstudio.com/playground/simple-form", "Wait")
            type text(<username field>, #id, "Standard")
            type text(<first name field>, #pass, "Standard")
            wait(10)
            click(<value="Submit">, "Left Click", "No")
        }
    }
}



Running the script will open a new browser for each table item within the table, and fill the designated fields with the table items.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox