How to Create an AI Chat with Gemini in Construct 3

UpvoteUpvote 1 DownvoteDownvote

Index

Features on these Courses

Stats

21 visits, 32 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 26 Aug, 2025.

Step 3: Structuring Your Code

To keep the project organized, we'll use three scripts:

  • Gemini.ts: The core logic for our AI. This file will be responsible for building requests to the Gemini API, sending them, and processing the responses.
  • importsForEvents.ts: A bridge file required by Construct. It imports our module so that its functions can be called from the event sheet scripting environment.
  • main.ts: The project's entry point, executed on startup. We'll use it to initialize global variables, like a convenient reference to Construct's runtime object.

The setup for importsForEvents.ts and main.ts is minimal.

importsForEvents.ts contains a single line to import our functions:

import * as Gemini from "./Gemini.js";

We mainly need main.ts to make Construct's runtime variable easily accessible throughout the project:

declare global {
    var runtime: IRuntime;
}

runOnStartup(async  (runtime: IRuntime) =>  {  
    globalThis.runtime =  runtime;
    })
  • 0 Comments

Want to leave a comment? Login or Register an account!