This wiki has been moved to https://github.com/SuperTux/wiki into the mediawiki branch.

Difference between revisions of "ScriptingScriptedObject"

From SuperTux
Jump to: navigation, search
(Methods: updated to current svn)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
  
= Summary =
+
== Summary ==
  
A ScriptedObject is basically a SuperTux object that can be scripted to move around and animate. You can created ScriptedObjects
+
A ScriptedObject is basically a SuperTux object that can be scripted to move around and animate.
by defining them in level files. Each scripted object will be exposed under its name to the scripting engine.
+
  
= Example =
+
== Instances ==
 +
ScriptedObjects are created by being defined in level files. Each scripted object will be exposed under its name to the scripting engine. Access through the console is realised via the <tt>sector</tt> object.
 +
 
 +
=== Example ===
  
 
Example of a definition:
 
Example of a definition:
Line 22: Line 24:
 
  </pre>
 
  </pre>
  
The above object will be exposed under the name SUPERTUX in the scripting engine. Example usage:
+
The above object will be exposed under the name <tt>SUPERTUX</tt> in the scripting engine. Example usage:
  
 
  <pre>
 
  <pre>
Line 38: Line 40:
 
  </pre>
 
  </pre>
  
= Methods =
+
The object can be accessed from the console <tt>sector.SUPERTUX</tt>.
 +
 
 +
== Methods ==
 
{| class="objectlist"
 
{| class="objectlist"
 
! class="method"| set_action(string animation)
 
! class="method"| set_action(string animation)
Line 83: Line 87:
 
|}
 
|}
  
= Constants =
+
== Constants ==
  
 
None
 
None
  
 
[[Category:Scripting Reference]]
 
[[Category:Scripting Reference]]

Revision as of 05:47, 25 June 2007


Summary

A ScriptedObject is basically a SuperTux object that can be scripted to move around and animate.

Instances

ScriptedObjects are created by being defined in level files. Each scripted object will be exposed under its name to the scripting engine. Access through the console is realised via the sector object.

Example

Example of a definition:

  (scriptedobject
    (x 2291)
    (y 1275)
    (name "SUPERTUX")
    (sprite "images/creatures/tux_big/tux.sprite")
    (layer 100)
    (visible #t)
    (physic-enabled #t)
    (solid #t)
  ) 
 

The above object will be exposed under the name SUPERTUX in the scripting engine. Example usage:

  // This script will make tux look and walk left/right (this should make him appear
  //   "upset")
  SUPERTUX.set_action("stand-right");
  wait(2);
  SUPERTUX.set_velocity(200,0);
  wait(0.3);
  SUPERTUX.set_velocity(0,0);
  wait(0.4);
  SUPERTUX.set_action("stand-left");
  SUPERTUX.set_velocity(-200,0);
  wait(0.3);
 

The object can be accessed from the console sector.SUPERTUX.

Methods

set_action(string animation) Activates the sprite's action specified in animation.
get_action() Returns the name of the sprite's current action.
move(float x, float y) Moves the object by x units to the right and y down relative to its current position.
set_pos(float x, float y) Basically identical to move, except its relativity to the sector origin.
get_pos_x() Returns the X coordinate of the object's position.
get_pos_y() Returns the Y coordinate of the object's position.
set_velocity(float x, float y) Makes the object move in a certain direction (with a certain speed) given by the x and y coordinates.
get_velocity_x() Returns the X coordinate of the object's velocity.
get_velocity_y() Returns the Y coordinate of the object's velocity.
set_visible(bool visible) Shows or hides the object according to the value of visible.
is_visible() Returns true if the object is visible, false otherwise.
set_solid(bool solid) Makes the object solid according to the value of solid.
is_solid() Returns true if the object is solid, false otherwise.
get_name() Returns the name of the object

Constants

None