UBot Boot Camp Advanced – The Define Command – Making Custom Commands and Functions

Define Command

“Examples” Tab 1

UBot Studio Stealth

download define tutorial, ubot studio stealth, ubot studio

The Define command…

define command, ubot stealthOne of the most powerful commands in UBot Studio Stealth. You can find it under the “flow commands” in the Tool Box. It enables the user to create their own custom commands to use multiple times throughout their code. Much the same way you can with UBot’s standard commands and functions as well as plugins. The only difference is that you can name them and control the end result. You can also use them inside one another along with all the other possible combinations of commands and functions that UBot has to offer. This enables the user to reduce their code base drastically and use multi-threading to increase production and stability. A define used wisely can also reduce memory issues for longer lasting sessions and more efficient debugging. There’s nothing better than knowing exactly where the problem code is. Some sites change often and hunting for that piece of code could take a ton of time if you don’t organize your code. This tutorial aims to teach you the basic concepts and only practice will show you the true power of a define.

In the code example provided from the Code Docta UBot Expert Tutorials Store you will find five tabs. The first tab is a bot using the same concepts in a real life scenario. The third tab called “Functions” holds the function “define’s” used for the first two tabs. The second tab shows you the commands and functions used multiple times in different ways hence the tab name “Examples”. The fourth tab “Commands” contains all the command “define’s” for the first two tabs as well. So you can see that even though the define’s are in different tabs they can be called from other tabs. The calling nodes can be found under Custom Commands/Functions in the Tool Box. These custom defines are also search-able in the search box or by using (Ctrl+e) and type your custom command name. Very cool if you ask me!! Finally the last tab is just for the “Resources” where you can also find my PayPal address if you wish to donate.

When I build my commands I usually do it in the main bot tab until I have it working the way it needs to be. Once I know it works I move it to its respective tab. This makes it easier than switching tabs while debugging. The best way to move it is to go into code view (Ctrl + I) and cut the code switch to its destination tab and paste it where you want it to be. Then go back to node view (Ctrl + I) before switching tabs again. If you don’t you may lose your code!! If you decide to just copy the node(define) and paste it in its destination tab then you will need to delete it in the original tab and go back to its new tab and “refresh” the code. You “refresh” the code by switching to code view and back to node view (Ctrl + I) 2x. This way it will also refresh the Tool Box too because when you delete it it is removed. So which way will you do it?

set command, ubot studio stealthOkay moving on, let’s talk about the second tab “Examples” and what is happening there. First we set a variable #url to use in our examples. You don’t need to use a variable you can hard code it or even create a function for it if you want. It is important to keep in mind that the more variables, lists and tables you use the more memory it takes. UBot is a 32bit program and is allocated approximately 4GB of memory per instance. UBot is taking its chunk out of that to run and you may be only left with 1-1.5GB to play with depending on what plugins are being used if any. Each data structure claims a chunk of memory whether it is one item or 100+. So a database would be ideal if you are working with large data. But that is a topic for another tutorial just know it adds up quick and over time memory builds too.

In the next node we have a custom command “my command” and it takes a parameter “URL”. So, I am passing the #url variable so the command can do something with it. In out case we will navigate to the URL in the set command. This is a simple demonstration to help you understand what can be a complicated concept. Complicated by passing other things and more parameters but so far we just did the same thing as using a navigation command with the #url variable inside. Let’s do something crazy…

Next we have an alert command to simplify what is happening inside or custom function “my function” taking a parameter “URL”. So let’s run that and it will show you what’s inside #url variable. Why? Because we passed it to a function and the main purpose of a $function is to return something. Incidentally, the “alert command” is great for debugging too. Again, this is a simple example to demonstrate some pretty powerful concepts.

Here’s the crazy part, we use “$my function” inside “my command” to pass #url. Are you still with me!? Okay, so not saying you should do this exact thing, just saying you can. You can do some complicated amazing things with a define command. So look at the next node I use a function “$Google Root URL” instead of a variable. This doesn’t make sense for this small bot however, if we can get in the habit now then when you make large bots you will be making memory efficient software!! The reason you would want to use a $function rather than a variable is that when using a function/command with the “Scope” set to “Local” (set command and lists) the data is cleared from memory after the custom define is done running. More about “Scope” later but now what you need to see is that using a $function instead of a variable like in the next few nodes is better for saving memory as it is in memory for just a split second. Also, we can just hard code it but think about that for a second, if you need to change it at some point it would be easier to just change it once right? In a larger bot you could be using that is many places. Additionally, you do not need to use $my function to do all this this way.

The next node shows the base with our search term(keyword(s)) if you run this it will do a search for “I love you .png” images. Still we are not doing anything different than just using the string hard coded in the navigation command. But you can see we can concatenate a string with functions too. Essentially, joining to strings of text together. This is easily seen in an alert command.

For the next node we will show the UI variable “#UI_TB_results per page”. I use this convention for UI vars so when I search for then it is easier. If I don’t know the exact name I can type TB for text box and it will list all my text box variables. Also it is easier to find in the Debugger and Tool Box. Additionally all UI variables always have the “Scope” of “Global” and you can’t use a custom function for them. In fact you need to be careful using a custom function in the “stat monitor” as it will create an endless loop that is VERY HARD to get out of and could make your computer crash. However, UI variables are like functions they don’t need to be passed through a parameter into another define!! Again because they are “Global” which means they can be used anywhere at anytime they will always be the same every where. An example would be to use the same text box variable in 3 different tabs. If you change one they all change. “Local” means it is only used in the residing define and no place else unless you pass it as a variable to another define. As mentioned earlier this is how threads keep the information in one thread rather mix it up if done correctly. Another thing about “Local” is that the lists and variables don’t show in the Debugger. All one needs to do to see them is change the “Scope” to “Global”. But once you have your code don’t forget to change it back. If you have code in a define that is not in multi threading code you should have it set to “Local” whenever possible. This helps when you are coding in UBot Studio. The Debugger will use less memory.

Finally we have a custom command called “Google Search” that takes 2 parameters. The first parameter “Google keyword”(search term) will obviously search just as if you went to Google itself. The next parameter is “Qty per page” is the quantity of search results per page. I am sure you have noticed all the parameters are all in CAPS. I do this so that I know it is a custom command at a glance. When you are scrolling through your code and looking for some UBot/Plugin command it helps to know the difference quickly. Anyway, if you run that command it will search the UBot forum for anything I have posted. If you change “code docta” with what it is you need help with you will find it much better than the forum search.



Posted in Advanced Training.