Formatting Combat into the Code

Essentially I’m trying to create a combat system that is similar to that of Sordwin and City of Lux. My game is high fantasy, so multiple instances of combat as well as numerous weapons of choice will be present. I find it much simpler to divide combat into:

Cast a Spell.

However, I’m at a complete loss as to how I would code this, let alone have the game recognize what weapon you were using and the stats/style/etc… that would be entailed within that.

I’m looking for a starting place if anyone could give me that. I also plan to eventually include some type of inventory, which I’m sure the system would look at in order for it to be possible.

So in theory I get what needs to be done, but I’m not extremely choicescript savvy in that regard.

So far all I have is:

Blah blah, how will you attack?
    #Cast a Spell

I suppose this also brings into question how I would record spells? I’m planning on a predetermined set, just like normal stuff. Fireball, Ice, Wind, etc…

I understand this is a bit in depth, but I’d appreciate anyone who has the time to help out. I don’t check terribly often, but I’ll try to keep on top of this.


I’m kinda a newbie too, but I can tell you what i know, at least. I think you need to define each weapon as a variable along with the styles and/or spell sets and then use an if statement during stat checks so the game can recognize it. Maybe something like this:

*create weapona
*create spellset "fire"
*create fightstyle "agg"

Then you can set that to true or false for weapons and the fighting style to the other variations depending on the player’s choices. For spellsets, you can then define what spells are in that specific spellset in the choices using a *selectable_if like this:

*selectable_if (spellset = "fire") #Cast a fireball.

Or if you’d like to keep track of it, make another variable for spell types, then set that accordingly. Something like this:

*if (spellset = "fire")
set spelltype "spell one, spell two, etc"

Again, I’m also a newbie and this probably isn’t completely correct, but I hope it can help a bit. Good luck!

1 Like

I haven’t coded in actual combat, but I do like magic and have thought of a way to use it in one of my many projects I’m working on as I teach myself to use ChoiceScript. My way of approaching things can get a bit…extensive, and there’s a ton of *if statements involved.

So, my goto would be creating a variable for each weapon type as a boolean.

*create primary_weapon “”
*create secondary_weapon “”
*create sword false
*create spear false
*create dagger false
*create bow false
*create quarterstaff false

*create firespells false
*create icespells false
*create windspells false

That’s what I would start with, and, once the option came up where the magic and weapons in question come into play, I’ll set them to true and then code them in. I’m also the type of person to use counters, so it would be something like:

*if (firemagic = 1) #Cast Fireball
*if (icemagic = 1) #Cast Ice Sheild

For the weapons, I’d code for the primary weapon and have the scenes alter depending on the scene and the weapon at hand. I’d probably also code in secondary alterations where the secondary weapon would come in, too.

I generally keep a document or a notebook that has notes detailing what each counter in either magic class would be, so fireball for Level One and Inferno at a higher level. However, for the actual combat aspects, such as health and healing and enemy damage and such, that’s better addressed by someone else.

That’s how I would begin, but others might have a way you’ll like better.

Best of luck.


I got here a bit late, and it seems like everyone here explained it better than I could have. However, if you need help making an inventory or complex fighting scenes, I would be willing to help.

I would have a variable for current weapon which holds the index to an “object” and create all objects in a “array”.

*create current_weapon 1

*create weapons_1_name "Excalibur" 
*create weapons_1_type "sword" 
*create weapons_1_damage 15
*create weapons_1_defense_buff 5
*create weapons_1_acquired true
*comment add as many attributes as you wish... 
*comment repeat this for every possible weapon in your game.

Then in the game you can access these attributes like so:

*temp weapon_type weapons[current_weapon]["type"]
*temp hit_point weapons[current_weapon]["damage"] 

	# Attack with your ${weapon_type}. 
		*set enemy_health -hit_point
	# ... 

For the spells I would do a similar thing, but maybe have more than one spell available at a time.

*create active_spell_1 "" 
*create active_spell_2 "" 
*create active_spell_3 "" 
*create active_spell_4 "" 

Then when the player selects to cast a spell in the first level of the choice, I would expose the options in a sub-choice.

Using boolean is not a bad idea per se, and they seem intuitive at first. But they don’t scale well. If you have many options, keeping track of everything through booleans and conditionals can quickly become unwieldy. For most cases it’s better to use references (pointers). In this example, you can describe as many weapons as you want and have a single variable “pointing” to the current one in use. Then you can avoid the “conditional-hell” of checking for every possibility. You can use this pattern for the spells, the inventory system or any other “collection” of items, even to manage NPCs.

Take a look at the cslib library, specially the menu module. It can help you build choices dynamically from arrays.


I think this seems like a useful system. Really wish I had thought of that before I made my combat system.

Perhaps a combination of this and gosubs might work well as well, though I haven’t tested it. My combat system had a bunch of gosubs to determine the effects of a player’s choices. (Somebody, feel free to correct me on anything. It’s been a long time since I’ve used ChoiceScript and I’m super rusty).

*temp current_weapon = "longsword"
What would you like to do?
   #Attack with ${current_weapon}
      *gosub [current_weapon] "attack"
   #Parry with ${current_weapon}
      *gosub [current_weapon] "parry"

*label longsword

*params style
*temp damage = //Do damage calculation
*if (style = "attack")
    You attack with your longsword for ${damage} hitpoints.
*else_if (style = "parry")
    You prepare to parry with your longsword.
    *set parry = true
    You take a moment to catch your breath.
*end if 


I’d then write out one of these gosubs for every weapon/spell type.


  • Easily amend and balance weapons/spells.
  • Full control over how to handle specific cases.
  • Modular design makes it easy to add new weapons/spells later on, especially if they have unique results.


  • It can get very convoluted - my spell system used a prime-number system to navigate what spells were being cast on which element.
  • You’d have to write out a lot of these, and it makes bug-checking a bit difficult when it gets a lot. I’d recommend a separate scene file and then *gosub_scene [scene] [label] [params]
  • If you want to make a lot of weapons/spells function similarly, then this doesn’t allow for that, but you could make it [current_weapon_type] instead to group them together.
  • If you want to redesign your combat system later, you’d have a lot of rewriting to do.

Unfortunately, I currently lack the brainpower to figure out how to combine this with @cup_half_empty 's idea. I’d be interested in seeing if it’s a viable solution.

1 Like

Also, not sure if this is the correct space to mention it, but it might be worth considering that turn-based combat is very difficult to make fun in CS games. I’ve never succeeded. This kind of modular design I suggested is the nearest I got to making it interesting and dynamic, but it’s, for all it’s worth, still very repetitive and loses novelty very quickly.

I haven’t played Sordwin and City of Lux, so I’m not sure how that goes, but I’ll definitely investigate it to see how it handles, and I’d love to see how yours works out. <3

I think it is not only viable but a great idea!

I too lack the current brain power to conjure up something quickly. But if anyone is thinking of building a combat system and wants to put some effort into it, i think it’s the best way to go. And to be honest I don’t think it would be that hard to implement. :thinking: But that’s subjective, anyway.

You’re right in that turn based combat can become boring, that’s why each combat would have to be built on a per case basis. I think this :point_up: is less of a system and more of a framework, a general guide.

1 Like