Jump to content
UBot Underground

If variable = 50 then...


Recommended Posts

At the moment my bot will run a loop and then it'll use increment to increase the variable at the end of the cycle. What I want to do is figure out how I can use an if statement to evaluate if the bot has reached 50 and if so then sleep, any ideas on how to do this?

 

post-1721-0-70836300-1358051936_thumb.png

Link to post
Share on other sites

LOOP WHILE is a Node, a command in UBot, not a variable.
 
The logic behind it would be...
 
Repeat certain actions as long as a certain condition is met (in your case the incrementing step value is less than 50)
 
The code would be:
 

    set(#var_CYC_LoopNO, 50, "Global")
    loop while($comparison(#var_CYC_LoopNO, ">", 0)) {
        decrement(#var_CYC_LoopNO)
        divider

        comment("Place your own CODE Here")

        divider
    }

...alternatively:

    set(#var_CYC_LoopNO, 0, "Global")
    loop while($comparison(#var_CYC_LoopNO, "<", 50)) {
        divider

        comment("Place your own CODE Here")

        divider

        increment(#var_CYC_LoopNO)
    }

 

  • In the first case you start the cycling from TOP and decrement the looping variable as the first thing inside the loop
  • In the second case you start at the BOTTOM and increment the cycling variable after you have performed all code, just before the end of the looping sequence.

 

Each has its own benefits depending on what you need to code.

For instance, I'd rather use the decrementing from TOP whenever I have to loop through lists/tables, because the number of iterations is usually resulting from the list/table size, which would give a value that at its MAX would exceed the range of the incremental values any reference functions would allow.

 

To make it simple:

 

A table that has 3 rows of data.

 

$total table rows would return the value 3

 

A looping upto 3 cycles is in order.

 

Each row in the table is referenced though starting from 0, then 1, then 2 is max (corresponding to the 3rd row)

 

A reference to any $table cell depending on the looping incremental variable of the LOOP node cannot be 3 though, as the $table cell(&table, #var_CYC_LoopNO, 0) would return an error when #var_CYC_LoopNO = 3 !!!

 

As such, it's better to evaluate the max number of rows:

 

set(#var_CYC_LoopNO, $total table rows(&table), "Global")

and then

decrement(#var_CYC_LoopNO)

thus being able to LOOP from TOP to BOTTOM between the values 2, 1, 0 respectively and safely referencing the table cells with the table cell related functions.

  • Like 1
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...