Navigation

    CreatiCode Scratch Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode

    The Absolution Value Operator

    2D Blocks
    1
    1
    176
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • info-creaticode
      CreatiCode last edited by admin

      Introduction

      When a number is greater than 0, such as 3.5, we say it is a “positive” number; when a number is less than 0, such as -2.1, we say it is a “negative” number.

      We can convert a negative number to a positive number using the “abs” operator.

      r8.gif

       
      If the input number is already a positive number, then the output number is the same as the input:

      r9.gif

       
       

      Example

      Suppose a sprite is at the x position of -25, and we want to know its horizontal distance from the center of the stage. We can simply calculate it using abs(-25), which gives us 25.

      1 Reply Last reply Reply Quote 0
      • First post
        Last post