# Functions

Use functions in place of values for some automatic calculations. Example:

``` update sprite MySprite where x=random(50) if (covered(MySprite)) update sprite MySprite where angle=getpolard(MySprite.x,MySprite.y,AnotherSprite.x,AnotherSprite.y) endif ```
• distance(x1,y1,x2,y2) - calculates the pixel distance between two points
• random(n) - returns a random number between 0 and n (not including n)
• covered(spriteName) - returns true if the named sprite is covered by another sprite's bounding box
• iskeydown("n") - returns true if the letter (in quotes) is currently pushed down
• getdata(dataName,#) - returns value in the # position of the data structure (1-based)
• timems() - returns the time, in milliseconds, that the game has been running (not including pauses)
• getglobalx(spriteName) - returns the global x-position of the sprite (useful if the sprite has a parent)
• getglobaly(spriteName) - returns the global y-position of the sprite (useful if the sprite has a parent)
• getpolard(x1,y1,x2,y2) - get angle from point 1 to point 2
• getpolarx(x,angle,distance) - given an x coordinate, return a new x value the given angle and distance away
• getpolary(y,angle,distance) - given an y coordinate, return a new y value the given angle and distance away
• islive(spriteName) - returns true if the sprite has been launched is still on the canvas
• savedata(key,value) - saves data to the browser by key and value (internally, the system adds a game identifier so do not do this yourself)
• getsavedata(key) - returns data that you previously saved to the browser
• Math.min(v1,v2) - returns the lowest value in the list
• Math.max(v1,v2) - returns the highest value in the list
• Math.floor(v1,v2) - returns integer portion of a value rounding downwards
• Math.ceil(v1,v2) - returns integer portion of a value rounding upwards
• Math.cos(v1) - returns cosine
• Math.sin(v1) - returns sine
• Math.tan(v1) - returns tangent
• Math.abs(v1) - returns the absolute value