Operator Blocks

Basic Operators

{"func":"valueOpAdd"}

+

"+" returns the addition of the two parameters

Parameters:

Num1: this parameter is one of the two numbers that will be added together.

Num2: this parameter is one of the two numbers that will be added together.

Related Blocks:
{"func":"valueOpSubtract"} ,     {"func":"valueOpMultiply"} ,     {"func":"valueOpDivide"}

Sample Code:
{"func":"registerBroadcastTrigger","values":[{"type":"string","value":"AddPoint"}],"next":{"func":"blockLooksSay","values":[{"type":"wrapper","func":"valueControlMessageSource"},{"type":"string","value":"has"},{"type":"wrapper","func":"valueOpAdd","values":[{"type":"wrapper","func":"valueControlMessageValue"},{"type":"number","value":"1"}]},{"type":"string","value":"points!"}]}} Add to my Backpack


{"func":"valueOpSubtract"}

-

"-" returns the subtraction of the two parameters.

Parameters:

Num1: this parameter is a number that you will subtract Num2 from.

Num2: this parameter is a number that will be subtracted from Num1.

Related Blocks:
{"func":"valueOpAdd"} ,     {"func":"valueOpMultiply"} ,     {"func":"valueOpDivide"}

Sample Code:
{"func":"blockMotionChangeYBy","values":[{"type":"wrapper","func":"valueOpSubtract","values":[{"type":"number","value":"0"},{"type":"wrapper","func":"valueSensingDistanceToSprite","values":[{"type":"string","value":"bottomedge"}]}]}]} Add to my Backpack


{"func":"valueOpMultiply"}

*

"*" returns the multiplication of the two parameters.

Parameters:

Num1: this parameter is one of the two numbers that will be multiplied.

Num2: this parameter is one of the two numbers that will be multiplied.

Related Blocks:
{"func":"valueOpAdd"} ,     {"func":"valueOpSubtract"} ,     {"func":"valueOpDivide"}

Sample Code:
{"func":"registerFunction","cat":"functions","name":"Multiply By 2","label":"Multiply By 2{param:Num}","hasFlap":false,"values":[{"type":"wrapper","func":"valueParam","name":"Num"}],"next":{"func":"blockControlReturn","values":[{"type":"wrapper","func":"valueOpMultiply","values":[{"type":"wrapper","func":"valueParam","name":"Num"},{"type":"number","value":"2"}]}]}} Add to my Backpack


{"func":"valueOpDivide"}

/

"/" returns the division of the two parameters.

Parameters:

Num1: this parameter is a number that you will divide by Num2 (the dividend).

Num2: this parameter is a number that Num1 will be divided by (the divisor). If this number is 0, this code block returns nothing.

Related Blocks:
{"func":"valueOpAdd"} ,     {"func":"valueOpSubtract"} ,     {"func":"valueOpMultiply"}

Sample Code:
{"func":"blockMotionGoTo","values":[{"type":"wrapper","func":"valueOpDivide","values":[{"type":"wrapper","func":"valueSensingStageProperty","values":[{"type":"choice","value":"width"}]},{"type":"number","value":"2"}]},{"type":"number","value":"0"}]} Add to my Backpack


{"func":"valueOpMod"}

Mod

"Mod" returns the remainder after dividing the two parameters.

Parameters:

Num1: this parameter is a number that you will divide by Num2 (the dividend). The remainder of the result of this division will be returned. For example, "4 mod 2" returns 0 and "6 mod 5" returns 1.

Num2: this parameter is a number that Num1 will be divided by (the divisor). If this number is 0, this code block returns nothing. The remainder of the result of this division will be returned.

Related Blocks:
{"func":"valueOpAdd"} ,     {"func":"valueOpSubtract"} ,     {"func":"valueOpMultiply"} ,     {"func":"valueOpDivide"}

Sample Code:
{"func":"blockLooksSay","values":[{"type":"wrapper","func":"valueOpMod","values":[{"type":"number","value":"7"},{"type":"number","value":"6"}]}]} Add to my Backpack


{"func":"valueOpBinary"}

Binary Operator

"Binary Operator" returns the result of various math operations (e.g. addition) on the number specified by the second parameter.

Parameters:

Num1: this is the first of two numbers that the binary operation will operate on.

Binary Operator: this parameter is the operation you want to perform on Num1 and Num2. It must be a binary operation, meaning an operation between two numbers. "+," "-," "*," and "/" return numbers, while "=," "<," "<=," ">," ">=," "!=," "and," "or," and "xor" return a Boolean value (true if the expression is true, like "2 < 4," and false if the expression is false, like "false or false.") "<<" and ">>" are called bit-wise operators. "<<" multiplies Num1 by 2 to the (Num2)th power. ">>" does the opposite; it divides Num1 by 2 to the (Num2)th power. For example, "2 << 3" returns 16, and "24 >> 2" returns 6.

Related Blocks:
{"func":"valueOpAdd"} ,     {"func":"valueOpSubtract"} ,     {"func":"valueOpMultiply"} ,     {"func":"valueOpDivide"}

Sample Code:
{"func":"blockLooksSay","values":[{"type":"wrapper","func":"valueOpBinary","values":[{"type":"number","value":"0"},{"type":"choice","value":"+"},{"type":"number","value":"0"}]},{"type":"string","value":"is"},{"type":"string","value":"0"}]} Add to my Backpack


Math Functions

{"func":"valueOpRound"}

Round

"Round" rounds the number specified by the parameter to a whole number and returns the integer result.

Parameters:

Number: the method returns this parameter, a number, rounded to the nearest whole number. For example, "round 4.3" returns 4, "round 8.65" returns 9, "round 5" returns 5, and "round 1.5" returns 2.

Related Blocks:
{"func":"valueOpAdd"} ,     {"func":"valueOpSubtract"} ,     {"func":"valueOpMultiply"} ,     {"func":"valueOpDivide"}

Sample Code:
{"func":"blockLooksSay","values":[{"type":"wrapper","func":"valueOpRound","values":[{"type":"number","value":"1.1"}]},{"type":"string","value":"is 1!"}]} Add to my Backpack


{"func":"valueOpRandom"}

Pick Random

"Pick Random" returns a random number between the two parameters.

Parameters:

Lower bound: "Pick Random" picks a random number above or equal to this parameter.

Upper bound: "Pick Random" picks a random number below or equal to this parameter.

Related Blocks:
{"func":"valueOpLess"} ,     {"func":"valueOpEqual"} ,     {"func":"valueOpGreater"}

Sample Code:
{"func":"registerCloned","next":{"func":"blockControlForeverIf","values":[{"type":"wrapper","func":"valueVar","name":"Playing"}],"containers":[{"func":"blockMotionMove","values":[{"type":"number","value":"10"}],"next":{"func":"blockControlWait","values":[{"type":"number","value":"1"}],"next":{"func":"blockControlIf","values":[{"type":"wrapper","func":"valueOpEqual","values":[{"type":"wrapper","func":"valueOpRandom","values":[{"type":"number","value":"1"},{"type":"number","value":"10"}]},{"type":"string","value":"5"}]}],"containers":[{"func":"blockMotionTurnCW","values":[{"type":"string","value":"15"}]}]}}}]}} Add to my Backpack


{"func":"valueOpMath"}

Math Function

"Math Function" returns the result of various math operations (e.g. addition) on the number specified by the second parameter.

Parameters:

Num1: this is the first of two numbers that the binary operation will operate on.

Binary Operator: this parameter is the operation you want to perform on Num1 and Num2. It must be a binary operation, meaning an operation between two numbers. "+," "-," "*," and "/" return numbers, while "=," "<," "<=," ">," ">=," "!=," "and," "or," and "xor" return a boolean value (true if the expression is true, like "2 < 4," and false if the expression is false, like "false or false.") "<<" and ">>" are called bit-wise operators. "<<" multiplies Num1 by 2 to the (Num2)th power. ">>" does the opposite; it divides Num1 by 2 to the (Num2)th power. For example, "2 << 3" returns 16, and "24 >> 2" returns 6.

Related Blocks:
{"func":"valueOpAdd"} ,     {"func":"valueOpSubtract"} ,     {"func":"valueOpMultiply"} ,     {"func":"valueOpDivide"}

Sample Code:
{"func":"blockLooksSay","values":[{"type":"wrapper","func":"valueOpBinary","values":[{"type":"number","value":"0"},{"type":"choice","value":"+"},{"type":"number","value":"0"}]},{"type":"string","value":"is"},{"type":"string","value":"0"}]} Add to my Backpack


{"func":"valueOpMath2"}

Math Function 2

"Math Function 2" returns the result of various math operations (e.g. atan2) on the numbers specified by the second and third parameters.

Parameters:

MathFunction: this parameter is the operation you want to perform on Num1 and Num2.

Num1: this is the first of two numbers that the binary operation will operate on.

Num2: this is the second of two numbers that the binary operation will operate on.

Related Blocks:
{"func":"valueOpMath"} ,     {"func":"valueOpConstants"}

Sample Code:
{"func":"blockLooksSayFor","values":[{"type":"wrapper","func":"valueOpMath2","values":[{"type":"choice","value":"pow"},{"type":"number","value":2},{"type":"number","value":"10"}]},{"type":"number","value":"2"}]} Add to my Backpack


{"func":"valueOpConstants"}

Constants

"Constants" returns the specified constant (e.g. pi).

Parameters:

Constant: this parameter should be a constant, like "pi," "e," "ln2," "ln10," "log2e," and more. The method returns the numerical value of this constant.

Related Blocks:
{"func":"valueOpAdd"} ,     {"func":"valueOpSubtract"} ,     {"func":"valueOpMultiply"} ,     {"func":"valueOpDivide"}

Sample Code:
{"func":"blockLooksSay","values":[{"type":"string","value":"Pi is:"},{"type":"wrapper","func":"valueOpConstants","values":[{"type":"choice","value":"pi"}]}]} Add to my Backpack


Boolean

{"func":"valueOpLess"}

<

"<" returns true if the first value is less than the second value and false otherwise.

Parameters:

Num1: if this number is less than Num2, the method returns true.

Num2: if this number is greater than or equal to Num1, the method returns true.

Related Blocks:
{"func":"valueOpEqual"} ,     {"func":"valueOpGreater"}

Sample Code:
{"func":"registerFlagTrigger","next":{"func":"blockControlWhile","values":[{"type":"wrapper","func":"valueVar","name":"Playing"}],"containers":[{"func":"blockControlIf","values":[{"type":"wrapper","func":"valueOpLess","values":[{"type":"wrapper","func":"valueVar","name":"NumLives"},{"type":"string","value":"0"}]}],"containers":[{"func":"blockVarPropSet","values":[{"type":"string","value":"Playing"},{"type":"string","value":"self"},{"type":"string","value":"false"}]}]}]}} Add to my Backpack


{"func":"valueOpEqual"}

=

"=" returns true if the first value is equal to the second value and false otherwise.

Parameters:

Num1: if this number is equal to Num2, the method returns true.

Num2: if this number is equal to Num1, the method returns true.

Related Blocks:
{"func":"valueOpLess"} ,     {"func":"valueOpGreater"}

Sample Code:
{"func":"registerCloned","next":{"func":"blockControlForeverIf","values":[{"type":"wrapper","func":"valueVar","name":"Playing"}],"containers":[{"func":"blockMotionMove","values":[{"type":"number","value":"10"}],"next":{"func":"blockControlWait","values":[{"type":"number","value":"1"}],"next":{"func":"blockControlIf","values":[{"type":"wrapper","func":"valueOpEqual","values":[{"type":"wrapper","func":"valueOpRandom","values":[{"type":"number","value":"1"},{"type":"number","value":"10"}]},{"type":"string","value":"5"}]}],"containers":[{"func":"blockMotionTurnCW","values":[{"type":"string","value":"15"}]}]}}}]}} Add to my Backpack


{"func":"valueOpGreater"}

>

">" returns true if the first value is greater than the second value and false otherwise.

Parameters:

Num1: if this number is greater than Num2, the method returns true.

Num2: if this number is less than or equal to Num2, the method returns true.

Related Blocks:
{"func":"valueOpLess"} ,     {"func":"valueOpEqual"}

Sample Code:
{"func":"blockControlForever","containers":[{"func":"blockSoundChangeTempo","values":[{"type":"number","value":"20"}],"next":{"func":"blockControlIf","values":[{"type":"wrapper","func":"valueOpLess","values":[{"type":"wrapper","func":"valueSoundTempo"},{"type":"string","value":"60"}]}],"containers":[{"func":"blockSoundSetTempo","values":[{"type":"number","value":"10"}]}]}}]} Add to my Backpack


{"func":"valueOpAnd"}

And

"And" returns true if both of the values are true and false otherwise

Parameters:

Bool1: this parameter should be a boolean value (true or false). If Bool1 and Bool2 are true, this method returns true.

Bool2: this parameter should be a boolean value (true or false). If Bool1 and Bool2 are true, this method returns true.

Related Blocks:
{"func":"valueOpOr"} ,     {"func":"valueOpNot"}

Sample Code:
{"func":"blockControlIf","values":[{"type":"wrapper","func":"valueOpAnd","values":[{"type":"wrapper","func":"valueVar","name":"Playing"},{"type":"wrapper","func":"valueLooksIsHidden"}]}],"containers":[{"func":"blockLooksShow","next":{"func":"blockLooksGoFront"}}]} Add to my Backpack


{"func":"valueOpOr"}

Or

"Or" returns true if at least one of the values is true and false otherwise.

Parameters:

Bool1: this parameter should be a boolean value (true or false). If Bool1 is true, this method returns true.

Bool2: this parameter should be a boolean value (true or false). If Bool2 is true, this method returns true.

Related Blocks:
{"func":"valueOpAnd"} ,     {"func":"valueOpNot"}

Sample Code:
{"func":"blockControlForever","containers":[{"func":"blockControlIf","values":[{"type":"wrapper","func":"valueOpOr","values":[{"type":"wrapper","func":"valueSensingTouchingCloneOf","values":[{"type":"string","value":"Ball"}]},{"type":"wrapper","func":"valueSensingTouchingColor","values":[{"type":"color","value":"#ffffff"}]}]}],"containers":[{"func":"blockControlBroadcast","values":[{"type":"string","value":"AddPoint"}]}]}]} Add to my Backpack


{"func":"valueOpNot"}

Not

"Not" returns true if the value is false and false if the value is true (reverses the given boolean value).

Parameters:

Bool: this parameter should be a boolean value (true or false). If it is true, the method returns false; if it is false, the method returns true.

Related Blocks:
{"func":"valueOpAnd"} ,     {"func":"valueOpOr"}

Sample Code:
{"func":"registerFlagTrigger","next":{"func":"blockControlRepeatUntil","values":[{"type":"wrapper","func":"valueOpNot","values":[{"type":"wrapper","func":"valueVar","name":"Playing"}]}],"containers":[{"func":"blockSoundChangeVolume","values":[{"type":"number","value":"1"}]}]}} Add to my Backpack


{"func":"valueOpBitNot"}

Bitwise Not

"Bitwise Not" returns the result of a bitwise not on a value.

Parameters:

Num1: this is the number that the bitwise not operation will operate on.

Related Blocks:
{"func":"valueOpConstants"}

Sample Code:
{"func":"blockLooksSayFor","values":[{"type":"wrapper","func":"valueOpBitNot","values":[{"type":"number","value":5}]},{"type":"number","value":"2"}]} Add to my Backpack


Strings

{"func":"valueOpJoin"}

Join

"Join" joins the two given strings and returns the result.

Parameters:

String1: the result of concatenating String2 to this string will be returned.

String2: the result of concatenating this string to String1 will be returned.

Related Blocks:
{"func":"blockLooksSay"} ,     {"func":"blockLooksSetLabel"}

Sample Code:
{"func":"blockPenDrawText","values":[{"type":"wrapper","func":"valueOpJoin","values":[{"type":"string","value":"X:"},{"type":"wrapper","func":"valueMotionXPosition"},{"type":"string","value":"Y:"},{"type":"wrapper","func":"valueMotionYPosition"},{"type":"string","value":"Direction:"},{"type":"wrapper","func":"valueMotionDirection"}]}]} Add to my Backpack


{"func":"valueOpLetter"}

Letter

"Letter" returns the letter at the index (specified by the first parameter) of the string (specified by the second parameter).

Related Blocks:
{"func":"valueOpLength"}

Sample Code:
{"func":"blockVarSet","values":[{"type":"string","value":"MyLetter"},{"type":"wrapper","func":"valueOpLetter","values":[{"type":"wrapper","func":"valueOpSubtract","values":[{"type":"wrapper","func":"valueObjLength","values":[{"type":"wrapper","func":"valueVar","name":"MyWord"}]},{"type":"number","value":"1"}]},{"type":"wrapper","func":"valueVar","name":"MyWord"}]}]} Add to my Backpack


{"func":"valueOpLength"}

Length

"Length" returns the length of the specified string.

Related Blocks:
{"func":"valueOpLetter"}

Sample Code:
{"func":"blockVarSet","values":[{"type":"string","value":"MyLetter"},{"type":"wrapper","func":"valueOpLetter","values":[{"type":"wrapper","func":"valueOpSubtract","values":[{"type":"wrapper","func":"valueObjLength","values":[{"type":"wrapper","func":"valueVar","name":"MyWord"}]},{"type":"number","value":"1"}]},{"type":"wrapper","func":"valueVar","name":"MyWord"}]}]} Add to my Backpack


{"func":"valueOpTextSplit"}

Split

"Split" splits the specified string into an array of substrings based on the delimiter and returns the array. For example, splitting "hello world" with the delimiter "o" will return "hell", " w", and "rld".

Related Blocks:
{"func":"valueOpTextSubstring"}

Sample Code:
{"func":"blockVarSet","values":[{"type":"string","value":"split"},{"type":"wrapper","func":"valueOpTextSplit","values":[{"type":"string","value":"hello world"},{"type":"string","value":"o"}]}]} Add to my Backpack


{"func":"valueOpTextReplace"}

Replace

"Replace" searches the specified string (second parameter) for a match (first parameter) and replaces the match with the new value (third paramter). The replaced string is returned. For example, replacing "Hello" in "Hello World" with "Hi" returns "Hi World".

Related Blocks:
{"func":"valueOpTextSplit"}

Sample Code:
{"func":"blockVarSet","values":[{"type":"string","value":"title"},{"type":"wrapper","func":"valueOpTextReplace","values":[{"type":"string","value":"hello"},{"type":"string","value":"hello world"},{"type":"string","value":"hi"}]}]} Add to my Backpack


{"func":"valueOpTextIndex"}

Index Of

"Index Of" returns the position of the first occurrence of a substring (first parameter) in a string (second parameter) . For example, index of "World" in "Hello World" returns 7.

Related Blocks:
{"func":"valueOpTextLastIndex"}

Sample Code:
{"func":"blockVarSet","values":[{"type":"string","value":"index"},{"type":"wrapper","func":"valueOpTextIndex","values":[{"type":"string","value":"world"},{"type":"string","value":"hello world"}]}]} Add to my Backpack


{"func":"valueOpTextLastIndex"}

Last Index Of

"Last Index Of" returns the position of the last occurrence of a substring (first parameter) in a string (second parameter). For example, last index of "l" in "Cello" returns 4.

Related Blocks:
{"func":"valueOpTextIndex"}

Sample Code:
{"func":"blockVarSet","values":[{"type":"string","value":"lastIndex"},{"type":"wrapper","func":"valueOpTextLastIndex","values":[{"type":"string","value":"l"},{"type":"string","value":"cello"}]}]} Add to my Backpack


{"func":"valueOpTextSubstring"}

Substring

"Substring" returns all characters from the starting position to the ending posiiton of the string (first parameter). For example, substring of "Who is there?" from start position 5 to end position 7 returns "is".

Related Blocks:
{"func":"valueOpTextSplit"}

Sample Code:
{"func":"blockVarSet","values":[{"type":"string","value":"substrings"},{"type":"wrapper","func":"valueOpTextSubstring","values":[{"type":"string","value":"Who is there?"},{"type":"number","value":5},{"type":"number","value":7}]}]} Add to my Backpack


{"func":"valueOpTextTransform"}

Perform

"Perform" performs various string operations (first parameter) on the given string (second parameter).

Related Blocks:
{"func":"valueOpJoin"}

Sample Code:
{"func":"blockVarSet","values":[{"type":"string","value":"exclaim"},{"type":"wrapper","func":"valueOpTextTransform","values":[{"type":"choice","value":"uppercase"},{"type":"string","value":"Yikes!"}]}]} Add to my Backpack