Logical
@if[@cond,@n1,@n2]
Returns @n1 if @cond is true (not 0), else returns @n2.

$if[@cond,$s1,$s2]
Returns $s1 if @cond is true (not 0), else returns $s2.
Example: $if[(@time<.5),"It's before noon","It's after noon."];

@loop[@counter,@start,@limit,@increm][numeric expression]
Evaluates a numeric expression repeatedly and accumulates the result of each evaluation. Within the expression, @c_  is the counter and @a_  is the accumulator (the variable containing the sum of the results of all the iterations).

Example, the sum of odd numbers 1 through 9:
    @loop[0,1,9,2][@c_].

In the above example, the counter starts at 1 and goes to 9, incrementing by 2. Each loop, the result of the expression (in this case the expression is simply @c_, which is the counter itself) is stored in @a_ (although that variable isn't used in this example) and the @loop function itself returns the total after all the iterations.  So the above example is the same as 1+3+5+7+9, and the result would be 25.

NOTE: entering the wrong arguments to this function can cause it to become stuck in an infinite loop. If this occurs, MB will continue to run, but without returning any result for the call to @loop. You can press F12 to break out of an infinite loop.

@queue
Returns the index of the queue used by the most recent ENQUEUE command.

New in Magsbot 4.0:

@ftn[$button_name,...]
$ftn[$button_name,...]
Similar to the FTN command, but these functions also return a value from the action button. Within the action button, use the commands RETURN (for $ftn) or RETURN_ (for @ftn) to return a value to the calling routine. For example:

(Calling routine:)

@x=@ftn["MyButton",12];
report $fmt["MyButton returned %s",@x];
output:
MyButton returned 14

(Inside MyButton:)

ARGS @n;
RETURN_  @n+2

You can also create a macro to make the function call simpler. For instance, you could add this to userdefs.udf:
@MyButton[@]=@ftn["MyButton",~1]
Then you can call your function simply like this:
@x=@MyButton[12]
 
New in Magsbot 6.0:

@threadcount
Returns the number of currently running threads.

@thread_[@index]
Returns the handle of a currently-running thread by index.

@thread
Called outside of a thread, this returns the handle of the most recently-created thread. Version 7.11.8 and higher: called within a thread, returns the handle of that thread.

Also see the related commands: THREAD, THREADSUSPEND, THREADRESUME and THREADEND.

Back to Functions