ChoiceScript and AI?


Putting this into Game Development instead of ChoiceScript Help, because I think this is more about utilization of the code instead of the code language itself.

I have a hopefully interesting, but very hypothetical question. I’ve been mulling over the different ways we can skip around in and in between scenes, as well as the option of RNG that is implemented, and I came up with a question I don’t have the experience to even fathom an answer to:

Would it be possible to code even a rudimentary reactive AI in ChoiceScript?
By this I specifically mean some kind of automatic algorithm to figure out if the player has done a series of choices so far, and then react and change a scene based on that information.

For example: Player is going through a dungeoncrawl and has been making consistent choices throughout the dungeon. They have chosen to be a mage. AI would identify the pattern and construct an end boss from that. Instead of facing a boss with slow and powerful ranged attacks, the MC faces a fast melee character resistant to some spells.

NOTE: I realize that the action I’m suggesting can be achieved by human effort and extensive use of variables, and that it would be much easier to do it manually. My question is hypothetical, and I want to open a discussion to figure out just how CS can be utilized if someone really wanted to go for it.


My experience with CS is somewhat limited (I’ve only modding existing games, not actually made my own), but what you’re asking doesn’t seem…feasible? Possible?

The closest thing I can imagine is to get a set of variables, assign each to their proper choice, and then have a string at the end that picks from a list of possible bosses or boss traits based on a character’s values in the variables. But you mentioned you don’t want it to have extensive use of variables… How exactly would this theoretical AI know what choice was which?


Of course variables would come into play, and be a fairly great component. I just want the desired shifting end result to be more or less automated.
I suppose the only feasible way to have it work would be if the AI was a complex pile of *if, *elseif and *else statements that the scenes would keep referring to.

To me this is a thought experiment about where CS draws a line on what it can’t be bent to do without added programming.


Well, choicescript is just an overlay(idk what it’s called) of another code, isn’t it? So maybe, by some wondorous miracle, it may actually be possible? Though yeah, it still would involve a hell lot of if commands.


I absolutely love these kinds of questions, the boundaries of IF in general is something that really stimulates me and something I try to challenge in my own mediocre way. I’m really not much of a coder though, it’s never quite clicked with me.

That said if I were to try my hand at this, specifically as it relates to the example you gave, I’d begin by setting up counters which track the types of decisions the player’s been making throughout the game. This could be as simple as creating respective integer variables for mage, rogue and tank (assuming these as our play styles). From there, for each decision made, that particular counter goes up by one so that by the time you reach a boss you might have something along the lines of mage: 10 rogue: 4 tank: 6. You’d of course need to set up a few lines of code which determine the highest value so that you have your dominant play style and can adjust the situation accordingly.

That would be a very simple way to go about things, but you could definitely up the complexity from there using the same base system. Since you know the upper limit of your counter (no playstyle can go above 20 in the example I’m using) you could set markers at different points. Changing the way the boss fights if you have a high (perhaps defined as above 9) rogue counter and a mid range(above 6) mage counter. The complexity further increases if you introduce additional play styles. Aside from that, there’s all sorts of nuance that you could add to the environment and even character interactions using the same principle.

I’m kinda messing around a bit with this idea in the game I’m working on, I don’t think it directly applies to the type of thing you might be thinking of, but it’s a close work around in certain respects that’s definitely possible in CS. It’s just a huge headache and a lot of branched coding.


It would be possible to do. Create an object based on the task at hand under its own scene that handles the ‘math’ involved- somewhat like a variable to result sorter/translator. The amount of work involved makes it a frightful undertaking, however. At least as independent writers unaffiliated with any game company. Is it possible? Yes. Artificial Intelligence is, note, artificial. It does not act autonimously- rather, follows algorithms programmed into it. Can you code out algorythms in Choice Script? Yes. But does it make sense to do so? Good question- not really, unless you’re a glutton for punishment and want to create a lot of unnecessary work for yourself. But it is possible to create an AI with Choicescript? Sure. With a rather ridiculous amount of work compared to the gain of having one.


I think the novelty of the original proposed situation would be a fairly neat draw, I mean who doesn’t want to face a custom challenge designed to test them? I might actually try to code something short that follows those lines, just as a proof of concept. Though I can’t really think of a way other than variable counters and extensive if/elseif/else statements during the ‘final battle’. I don’t think that necessarily counts as an AI.


AI could definitely be done in ChoiceScript, but to be honest, it would be a nightmare of an undertaking. I wrote a system for custom passwords that are cross-platform and cross-project, and that alone was a horrendous undertaking, and VERY inefficient. I think if run using a real game with a large number of variables, the time it would take to generate the password would be enormous. Just with the small test group of values I used there was a VERY noticeable lag. Anything involving looping and gosub/returns slows down the interpreter like crazy.

Just my two cents :stuck_out_tongue:


AI in choicscript: A Simple aproach

The MC and their group lands on a deserted area.

There are a rival group in the island hunting them.

And an enormous javalli that also inhabit the island.

In this “lord of flies” kind of scenario the rival group has an agressive AI that “sweep” the island hunting down the MC group AND the Javalli.

And the Javali got an defensive AI that look for places with highest defense points, like hills and woods in the (X, Y) map array.

The AI “choice” which side of the island will explore based on these directives. Its map the terrain variables and take a path based on them.

How about that?