Formatting Combat into the Code

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"] 

*fake_choice
	# 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.

5 Likes