Fuze Arena Logo
  • Forum
  • Creations
    Catalogue Showcase
  • Help

clamp()

Purpose

Restrict a value to a specified range

Description

If the specified number is below the minimum value returns the minimum value. If it is above the maximum value returns the maximum value. If it is between mimum and maximum then the number is returned.

Syntax

result = clamp( number, minimum, maximum )

Arguments

number Number to restrict

minimum Minimum value for number

maximum Maximum value for number

result Restricted value

Example

setCamera( {0, 10, 10 }, { 0, 0, 0 } )
bright = 50
light = worldLight( { -1, -1, -1 }, white, bright )
ballmodel = loadModel( "Kat Deak/Discoball" )
ball = placeObject( ballmodel, { 0, -0, 0 }, { 10, 10, 10 } )
loop
    c = controls( 0 )
    if c.up then
        bright = bright + 1
    endIf
    if c.down then
        bright = bright - 1
    endIf
    bright = clamp( bright, 0, 100 )
    setLightBrightness( light, bright )
    rotateObject( ball, { 0, 1, 0 }, 1.0 )
    drawObjects()
    printAt( 0, 0, "Use up and down arrows to adjust brightness: ", bright )
    update()
repeat

Associated Commands

ceil(), floor(), max(), min()

logo

©2019 FUZE Technologies Ltd. FUZE is a registered trademark of FUZE Technologies Ltd. All rights reserved.

Useful links

  • Fuze Main Site
  • Fuze Arena on Twitter
  • Fuze Arena on Youtube
  • Download Buyer

Contact Information

  • FUZE Technologies Ltd
    15 Clearfields Farm
    Wotton Underwood
    Aylesbury, Buckinghamshire
    ​England, HP18 0RS

  • +44 (0) 1844 239 432

  • contact@fuze.co.uk

© Copyright FUZE Technologies Ltd. All rights reserved.