Code Docta (Nick C.) 638 Posted March 13, 2016 Report Share Posted March 13, 2016 Hi! In this tutorial I will attempt to show you how to use a "define" command/function, I call them "methods". A method can be a group of nodes or just one node that accomplishes a specific task. Much like if you have separate tabs to do different things in your program. Tabs are containers, defines are custom containers that can contain groups of other commands and functions even your custom commands/functions. Why do I need to do all this extra work man?Saves memory - Local variables and list are not saved to memory when used inside defines. Reusable code - You can reuse these methods again and again in your program.Readability - You can name your methods to be more descriptive and not waist time thinking about it for a few minutes. You know what it is at a glance.Errors - When you throw an error you will see exactly which define it came from by its name.Developing - When the scope is Local it does not show in the debugger. This means less memory to refresh and fewer restarts of the studio.Accessibility - You can find your code much easier.Your own libraries - Soon you will have a library to use over and over, it just gets easier as you go. You can share these with others in the bot bank or in your private bot bank. From the bank you can just drag them on over with out the actual define and it will compile just dandy.Leaner & Meaner programs are better! UBot is 32bit and it only gets 3-4 GB of Ram per process so, we need to trim the fat.Custom CommandsMuch like the commands given to you in UBot, a group of them may be called a "sub routine", those nodes can be put in a diefine. You can put a set of commands/nodes into the define container and run those synchronously to get the desired resuklt and use it more than once throughout your code. Ubot Forum Login("", "") define Ubot Forum Login(#USER NAME, #PASSWORD) { clear cookies navigate("http://network.ubotstudio.com/forum/","Wait") wait for element(<password field>,15,"Appear") comment("sign in") click(<login link>,"Left Click","No") wait for element($element offset(<username field>,0),10,"Appear") type text($element offset(<username field>,0),#USER NAME,"Standard") type text($element offset(<password field>,0),#PASSWORD,"Standard") click($element offset(<login button>,0),"Left Click","No") wait for element(<login link>,15,"Appear") } Just supply some parameters, a user name and a password. You can see that it has a dynamic nature where those two field always change. Custom Functions - are a little more snazzy and very helpful. The purpose of a function is to return something. Anything under "Parameters" the tool box are functions. Thin about what they do, like $next list item, this returns/gives you the next list item. It auto increments the list position and keeps track of where it is for you.The function $list from file, it reads in all the lines of a file and the parameter is a file path.Or $scrape page, it return to you the text of a page with in the parameters given. The $document text function is a good one, it "returns" whatever is in the UBot browser window so you may manipulate or do as you wish with it. alert($file name("C:\\somedirectory\\filename.csv")) define $file name(#PATH) { return($replace regular expression(#PATH,".*?\\\\|\\..*",$nothing)) } Someone gave you some regex to get the filename .*?\\|\..* Do you want to remember that regex?Do you want to remember how to use it?Of course not, just make the function and save it somewhere for future use. Also, you can reuse that function for another filename somewhere else in your code. Typically, I put Custom Commands and Custom Functions in their own tabs and when I compile, I hide them so users don't see them. In larger programs. These tabs can get very big and I split them off to reduce the render times of each tab. Another cool thing about these Methods are you can pass variables and functions via parameters. Parameters are bits of data you may need to share between defines or from other places, like from files or lists etc.sIn addition there is this notion called a "Scope". You may have noticed inside lists and sets there is a drop down to set the "Scope" to the default "Global" or "Local". Local means the data contained in a variable or list is localized to the define that "list" or "set" node it resides in. It also means it wont be seen in the debugger. So when it works that is the time to change necessary nodes to "Local". This is a must do while multi - threading. When you create your own methods they will show up in the search box or in the toolbox either under Commands>>Custom Commands or Parameters>>Custom Functions like so. For some more info on defines you can see the wiki custom commands post here In the attached .ubot file are some examples and a basic search bot,they are fully commented. The First Tab - "UBot Forum Search" This is a simple bot to demo all the methods together. In the next tab "Examples" are the how to do's. The Function tab contains the respective functions and same with the "Commands" tab. Building Functions and Commands When I build a command I do so in the tab I am making it for initially. Then I go to code view (ctrl + i), cut it and paste into commands tab where I need it to go. Then I switch back to node view (ctrl+i) and save with (alt + f + s). This saves from all that tab switching. i also will build them right in the commands tab. Like a login sequence. In order to run a define you must drag your command into the node view box from the toolbox or search box. Then I right click and run. If it is the only command then you can press the F5 key.Testing and Building Functions I usually test a function in an "Alert" command and build it in the "Functions" tab. Then place my functions where needed. When should I make a Method?If you are copying and pasting a node or group of nodes more than once it is time to make that baby/those babies into a method.Sometimes you just have to use a variable and others they should be a made into a function. Setting variables chops away at precious memory. Methods have many hidden secrets that you can only find with practice.Feel free to ask questions if anything is unclear, after all I made this for you to learn. Download this from the UBot Store The UBot tutorial for this store item is here. Enjoy,CD(Nick) P.S. For those interested in my Dark IDE look..press the windows key and + key to activate the windows magnifierwin key plus + zooms inwin key plus - zooms outctrl + alt + i inverts the colors and if you like the darkness then +1The feature requests is in the tracker. http://tracker.ubotstudio.com/search?utf8=%E2%9C%93&q=dark+theme Take the poll too. Keep in mind you don't have control over the colors when inverting.So, obviously we would like to change those to suit our needs. 8 Quote Link to post Share on other sites
davidford76 12 Posted March 13, 2016 Report Share Posted March 13, 2016 Thanks for putting this tutorial out. I will be trying to learn define commands. I know it can be a huge benefit to learn. 1 Quote Link to post Share on other sites
giganut 109 Posted March 13, 2016 Report Share Posted March 13, 2016 Killin it man! this is a great tut, much appreciation and respect for tasking the time to share that with us. 1 Quote Link to post Share on other sites
jeepinjeff 4 Posted March 13, 2016 Report Share Posted March 13, 2016 Saaaweeeeeet! Kudos, brother! 1 Quote Link to post Share on other sites
CanadaJones 3 Posted March 13, 2016 Report Share Posted March 13, 2016 Nick,Thank you VERY MUCH for sharing this with us! I have 2 questions if you wouldnt mind me asking. 1. You said: "Typically, I put commands and functions in their own tabs and when I compile I hide them so users don't see them." Is hiding the tabs in compile a basic feature to compile (I havent compiled my first bot yet), or is there some secret sauce to this as well? 2. You said: "When I build a command I do so in the tab I am making it for initially. Then I go to code view (ctrl + i) cut it and paste into commands tab where I need it to go." Do you leave the command in the tab that you were making it for initially after you've copied and pasted what was in code view into the commands tab, or do you remove it? 1 Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted March 14, 2016 Author Report Share Posted March 14, 2016 Thanks guys!!! Glad you think this is cool. For those interested in my Dark IDE look..press the windows key and + key to activate the windows magnifierwin key plus + zooms inwin key plus - zooms outctrl + alt + i inverts the colors and if you like the darkness then +1these feature requests in the tracker http://tracker.ubotstudio.com/search?utf8=%E2%9C%93&q=dark+theme take the poll as well Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted March 14, 2016 Author Report Share Posted March 14, 2016 Just want you to know this is also a supplement to this thread toohttp://network.ubotstudio.com/forum/index.php/topic/19145-journey-the-ultimate-ubot-bot-build-plugin-free-bot-no-plugins-are-used/?do=findComment&comment=119591 Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted March 14, 2016 Author Report Share Posted March 14, 2016 Nick,Thank you VERY MUCH for sharing this with us! I have 2 questions if you wouldnt mind me asking. 1. You said: "Typically, I put commands and functions in their own tabs and when I compile I hide them so users don't see them." Is hiding the tabs in compile a basic feature to compile (I havent compiled my first bot yet), or is there some secret sauce to this as well? 2. You said: "When I build a command I do so in the tab I am making it for initially. Then I go to code view (ctrl + i) cut it and paste into commands tab where I need it to go." Do you leave the command in the tab that you were making it for initially after you've copied and pasted what was in code view into the commands tab, or do you remove it?1. When you compile a bot you have more options like in the image I provided. Try to compile the bot provided, don't be suurred. ctrl + shift + c then you will see many options you can cancel at anytime. 2. When you CUT it is removed from the tab it was created in and them paste it into "Commands" tab, I did not say copy. You definitely DO NOT want more than one define for the same command or function. Make sense? Quote Link to post Share on other sites
Sebastian Rooks 3 Posted March 15, 2016 Report Share Posted March 15, 2016 I'm on a define kick myself. Or rather they're kicking my.....I've got a bot using twenty something includes. I thought I was going to be streamlined and efficient, but I don't think I've made any honest forward progress in the last 12 straight hours of effort. A lot of my defines have other defines included with them. I've been crashing all day, and I think I'm almost to the bottom of it? Can you not use a define to call another define? That seems to be what's doing me in right now. Emphasis on "seems" because I usually end up being wrong. Anyway, thanks for the tutorial Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted March 15, 2016 Author Report Share Posted March 15, 2016 Hey S.B!Ya, you can all day long. Your problem may be that you need to pass variables between them thru parameters. Especially if they are scoped as "Local" and not "Global".It should be pretty clear in the OP and in the bot provided. "In addition there is this notion called a "Scope". You may have noticed inside list and set's there is a drop down to set the Scope to the default "Global" or "Local". Local means the data contained in a variable or list is localized to the define that "list" or "set" node it resides in. It also means it wont be seen in the debugger. So when it works that is the time to necessary nodes to "Local"." and "Another cool thing about these Methods are you can pass variables and functions via parameters. Parameters are bits of data you may need to share between defines or from other places like from files or lists etc." If not lemme know and I will see if I can make it clearer. It is really hard to be a noob when you are not. So, I want everyone to understand especially new folks.Look in the bot as well as it is demonstrated in it.Hope this helps,CD Quote Link to post Share on other sites
CanadaJones 3 Posted March 17, 2016 Report Share Posted March 17, 2016 @Nick, 2 questions: 1. Could you elaborate a bit on both the purpose of functions, and commands, as well as how they're different? After closely examining the example robot provided to us in this thread, I noticed that there is a functions tab, and a commands tab, and each tab has a "Define My Function" and "Define My Command", and im very hazy as to what each is supposed to do. 2. I noticed in your Defines you have Parameters, and Returns. This is something that I havent seen alot of in my limited experience of Ubot, and I think learning it in the beginning would help us all out on getting off to a great start. Thanks as usual bro! Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted March 17, 2016 Author Report Share Posted March 17, 2016 Everything under "Commands" in the toolbox are examples of a command. When you make your own custom command you can make it so what you want to do and name it what you want. Everything under "Parameters" which should be called "Functions" are examples of a function. Except you might pass it parameters that the function can operate on then give you (return) the desired result. They both run a sequence of commands and functions to do something which is desired by you. The more you make the more creative you will become with them. Try starting with a login procedure. Then use that custom command to login and post a blog. Make another to login and update plugins,You will see you can use the login custom command for both procedures. I assure you they will become addicting. Hope that helps,CD 2 Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted March 17, 2016 Author Report Share Posted March 17, 2016 A Command is a statement. A custom command(define) can hold many statements (commands/custom commands). A Function is a question. This is why it returns an answer. These can only be used in a command/custom command. Parameters passing parameters are like passing or handing off a footballexcept we can pass a variable, function, list or tables and such like so param exmple("I passed a parameter thru a command")define param exmple(#something to pass) { alert(#something to pass)} same concept with a function in the examples tab of the attached bot you can see another example 1 Quote Link to post Share on other sites
LordPorker 7 Posted April 24, 2016 Report Share Posted April 24, 2016 Ye said: In addition there is this notion called a "Scope". You may have noticed inside list and set's there is a drop down to set the Scope to the default "Global" or "Local". Local means the data contained in a variable or list is localized to the define that "list" or "set" node it resides in. It also means it wont be seen in the debugger. So when it works that is the time to change necessary nodes to "Local". This is a must do while multi - threading. So re the debugger; during testing you set either list or set as Global in order to view the results? Then, once it's all ready, you change it to Local? If so, are there any other UB commands that need the same treatment? Great tut btw! Kudos for helping us out. 1 Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted April 25, 2016 Author Report Share Posted April 25, 2016 Your welcome guys, As far as I know LP. Glad I can help! Quote Link to post Share on other sites
ILoveUBot 10 Posted May 6, 2016 Report Share Posted May 6, 2016 This is a really useful tutorial Code Docta. I've been using define commands for a long time, but I've never created define functions. Here is an example of when I use defines and then a lot of set commands within a define. Is there a way to turn these set commands into functions that would be cleaner and more efficient? I'm struggling to get my head round it. setup() personOne() divider define personOne { set(#row,0,"Global") credentials() } define personTwo { set(#row,1,"Global") credentials() } define personThree { set(#row,2,"Global") credentials() } divider define setup { clear table(&pinAccs) create table from file("{$special folder("Application")}\\pinterestAccs.csv",&pinAccs) } define credentials { clear cookies set(#firstName,$table cell(&pinAccs,#row,0),"Global") set(#lastName,$table cell(&pinAccs,#row,1),"Global") set(#email,$table cell(&pinAccs,#row,2),"Global") set(#day,$table cell(&pinAccs,#row,3),"Global") set(#month,$table cell(&pinAccs,#row,4),"Global") set(#year,$table cell(&pinAccs,#row,5),"Global") set(#gender,$table cell(&pinAccs,#row,6),"Global") set(#country,$table cell(&pinAccs,#row,7),"Global") set(#county,$table cell(&pinAccs,#row,8),"Global") set(#address line1,$table cell(&pinAccs,#row,9),"Global") set(#address line2,$table cell(&pinAccs,#row,10),"Global") set(#city,$table cell(&pinAccs,#row,11),"Global") set(#postcode,$table cell(&pinAccs,#row,12),"Global") set(#title,$table cell(&pinAccs,#row,13),"Global") set(#phonenumber,$table cell(&pinAccs,#row,14),"Global") set(#countryUK,$table cell(&pinAccs,#row,15),"Global") set(#age,$table cell(&pinAccs,#row,16),"Global") set(#houseNumber,$table cell(&pinAccs,#row,17),"Global") set(#password,$table cell(&pinAccs,#row,18),"Global") set(#username,$table cell(&pinAccs,#row,19),"Global") set(#pin_UN,$table cell(&pinAccs,#row,20),"Global") set(#pin_Pass,$table cell(&pinAccs,#row,21),"Global") } 1 Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted July 8, 2016 Author Report Share Posted July 8, 2016 Sorry Iloveubot!just saw this, lemme throw it in the ide and take a lookisy! Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted July 8, 2016 Author Report Share Posted July 8, 2016 ok, took a look.Do you run the users separately?Do you need to see these credentials in a UI?Do you need the credentials in more than one place? like a UI and saving to a log file or if a certain condition existIn any case,this is what I came up with so far comment("false is Local to not see in debugger and waist studio memory and used for threading true is Global to see in debugger I often use a UI check box for this. It is easier to switch") set(#debug_scope,"true","Global") setup() set(#row index,0,"Global") comment("can do table total rows") loop(3) { credentials(#row index) comment("can throw a pause in here") } divider comment("I would change define name to Load Accounts Table") define setup { clear table(&pinAccs) create table from file("{$special folder("Application")}\\pinterestAccs.csv",&pinAccs) } comment("I would change these to local you can make a debug function to make it easy to change all to local and back to global") comment("it is just a convention of mine to capitalize define parameters") define credentials(#ROW) { clear cookies set(#firstName,$table cell(&pinAccs,#ROW,0),$debug SCOPE(#debug_scope)) set(#lastName,$table cell(&pinAccs,#ROW,1),$debug SCOPE(#debug_scope)) set(#email,$table cell(&pinAccs,#ROW,2),$debug SCOPE(#debug_scope)) set(#day,$table cell(&pinAccs,#ROW,3),$debug SCOPE(#debug_scope)) set(#month,$table cell(&pinAccs,#ROW,4),$debug SCOPE(#debug_scope)) set(#year,$table cell(&pinAccs,#ROW,5),$debug SCOPE(#debug_scope)) set(#gender,$table cell(&pinAccs,#ROW,6),$debug SCOPE(#debug_scope)) set(#country,$table cell(&pinAccs,#ROW,7),$debug SCOPE(#debug_scope)) set(#county,$table cell(&pinAccs,#ROW,8),$debug SCOPE(#debug_scope)) set(#address line1,$table cell(&pinAccs,#ROW,9),$debug SCOPE(#debug_scope)) set(#address line2,$table cell(&pinAccs,#ROW,10),$debug SCOPE(#debug_scope)) set(#city,$table cell(&pinAccs,#ROW,11),$debug SCOPE(#debug_scope)) set(#postcode,$table cell(&pinAccs,#ROW,12),$debug SCOPE(#debug_scope)) set(#title,$table cell(&pinAccs,#ROW,13),$debug SCOPE(#debug_scope)) set(#phonenumber,$table cell(&pinAccs,#ROW,14),$debug SCOPE(#debug_scope)) set(#countryUK,$table cell(&pinAccs,#ROW,15),$debug SCOPE(#debug_scope)) set(#age,$table cell(&pinAccs,#ROW,16),$debug SCOPE(#debug_scope)) set(#houseNumber,$table cell(&pinAccs,#ROW,17),$debug SCOPE(#debug_scope)) set(#password,$table cell(&pinAccs,#ROW,18),$debug SCOPE(#debug_scope)) set(#username,$table cell(&pinAccs,#row,19),$debug SCOPE(#debug_scope)) set(#pin_UN,$table cell(&pinAccs,#ROW,20),$debug SCOPE(#debug_scope)) set(#pin_Pass,$table cell(&pinAccs,#ROW,21),$debug SCOPE(#debug_scope)) } define $debug SCOPE(#SCOPE) { comment("in most cases you don't need to pass a variable but it can be useful for setting different scopes in other sections of code") if(#SCOPE) { then { return("Global") } else { return("Local") } } } With more info I can help a lil more but I hope this give a better idea to you.Hope that helps,CD Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted July 8, 2016 Author Report Share Posted July 8, 2016 Also,You may need to put the custom function I made on top of the custom commands.This is another reason I put them in other tabs so no need to think about which comes first.It does matter if they're in the same tab. Quote Link to post Share on other sites
deliter 203 Posted July 8, 2016 Report Share Posted July 8, 2016 nice thread just to elaborate on this particulary what ILoveUbot was asking about custom commands and functions A custom command just like the ubot commands,the blue coloured nodes, do not return a result,so they carry out an action Functions,the green nodes in Ubot,pretty much all of them return a result,data input-data output,so functions are made when you want to input something and have data returned in some form define $addNumbers(#first, #second) { return($add(#first,#second))}set(#addMe,$addNumbers(1, 2),"Global") 1 Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted July 9, 2016 Author Report Share Posted July 9, 2016 I updated the original post to explain better custom functions and commands.The attached ubot file has additional code to play with as well. 1 Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted April 11, 2017 Author Report Share Posted April 11, 2017 updated OP with The UBot tutorial for this store item is here. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.