Thread

From UBot Studio
(Difference between revisions)
Jump to: navigation, search
(Example 3)
Line 154: Line 154:
  
 
[[File:threadlocallists.gif]]
 
[[File: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.
 +
 +
<pre>
 +
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))
 +
            }
 +
        }
 +
    }
 +
}
 +
 +
</pre>
 +
 +
 +
 +
[[File:addl2l.gif]]

Revision as of 16:32, 6 March 2014

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

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox