ID:1906631
 
(See the best response by Nadrew.)
Problem description:
I want to know, is it possible to create a new variable mid-game, and if so, how is it done? I hope to cut down on the number of unusable variables my players will have. For example, the player might choose between swordsman and axeman at the beginning of their game. Choosing swordsman would add a swordsmanship variable determining their skill, axeman would add an axemanship variable, for the same purpose.
You can either genericize the variable, and just name it weapon skill, or you can use a list to store skills by name or number.
You can use an associative list:
mob/player
// This defines a /list variable called "skill_levels"
// and initializes it with a size of 0.
var skill_levels[0]

Login()
// Using text as the "key", you can get a "value".
// If the key doesn't exist, you get null.
src << "Swordsmanship: [skill_levels["Swordsmanship"] || 0]"

// If the key isn't in the list, it's automatically added.
// This adds 1 to the Swordsmanship skill.
skill_levels["Swordsmanship"]++

src << "Swordsmanship: [skill_levels["Swordsmanship"]]"
In response to Kaiochao
Best response
You shouldn't initialize your lists outside of a proc, it creates a nameless init() call that will screw you over later in life when it comes time to profile your code.

var/list/skill_levels

Login()
if(!skill_levels) skill_levels = list()
..()


Is more ideal in the long-run according to Lummox.