Forum rules - please read before posting.

I tested ChatGPT with AC code: here's what I found.

edited March 24 in Technical Q&A

This isn't a support request per se. I noticed recently that Chat GPT knows Unity code incredibly well. Yesterday, I was making a complex UI script and I asked it very specific pointed questions and it was able to give me perfect code with advance coding patterns that were a revelation to me. I simply had to copy and paste it and it worked perfectly.

Then today, on a whim, I asked it a simple question:
"The game I'm making in Unity uses the Adventure Creator addon. In a script I'm writing, I want to reference an Adventure Creator interaction and call it programmatically when the Esc key is pressed. "

This was its response:

To call an Adventure Creator interaction programmatically when the Esc key is pressed, you'll need to use Adventure Creator's scripting API. Adventure Creator is a powerful toolkit for making point-and-click adventure games in Unity, and it provides a comprehensive API for interacting with its systems through code.

Here's a basic example of how you can achieve this. Note that this approach requires a basic understanding of how Adventure Creator manages its interactions and assumes you have an interaction you wish to call:

Reference Adventure Creator's Namespace: To access Adventure Creator's classes and methods, you need to include its namespace at the top of your script.

using AC; // Adventure Creator namespace

Script Setup: You'll write a script that listens for the Esc key press and then calls the desired interaction. Adventure Creator uses "ActionLists" to define interactions, so you'll be calling an ActionList programmatically.
Here is an example script that does just that:

using UnityEngine;
using AC; // Adventure Creator namespace

public class CallInteractionOnKeyPress : MonoBehaviour
{
    public ActionListAsset interactionToCall; // Assign this in the Unity Editor

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            // Check if the interactionToCall is not null
            if (interactionToCall != null)
            {
                // Kick off the interaction (ActionListAsset)
                AdvGame.RunActionListAsset(interactionToCall);
            }
        }
    }
}

In this script:

ActionListAsset interactionToCall: You need to assign this variable in the Unity Editor. Drag and drop the ActionList asset you want to run when Esc is pressed.

AdvGame.RunActionListAsset(interactionToCall): This line is responsible for executing the specified ActionList.

Assign the ActionListAsset: In the Unity Editor, attach this script to a GameObject (it could be an empty GameObject dedicated to handling this script). Then, in the Inspector, drag your desired ActionListAsset into the Interaction To Call field of the script component.

Now, whenever you press the Esc key while the game is running, it should trigger the specified Adventure Creator interaction.

Remember, the actual implementation details might vary depending on the version of Adventure Creator you are using and the specific requirements of your project. Always refer to the official Adventure Creator documentation for the most accurate and detailed information.

Granted this is a simple example, but I was pleased and a little shocked, too. I've been throwing even more complex questions at it and it seems to be able to give me perfectly baked code instantly along with detailed explanations on how to use that code and caveats.

I apologize if this is old news to everyone here, but to me this was a revelation. Anyway, just putting it out here in case this helps someone.

Comments

  • I further went on to ask:

    "in the above adventure creator code, what if I want to run an AC interaction that is in the scene (and not an asset)"

    Here was its response:

    If you want to run an Adventure Creator (AC) interaction that is part of the scene (i.e., an ActionList that is not an asset but a GameObject in the scene), you can do so by referencing the ActionList component on the GameObject instead of using an ActionListAsset.

    Adventure Creator distinguishes between these two types of ActionLists:

    ActionList Assets: These are reusable, asset-based ActionLists that can be created in the project folder and used across multiple scenes or instances.
    ActionLists: These are scene-based and exist as components attached to GameObjects within your scene. They are not reusable across different scenes without duplication.
    To execute a scene-based ActionList from your code, you should:

    Reference the ActionList component directly.
    Use the Interact() method to run the interaction.
    Here’s how you can adjust the script to work with a scene-based ActionList:

    Step 1: Modify the Script to Use a Scene-Based ActionList
    First, modify your script to reference the ActionList component directly:

    using UnityEngine;
    using AC; // Make sure to include the Adventure Creator namespace
    
    public class CallSceneActionListOnKeyPress : MonoBehaviour
    {
        public ActionList sceneActionList; // Assign this in the Unity Editor
    
        // Update is called once per frame
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                // Check if the sceneActionList is not null
                if (sceneActionList != null)
                {
                    // Run the scene-based ActionList
                    sceneActionList.Interact();
                }
            }
        }
    }
    

    Step 2: Assign the Scene-Based ActionList
    In the Unity Editor, attach this script to a GameObject.
    Locate the ActionList component in your scene that you want to execute. This component will be attached to a GameObject in your scene.
    Drag the GameObject with the ActionList component from the Hierarchy into the Scene Action List field of the script component in the Inspector.

    Additional Notes
    Scene-based ActionLists allow for interactions that are specific to the scene context and can be manipulated directly within the scene, such as enabling/disabling GameObjects, playing animations, or triggering other scene-specific events.
    Remember that scene-based ActionLists are not shared across scenes. If you need the same interaction in multiple scenes, you would either duplicate the ActionList in each scene or use an ActionListAsset for reusability.
    This approach enables you to programmatically trigger Adventure Creator interactions that are directly part of your Unity scene, providing a straightforward way to initiate complex game logic or narrative elements in response to player actions or other game events.

  • Certainly impressive - though it's my understanding that ChatGPT's data isn't "live", so it won't be able to suggest up-to-date techniques and code API.

    To have an ActionList asset run when a given input is pressed, you define an "Active Input" in the top toolbar's Active Inputs window - no need for custom scripting.

  • edited March 25

    Thanks for pointing that out, Richard. I actually went back to ChatGPT with your feedback and wrote to it:

    In reference to the earlier code for Adventure Creator in Unity where pressing the ESC key calls an AC action list in the scene, I showed your answer to the creator of AC and this is what he had to say:

    "Certainly impressive - though it's my understanding that ChatGPT's data isn't "live", so it won't be able to suggest up-to-date techniques and code API."

    "To have an ActionList asset run when a given input is pressed, you define an "Active Input" in the top toolbar's Active Inputs window - no need for custom scripting."

    Based on Richard's feedback, what do you have to say?

    And this was it's response :smile:

    Richard's feedback highlights a very important aspect of working with Adventure Creator: the tool is designed to be as designer-friendly as possible, allowing for a lot of functionality to be implemented without the need for custom scripting. This approach not only speeds up development but also makes the game creation process more accessible to those who might not be comfortable writing code.

    The "Active Inputs" feature in Adventure Creator is a perfect example of this philosophy. It allows you to define inputs (like pressing the ESC key) directly in the Adventure Creator's interface and specify what should happen when those inputs are detected (such as running an ActionList). This method is more straightforward and keeps your project organized within the Adventure Creator framework, leveraging its built-in features for handling player inputs and actions.

    Using "Active Inputs" to Run an ActionList:
    Open the Active Inputs Window: Go to the Adventure Creator's top toolbar, and select Adventure Creator → Editors → Active Inputs to open the Active Inputs window.

    Create a New Active Input: Click the "Add new Active Input" button to create a new entry.

    Configure the Input: Set the "Input button" field to the key you want to use (e.g., "Escape" for the ESC key). Adventure Creator uses Unity's Input Manager, so the name should match one of the inputs defined in Unity's Input settings (Edit → Project Settings → Input Manager).

    Assign an ActionList: In the Active Input's settings, you can specify an ActionList to run when the key is pressed. This can be an ActionList asset or a cutscene you've set up in your scene.

    Set Additional Conditions (optional): You can also specify conditions for the input to be active, such as requiring a specific game state or the player being in a certain location.

    By using Active Inputs, you integrate your input handling directly into Adventure Creator's systems, making it easier to maintain and modify your game's input logic as your project grows. This approach also ensures that your game benefits from any optimizations or features that Adventure Creator adds to its input handling system in future updates.

    Richard's point about the limitations of my data being not "live" is accurate. While I strive to provide the most accurate and useful information based on my last update, software tools and best practices evolve over time. Always consulting the official documentation or reaching out to the community or tool creators, as you did, is a commendable approach to get the most current and effective solutions.

    I guess it heavily relies on the prompt direction, but I've been using it heavily for both AC and Unity code now, (I have the paid version, which runs on GPT 4, which is updated to last year I believe.) I'm pretty sure it has it's limitations, but for now, it beats googling answers, and perhaps once they figure out the 'live' data issue, it'll replace search engines.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.