Jump to content
UBot Underground

If/Then, but no Else?


Recommended Posts

I often have need for the classic If/Then/Else scenario, but there doesn't seem to be a way to do this in UBot. Am I missing something?

 

For example, I need to see if a certain value is on the page, and if it is do one thing, if it's not do another. I suppose I could break things apart into subs and have the sub exit to another part of the script if a condition is met, but there should just be an "Else" option to give it the full standard suite of basic logic operations.

 

Is this slated to be added? Or better yet is it already there and I'm just missing it?

 

Jonathan

Link to post
Share on other sites

I've actually had a need for the same thing, and I tried doing it the way you mentioned (breaking into subs and running one sub if the condition is met, and if it isn't allowing it to continue on the current one.)

 

Then, I figured out a way to use the "not" function. Here is an example of how you would program it to do what you said in your example:

 

Let's say I'm looking for the words "account successfully created" and if those words appear on the screen, then it goes to google.com and if those words DON'T appear on the screen then it goes to Yahoo.com. Here is how I'd program that:

 

If > Search Page > "account successfully created"

Then > Navigate > "www.google.com"

 

If > Not > Search Page > "account successfully created"

Then > Navigate > "www.yahoo.com"

 

http://img6.imageshack.us/img6/108/notfunction.jpg

Link to post
Share on other sites

Ahhh... I had even been using the NOT function in other ways, and though this is slightly inefficient from a "real programmer" standpoint, it will definitely get the job done. Great workaround, thanks!!!

 

Jonathan

Link to post
Share on other sites

Just dawned on me a possibly more efficient/faster solution... rather than have the node search the page all over again in order to test the NOT condition, just set a flag to true when the condition IS met, and test for it being true. Something like:

 

Set #flag = False

If search page true, then set #flag = True

If #flag = False then do something else

 

Saves on a search cycle and also allows for easy testing of that condition elsewhere in the script.

 

Jonathan

Link to post
Share on other sites

Yep, works nicely too, I've converted my script to use this approach and will use it a lot in the future.

 

Wish there were user definable constants... though I suppose there's really no risk that a variable will spontaneously change during script execution.

 

Jonathan

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...