Difference between revisions of "Legacy:Functions"

From Spherical
Jump to: navigation, search
m (wrap msg box in noinclude)
(ByteArray object: API links)
Line 128: Line 128:
 
== ByteArray object ==
 
== ByteArray object ==
  
* Sphere [[Object-ByteArray|ByteArray]] object: Holds an array of bytes.
+
* Sphere [[API:ByteArray|ByteArray]] object: Holds an array of bytes.
* [[CreateByteArray]](''length''): Create a new [[Object-ByteArray|ByteArray]].
+
* [[API:CreateByteArray|CreateByteArray]](''length''): Create a new [[API:ByteArray|ByteArray]].
* [[bytearray.concat]](''byte_array_object'', ''byte_array_to_append''): Returns bytearray with byte_array_to_append attached to the end of it
+
* [[API:ByteArray/concat|ByteArray.concat]](''byte_array_object'', ''byte_array_to_append''): Returns bytearray with byte_array_to_append attached to the end of it
* [[bytearray.slice]](''start_slice'' [, ''end_slice'']): Returns a slice of the bytearray starting at start, and ending at end or the end of the bytearray if end is omitted. If end is a negative number, the end point is started from the end of the bytearray.
+
* [[API:ByteArray/slice|ByteArray.slice]](''start_slice'' [, ''end_slice'']): Returns a slice of the bytearray starting at start, and ending at end or the end of the bytearray if end is omitted. If end is a negative number, the end point is started from the end of the bytearray.
  
 +
=== Conversion ===
  
=== Conversion to and from strings ===
+
* [[API:CreateByteArrayFromString|CreateByteArrayFromString]](''string''): Create a [[API:ByteArray|ByteArray]] from ''string''.
 
+
* [[API:CreateStringFromByteArray|CreateStringFromByteArray]](''byte_array''): Convert a [[API:ByteArray|ByteArray]] into a string.
* [[CreateByteArrayFromString]](''string''): Create a [[Object-ByteArray|ByteArray]] from ''string''.
 
* [[CreateStringFromByteArray]](''byte_array''): Convert a [[Object-ByteArray|ByteArray]] into a string.
 
  
 
=== Data hashing ===
 
=== Data hashing ===
  
* [[HashByteArray]](''byte_array''): Calculate MD5 'fingerprint' of data in ''byte_array''.
+
* [[API:HashByteArray|HashByteArray]](''byte_array''): Calculate MD5 'fingerprint' of data in ''byte_array''.

Revision as of 00:41, 2 June 2013

This is a definitive reference of the Sphere API: in other words, the functions that Sphere uses in its JavaScript engine. The page currently mimics the layout of docs/development/api.txt, but is undergoing reorganisation.

Alternatively, the whole Sphere API, sorted by category, with brief descriptions of the functions is available in the API text file mirror itself.

For assistance with using JavaScript itself, consult these links:


Making new function/object pages

Simple steps:
  1. Click a red link.
  2. Place the following code in the empty edit box: {{subst:functemp}} for a new function, or {{subst:objecttemp}} for a new object.
  3. Check the minor edit flag and save.
  4. Click 'edit' at the top of the page to add content.
  5. Try to be objective when writing, and save when you're done.
  6. Remove description from this page, add page link to list at the top of the matching section.



Engine functions

Game control

Accessing installed games

  • Sphere Game object: Holds info about an installed Sphere game.
  • GetGameList(): Get a list of installed Sphere games.
  • ExecuteGame(directory): Execute Sphere game installed in directory.

Script functions

File inclusion

Time

  • GetTime(): Get the number of milliseconds since an arbitrary point in time.

Conversion

System interfaces

Video

Screen size

Clipping

  • Sphere Rectangle object: Holds dimensions for clipping rectangle functions.
  • GetClippingRectangle(): Get the rectangle in which drawing is being clipped on screen.
  • SetClippingRectangle(x, y, width, height): Set a rectangle to clip screen drawing.

Graphics primitives

API:Functions/Primitives

API:Functions/Input

API:Functions/Networking

Map Engine

API:Functions/Map

Sphere objects

Besides the above, Sphere has a set of built-in objects for more generalized use within projects. Most are loaded from external resource files, but a few (Color, ColorMatrix) are defined solely in script and remain only in-memory during the running of the project.

API:Functions/Sounds

API:Functions/Colors

API:Functions/ColorMatrices

API:Functions/Spritesets

API:Functions/Fonts

API:Functions/WindowStyles

API:Functions/Images

API:Functions/Surfaces

API:Functions/Animations

API:Functions/Filesystem

API:Functions/Files

API:Functions/Log


ByteArray object

  • Sphere ByteArray object: Holds an array of bytes.
  • CreateByteArray(length): Create a new ByteArray.
  • ByteArray.concat(byte_array_object, byte_array_to_append): Returns bytearray with byte_array_to_append attached to the end of it
  • ByteArray.slice(start_slice [, end_slice]): Returns a slice of the bytearray starting at start, and ending at end or the end of the bytearray if end is omitted. If end is a negative number, the end point is started from the end of the bytearray.

Conversion

Data hashing

  • HashByteArray(byte_array): Calculate MD5 'fingerprint' of data in byte_array.