How can Module Scripts be used in my TD game?

This might be a dumb question, but how are module scripts used when scripting tower defense game? I don’t understand how their functionality works when it comes to scripting a TD game. I’m a bit new to module scripts and I need to know if they will have any use for my Tower defense game

2 Likes

They mainly serve to keep a clean structure for your system and to avoid duplicate code, you’d have a main script, where all modules are included. In your case for TD data stores for example, these modules could be:

  • Towers (owned towers by the player)
  • CharacterData (xp, level)
  • Currency (gold, gems, etc)

Modules are highly recommended, they allow you to easily add new features to your game instead of having to scroll through 100s or 1000s lines of code. If you need to update your character XP for some reason (for example: after spawning a tower), you can just require this module and call the method defined in the CharacterData module to add XP without having to write extra code.

3 Likes

Module scripts can be used to make your code much cleaner through something called object oriented programming (OOP). For your tower defense game you can have a separate module script for mob spawning and tower spawning. I recommend you to watch gnomecode’s tower defense tutorial if you want to know how exactly to do that.

2 Likes

To define how much the damage or speed/etc of a tower is, would you put these tower attributes as strings inside module scripts? As module scripts can be used to store data as well correct?

I’d make a separate module script for this, which will only contain these attributes and no code. I used to put them together but once the attributes grew, it got too messy so it’s better to keep them apart.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.