PowerQuest 0.17.3
PowerQuest Scripting Overview

PowerQuest scripts give you have simple access to most things you'll want to do in an adventure game.

The main scripting functions are split between Engine/PowerQuest, Character, Room, Hotspot, Prop, Region, Inventory, Dialog Tree, Camera, Audio, Gui, Gui Controls, and a few other classes.

The objects that make up your game can be accessed in your scripts via handy shortcuts. Type C. and autocomplete will show you a list all the characters in game. Same goes for R. for rooms, , I. for inventory items, E. for engine functions, etc.

Here's the full list:

  • E. for Engine - Shortcut to IPowerQuest, the hub for all the adventure game system stuff.
      E.FadeOut(1);
      E.Wait(3);
      if ( E.FirstOccurance("AteBadPie") )
          E.ChangeRoom(R.Vomitorium);
      E.Save(1);
      E.StartCutscene;
    
  • C. for Character
      C.Barney.Room = R.Current;
      C.Player.WalkTo( P.Tree );
      if ( C.Player.Talking == false )
          C.Player.PlayAnimation("EatPizza");
      C.Bill.Position =  Points.UnderTree;
      C.Barney.SayBG("What's all this then?");
      Dave: Ah... Nothing!
      C.Player.AnimWalk = "Run";
      C.Barney.Description = "A strange looking fellow with a rat-tail";
    
  • R. for Room - Each scene is a room
      if ( R.Current.FirstTimeVisited )
          R.Kitchen.ActiveWalkableArea = 2;
    
  • I. for Inventory Item - things you can pick up and use on other things
      I.RubberChicken.Add();
      I.Active.Description = "A rubber chicken with a pulley in the middle"
      if ( I.Sword.Active )
          Display: You can't use a sword on that
      if ( I.HeavyRock.EverCollected )
          Dave: I'm not lugging any more of those around
    
  • D. for Dialog Tree - For branching dialog
      D.SayHi.Start();
      D.TalkToFred.OptionOn("AskAboutPies");
    
  • O. for Dialog Option - For options within a branching dialog
  • G. for Gui - For accessing guis. See also Control. and Button. for accessing gui controls.
  • Cursor. - Mouse cursor
  • Camera. - Game camera
      Camera.Shake(3);
      Camera.SetPositionOverride( C.ScaryMonster );
    
  • Settings. - Shortcut to QuestSettings where game settings (like audio volume) is set
  • Audio. - Shortcut to SystemAudio, for audio functions
      Audio.Play("Explosion");
      Audio.PlayMusic("AwesomeMusic");
    
  • Globals. - Shortcut to your Global Script, where you stick all the code that you want to access from other scripts. It has a bunch of functions to stick code in too.
      Globals.m_myVariable = 69;
      Globals.MyFunction();
      E.WaitFor( Globals.MyBlockingFunction );
    
    The hotspots, props, regions and points in the current room are accessed like this:
  • P. for Prop - Props are visual objects in a room, including background/foreground objects, and clickable/interactive objects too
      P.GoldKey.Hide();
      P.Ball.MoveTo(10,20,5);
      P.Door.PlayAnimation("SlamShut");
      P.Door.Animation = "Closed";
    
  • H. for Hotspot - Hotspots have no visuals can be clickable
      H.BlueCup.Cursor = "Drink";
      if  ( H.Tree.UseCount > 0 )
          H.Tree.Description = "Someone's cut it down";
    
  • Region. - Regions are areas that player can walk on, used for scaling or tinting characters, triggering events, or blocking player movement
      if ( R.DiscoFloor.GetCharacterOnRegion( C.Dave ) )
          R.DiscoFloor.Tint = Color.blue;
      R.Chasm.Walkable = false;
    
  • Point. - Points are a named position in the room, handy to get player to walk to a spot
      C.Plr.WalkTo( Point.UnderTree );
    

Your Scripts

Quest Scripts you create and edit will be in a few different files. The functions are created automatically for you, but here's a list of them:

Game state and logic

Adding Variables

You can add member variables to any of your quest scripts. They'll be automatically saved/restored in-game if they're simple types.

In the quest script editor, just add variables to the "header" section. (Or anywhere in the script's .cs file). Eg:

public bool m_doorOpened = false;

Accessing variables

In the same script that the variable is declared, it can be accessed in any function, like so: m_doorOpened = true;

If you need to access a variable/function from multiple scripts, the best place for it is in the GlobalScript (GlobalScript.cs). This is like the other scripts, but it's easier to access from anywhere, and has some extra global functions too.

Access the global script like this:

Globals.m_doorOpened = true;

You can also access variables and functions from your other scripts, for example a room script or character script:

R.Kitchen.Script.m_doorOpened = true;
C.Dave.Script.m_wearingPants = false;

Functions

To add a function to a script file, open it in your IDE (VS/Monodevelop) first. Then add your function to the script class as you normally would in c#.

Calling regular functions you've made is no different than accessing variables

    OpenDoor();

if in the same script, otherwise: R.Kitchen.Script.OpenDoor();

But calling your own blocking functions (those that return an IEnumerator) is more complicated. Use the E.Waitfor function. Eg:

    E.WaitFor( R.Kitchen.Script.OpenDoorSlowly );`
    E.WaitFor( () => R.Kitchen.Script.OpenDoorSlowlyWithSound( "DoorSound" ) );  \\Functions with parameters need this weird 'lambda expression' thing.

Game Objects or Component references as Variables

Note that references to GameObjects and other unity objects WON'T be saved/restored.

If you need that you'll have to use the OnPostRestore() functions to re-initialize these and hook references back up.

Customising PowerQuest

PowerQuest is very flexible. If you're brave, you can edit everything about how it works. It's best not to directly edit the PowerQuest classes themselves though (The ones in the PowerQuest or Plugins folder). Since when you update PQ you'll lose your changes.

But most functionality can be added by editing things in the Game folder.

GlobalScript is the best place to add simple functionality. For example, GlobalScript.OnMouseClick() has all the logic for what happens when you click the mouse in the game. This can be changed to support different types of adventure game interface. And functions added to GlobalScript are easy to access from your interaction scripts too.

Advanced customisation

Most quest object classes have are "Partial" classes, so you can extend them by adding your own variables and functions.

The easy place to add these is in the file /Game/PowerQuestExtensions.cs

There's also callbacks for various game events that you can hook into to get things working the way you want.

This gets a bit hairy and hard to document, and there may be hooks that you need that aren't there. So hit me up on the forums/discord if you need help.