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

The PowerQuest tool manages scripts for you to make it easy to find the bit you want to edit.

There's a button for each "interaction" that can be made on each object. Eg. The Use, Look, Inv buttons next to hotspots. They open the script editor at the right place for you, so you don't have to go scrawling through scripts to find the right file and function to edit!

So, say you have a prop called "door", clicking the "Use" button next to it in the editor will:

  • Create a .cs script file for that room if it doesn't exist, and add an OnInteractHotspotDoor() function automatically.
  • Open the script editor at the right function so you can start typing your script.
  • That'll look like this:

Here's what the code in that image does:

- Makes the player (Dave) walks to the Door prop that was clicked on.
- Makes Dave say "I'd better try the door".
- If a custom variable is set (if the door's unlocked), the Door prop plays an animation and opens.
- Otherwise, the game displays a message "The door won't open".

If that's a bit scary, don't worry!

  • You can start by sticking to the non-codey bits and until you're excited to learn more.
  • Or run through the basics of W3 school's C# course, it has an interactive "Try it yourself" thing so you can mess around in a safe space :)

The Quest Script Editor

When you open a script from the PowerQuest Editor, it'll open initially in the Quest Script Editor (pictured above). This is a streamlined script editor for quickly editing dialog and quick interactions.

Editor controls:

  • Click the dropdown on the top-left to change to other functions in that script.
  • If Auto-Load is ticked, interacting with things in game will automatically open the script for you to edit.
  • While the game is running, hit Compile to immediately test your changes!
  • Ctrl-scroll to adjust font size.
  • Change text font and theme/colors in PQ Tools -> Editor Settings.
  • For more complex behaviour and coding, click the View C# button to explore the script in Visual Studio. There you have access to the entire files to add your own functions, proper autocomplete, syntax and error highlighting, debugging tools, etc, etc.

What If I have errors?

It'll happen! It's easy to miss a semi-colon at the end of the line and things like that.

You'll get a red error in the unity console (or at the bottom of the screen). Double click errors in that console window to take you to that line in your code. Hopefully the message there can make sense for you to fix. If not post in the discord and someone'll sort you out!

How do I know what to type?

Have a look at the PowerQuest API page!


Next: Look at how to set up your project in the Editor Manual.

Or: Dive further into scripting on the PowerQuest API page, which explains the different objects and functions you can use.


For Pro Coders:

But I'm used to using Visual Studio (etc), can't I do that?

You can and should use both! It's easy to switch between them. The Quest Script editor has a __'View C#'__ button that opens your IDE (VisualStudio,VSCode,etc) at the right file and location.

There's is a bunch of advantages to the Quest Script editor:

  • You don't have to put yield return in front of every blocking function (ones that return Coroutine ) Eg:
    • C.Dave.WalkTo(12,34); instead of yield return C.Dave.WalkTo(12,34);
  • Dialog lines have simple syntax. Eg:
    • Dave: Hello! instead of yield return C.Dave.Say("Hello");
    • Bill: Hi Dave!
    • Display: This is a message box instead of yield return C.Display("This is a message box");
  • Props, Hotspots and Points have simpler access. Eg:
    • P.Door instead of Props("Door")
  • Some other Simplified Commands:
    • WalkToClicked instead of yield return C.WalkToClicked();
    • FaceClicked instead of C.FaceClicked();
    • ... instead of yield return E.WaitSkip(0.5f); (use more or less dots for longer/shorter pauses)
  • You can also add your own Simplified Commands, Autocomplete, and Syntax Highlighting in PQ Tools -> Editor Settings. (If you're handy with regular expressions)

And there's limitations to the Quest Script Editor too:

  • They're only for editing 'Quest Scripts', the ones controlled by PowerQuest. If you want to do other unity scripting, do it the normal way (With VisualStudio, VSCode, etc)
  • You can only access the inside of script functions, and variables at the top of the script file. So adding more complicated functions needs to be done in an IDE.
  • Autocomplete is limited to certain things, mainly QuestObjects. So it's not as nice as you'll get in a real IDE
  • It's really just a glorified unity text box so gets confused sometimes :)

Next: Look at how to set up your project in the Editor Manual.

Or: Dive further into scripting on the PowerQuest API page, which explains the different objects and functions you can use.