Joysticks.js (system script)

From Spheriki

Jump to: navigation, search

Joysticks.js is a system script by Flikky that enables you to attach multiple map persons to different joysticks.


Contents

Usage

Use this to make the script available in your game: RequireSystemScript("joysticks.js");

Then make sure you set the update script: SetUpdateScript("UpdateJoysticks()");

And then, instead of AttachInput("player"); attach the joystick using AttachJoystick(0, "player"); (see below).


Variables and functions of joystick.js

  • DoesPersonExist(person)
    • returns true if a person exists.
  • GetNumJoystickPlayers()
    • returns the number of attached joysticks.
  • IsJoystickAttached(joystick)
    • returns true if a joystick is attached. Joystick is a number 0 to 3.
  • GetJoystickPerson(joystick)
    • returns the name of the person controlled with that joystick.
  • BindJoystickButton(joystick, joystick_button, on_press_script, on_release_script)
    • binds functions to the joystick buttons.
  • UnbindJoystickButton(joystick, joystick_button)
    • unbinds the functions to the joystick buttons.
  • AttachJoystick(joystick, name)
    • attaches a joystick number to a person name.
  • DetachJoystick(joystick, name)
    • detaches a joystick number to a person name.
  • UpdateJoysticks()
    • called each frame to recalculate movements and button actions.
  • UpdateBindedJoysticks()
    • internal function
  • UpdatePersonJoysticks()
    • internal function
  • gBindedJoysticks
    • internal variable
  • gPersonJoysticks
    • internal variable


Examples

This example creates two persons and attachs a joystick each. If there's only one joystick present, the example uses Sphere's standard function AttachInput(). Resorting to joysticks.js for single player situations isn't necessary.

RequireSystemScript("joysticks.js");

// This will set the update script to check for joystick input
SetUpdateScript("UpdateJoysticks()");

function game()
{
  // Create two persons
  CreatePerson("player_one", "player1.rss", false);
  CreatePerson("player_two", "player2.rss", false);
  
  // Attach two persons if there's two joysticks... otherwise attach only one.
  if (GetNumJoysticks() >= 1)
  {
    AttachJoystick(0, "player_one");
    AttachJoystick(1, "player_two"); // Attach a second joystick like this
  }
  else
  {
    AttachInput("player_one");
  }
  
  // Run map engine
  AttachCamera("player_one");
  MapEngine("some_map.rmp", 60);
}


Notes


See also

Personal tools