1 script to manage all AI or a script in each NPC?

Howdy,

In my game, each player can control up to 10 troops. Some are melee, some are ranged.

My question is am I better to have 1 script that decides when they move, when they attack, etc. Or should each NPC have its own script?

It honestly wouldn’t matter as either method will result in similar circumstances. It will only make a difference when Parallel Lua comes out of beta.

What’s more important is your own management of how you use it.

Hello, obviously a script in each NPC, it’s the most easy way.

Not very helpful when it comes to debugging each script is it?

1 Like

Unless using module scripts of course…

Using 1 script to manage all AI is the best way in my opinion and by using that method, you can use CollectionService

I know but one script for every NPCs can take his time.

And there’s no difference between one for every or one for all.

Metatables can be used to access data between scripts, among other options such as _G.

What really makes the difference is one’s work flow. One script might be easier, but Modulescripts and Attributes also work and are easier for others to edit and use.

Using 1 script to manage all AI is a much better approach since it gives you a lot more control and ease of use. As far as resources go, the difference won’t be as noticeable. There will be a lot of duplicated code, though, due to the 1 script per AI. If you want to communicate them, manage them, etc. without the need for unnecessary values then 1 script as a manger is the best.

One script is messy and hard for others to edit. That’s the purpose of ModuleScripts. Duplicate code is also irrelevant if done via cloning instead of manually. Attributes can be used to set states and properties. There’s a lot you can do with AI where splitting things up can make things a whole lot easier. One script is perfectly fine, but you’ll be creating new coroutines anyway.

1 Like

Ok so, the answer is:

  • In each NPC:
    • This one is easy and you will save your time.
  • For every NPC:
    • This one can be difficult than and will take more than the previous.

Of course it’s your decision.

It should be specified to use ModuleScripts so that important aspects only need to be managed in one place like variables. NPCs should only need to reference that data. The attribute part is a clean way for both developers and other scripts to see the status of said NPC.

There’s no difference between in each or for every…

The difference is editing all of the scripts vs one. It’s important to specify exactly what you mean to avoid misinterpretation.

What I’m suggesting is an entire system focused on NPC implementation with ease of access Vs everything crammed into one main script. The difference is not in performance, but in development.

You aren’t understanding, one can take more time and is hard, other can take less time and is easy, but it’s his choise, but as a RPG developer i can say one script to manage every NPCs can be accurate, because of the errors i had.

Not to be offensive, but it seems that you haven’t read or at least not understood my previous replies in this thread. Perhaps I have not explained myself well enough. What I’m talking about is the difference between throwing something together and creating a properly implemented system. I’m not sure if I can truly explain it properly without showing a working version of what I’m suggesting.

I recommend a properly implemented system when working with a team as it will be far more beneficial for everyone involved. A single script is fine if you’re working by yourself. It might be faster to write, but it will make future development harder.

1 Like

Putting entire scripts in each ai is absolutely excess and as a scripter you want to make your code as short and compact as possible.

Well, script excess or short code, styles of scripters can change with the time.

Writing code isn’t a matter of “style” what’s the point writing lines of pointless code… :skull: