ShiftContents

Category: Objects / Contents
Since engine version: 4.6.5.0 CP (extended in 4.9.1.0 GWE)

Description

Resorts the contained objects to the next object with a differing ID will be in front. The most common application for this command is inventory selection.

Syntax

bool ShiftContents (object pObj, bool fShiftBack, id idTarget, bool fDoCalls);

Parameters

pObj:
[opt] Object the content of which is to be shifted. Can be 0 in local calls.
fShiftBack:
[opt] If true, objects will be resorted backwards.
idTarget:
[opt] ID of the object type to be in front after the shift. If this parameter is specified, no call to ControlContents will be made. The object will be selected directly and without the selection sound. In this way you can overload the contents switching in ControlContents and add your own sounds or special events.
fDoCalls:
[opt] If true, calls to ControlContents and Selection will be made.

Remarks

This command calls the function "ControlContents" in the container object which can be used to overload the selection process. If the function ControlContents does not exist in the container object or returns 0, the function "Selection" will be called in the newly selected inventory object. If the function Selection does not exist in the contained object or returns 0, the engine will play the "Grab" sound effect for the container object (default behaviour for inventory selection). See also object scripts.
Notice: nowadays the function ShiftContents will also play the selection sound. To avoid double playback, object scripts should take this into consideration and not play their own selection sound or move the sound playback to the ControlContents function, as seen below.

Examples

protected func ControlSpecial()
  {
  [Inventarwechsel]
  ShiftContents();
  return(1);
  }
Part of an object script. Moves the contents of an object on special key 1.
protected func ControlContents(idTarget)
  {
  if (!ShiftContents(0, 0, idTarget)) return(1);
  return(1, Sound("Ding"));
  }
Through this object script selecting a new inventory item will play a "Ding" sound.
See also: ResortObjects, ScrollContents
Sven2, April 2002