Skip to content

Drain

The drain at the bottom of a pinball table, with no code: a ball that falls into it is lost, and the next of its Balls is served onto the PlungerServeDelay seconds later, until there are none left and the game’s over. A ball lost within BallSave seconds of being shot is given back instead, and shot again by itself (once: shot again, it has no ball save of its own).

Part of the Physics Games module: Physics puzzlers: a Slingshot to pull back and launch shots from, and Breakable things (planks, panes, blocks, pigs) that crack and break on hard knocks; a LevelGoal that wins a level once its targets are down (with a bonus for the shots left, and one to three stars) or loses it once the shots run out; a Slingshot and a Tower to make from the Entity menu (Genres, Physics Games); and the Physics template, levels of wood, glass and stone to knock down.

Put it on a trigger below the flippers. A ball is any body that falls into it (or one on its Layers); with other balls still on the table (multiball) a ball that drains just goes, and no ball is lost. Its Ball, Balls Left and Game Over outputs are for a Counter (“Ball {0}”) or a panel; its GameOverMessage opens a game-over panel. Its Extra Ball action adds a ball (a target or a Counter’s Reach can award one), and Save Ball starts a ball save. A Tilt covering it is put right as each ball drains.

Requires: Collider (a trigger the ball falls into)

Works with: Plunger (where each new ball is served); Counter (shows its Ball or Balls Left (Count an Output)); Tilt (a Tilt it puts right as the ball drains)

Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.

  • balls: a whole number = 3. How many balls a game has. (Field: a number.)
  • plunger: text = null. The plunger each new ball is served onto, by name. Empty: the nearest plunger. (Names an entity.) (Field: an entity’s name.)
  • serveDelay: a number = 1. Seconds after a ball drains before the next is served onto the plunger. (Field: a number.)
  • ballSave: a number = 5. Seconds after each ball is shot from the plunger that losing it gives it back (served and shot again by itself, with no save of its own this time): a ball save. 0 saves none. (Field: a number.)
  • layers: text = null. The collision layers it drains, e.g. “Ball”. Empty drains any body that falls into it (but flippers). (Names collision layers: their names, separated by commas.) (Field: a name.)
  • within: text = null. The table it counts balls on, by an entity’s name: the balls inside it or standing in its area. Empty counts every ball in the scene. (Names an entity.) (Field: an entity’s name.)
  • sound: text = null. A sound played as a ball drains, e.g. “Sounds/drain.wav”. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • saveSound: text = null. A sound played as a lost ball is saved. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • drainMessage: text = null. A message sent as a ball is lost, with the balls left as its data, e.g. “BallLost”. (Names a message.) (Field: a name.)
  • saveMessage: text = null. A message sent as a lost ball is given back by the ball save, e.g. “BallSaved”. (Names a message.) (Field: a name.)
  • gameOverMessage: text = “GameOver”. A message sent as the last ball drains, e.g. “GameOver”: a panel that says so opens on it. (Names a message.) (Field: a name.)
  • ball: a whole number = 1. Which ball is being played: 1 for the first. (Field: a number.)
  • gameOver: true or false = false. True once the last ball has drained. (Field: on or off.)
  • saveLeft: a number = 0. Seconds the ball save still has; 0 when it’s off. Set by the game. (Field: a number.)
  • serving: text = null. The ball waiting to be served, by its entity’s id. Set by the game. (Plain text: the ball waiting: the game sets it.) (Field: text.)
  • serveIn: a number = 0. Seconds until it’s served. Set by the game. (Field: a number.)
  • saved: true or false = false. True if the ball being served was saved, so it’s shot again by itself. Set by the game. (Field: on or off.)
  • saveReady: true or false = true. True from a ball being served until it’s shot, which starts its ball save (not for a saved ball). Set by the game. (Field: on or off.)

What anything can make it do with no code: a Trigger’s do when its message arrives, a Contraptions Wire’s input as its signal comes on, a script’s Game.Do(entity, “Name”).

  • ExtraBall. Adds a ball to the game.
  • SaveBall. Starts a ball save of its Ball Save’s seconds (5 if that’s 0): losing the ball soon gives it back.

What anything can read with no code: a Counter’s, Bar’s or Text’s output, a Contraptions Wire’s output as its signal; Text shows names too, the rest read numbers, true as 1.

  • Ball (a whole number, out of its balls). Which ball is being played: 1 for the first.
  • GameOver (true or false). True once the last ball has drained.
  • BallsLeft (a whole number). How many balls are left, the one being played too: 0 once the game’s over.
  • Saving (true or false). True while losing the ball would give it back.

Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.

  • ballsLeft: a whole number. How many balls are left, the one being played too: 0 once the game’s over.
  • saving: true or false. True while losing the ball would give it back.

Scripts use it as Drain: its methods, events and values that aren’t saved with the scene.