PowerQuest 0.18.12
Loading...
Searching...
No Matches
PowerQuest Scripting Overview

PowerQuest scripts are just c# but with super easy ways to do adventure game things!

Access those things with a simple letter or word, then a dot/period. eg. Type C. to get a list of characters, then C.Dave. will give a list of things you can do with that character.

You can type:

  • C. for Characters - C.Barney.WalkTo( C.Dave );
  • E. for Engine - "Game" level functions. Eg. E.FadeOut(1);, E.Wait();
  • R. for Rooms - R.Kitchen.FirstTimeVisited
  • P. for Props - P.Door.PlayAnimation("Open");
  • H. for Hotspots - H.Tree.Description = "Strudy Tree";
  • Regions. for Regions - Regions.River.Walkable = false;
  • Points. for Room Points - Plr.Walkto( Points.CaveEntry );
  • I. for Inventory Items - I.Screwdriver.Add();
  • D. for Dialog Trees - D.Shopkeeper.Start();
  • O. for Dialog Options - O.BuyFish.Show()
  • G. for Guis - G.Keypad.Show(). See also Control. and Button. for accessing gui controls.
  • Globals. for Globals Script - Your own global script with your own functions. Globals.MyFunction();
  • Audio. for Audio - Audio.Play("Bang");
  • Cursor. for Cursor - Cursor.Hide();
  • Camera. for Camera - Camera.Shake(10);
  • Settings. for Settings - Settings.VolumeMusic = 0.5f;

All the regular c# things work too. You don't need to know any c# to start, but when you want to learn more, try this W3 schools interactive tute thing!

More Examples:

Here's the full list with more examples:

  • 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);
    
  • 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
      O.AskAboutTrees.On();
      O.Tree.Description = "That tree's bad news.";
      O.AskForSandwich.OffForever();
    
  • G. for Gui - For accessing guis. See also Control., Label., Button., etc for accessing gui controls.
      G.Keypad.Show();
      G.Inventory.Hide();
      Label.KeypadReadout.Text = "ENTER PASSWORD";
    
  • Cursor. - Mouse cursor
  • Cursor.AnimationOverride = "SillyCursor"; Cursor.Visible = false;
  • Camera. - Game camera
      Camera.Shake(3);
      Camera.SetCharacterToFollow( C.Barney );
      Camera.SetPositionOverride( Points.InterestingPoint, 1.2f );
      Camera.SetZoom( 1.5f );
    
  • Settings. - Shortcut to QuestSettings where game settings (like audio volume) is set
      Settings.VolumeSFX = 0.5f;
      Settings.Language = "DE";
      Settings.DialogDisplay = eDialogDisplay.TextAndSpeech ;
    
  • Audio. - Shortcut to SystemAudio, for audio functions
      Audio.Play("Explosion");
      Audio.PlayMusic("AwesomeMusic");
      Audio.Stop("Alarm", 0.5f);
    
  • 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";
    
  • Regions. - Regions are areas that player can walk on, used for scaling or tinting characters, triggering events, or blocking player movement
      if ( Regions.DiscoFloor.GetCharacterOnRegion( C.Dave ) )
          Regions.DiscoFloor.Tint = Color.blue;
      Regions.Chasm.Walkable = false;
    
  • Points. - Points are a named position in the room, handy to get player to walk to a spot
      C.Plr.WalkTo( Points.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();

Blocking Functions:

  • Blocking functions make the script to wait for the function to finish before moving to the next line.
  • You need these if you're using Blocking functions like Dave: Hello or Plr.WalkTo( P.Door );
  • Blocking functions need to return an IEnumerator.
  • They also have a special way of calling them. Using =>.
      => R.Kitchen.Script.OpenDoorSlowly
      => Globals.Explosion(5);
    
  • In c# these look like yield return E.Wait(()=> Globals.Explosion(5));. So much easier in the Quest Script Editor ;)

Game Objects or Component references as Variables

Note that references to GameObjects, Components, 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. Avoid directly editing 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.