Currently, I am in the process of creating a JavaScript version of a basic "life path generator" commonly seen in pen and paper RPGs. The generators I have been working on are inspired by the structure provided at this link:
However, I am encountering difficulties with making a reference to a previously selected random outcome.
The traditional pen and paper method involves rolling a d6 to determine the character's class (Bard, Cleric, Druid, Fighter, Rogue, Wizard) and then rolling a d20 to establish a unique background based on the chosen class.
My plan is to create arrays or objects for each set of data, but I am unsure of how to make the second set react automatically to the first random selection. Ideally, I would like to generate everything randomly with the click of a button.
Below is my current attempt at solving this challenge:
var gen_data = {};
gen_data['main'] = {
'You are a {class}.'
if {class} = Bard '{bardBackstory}'
else if {class} = Cleric '{clericBackstory}'
else if {class} = Druid '{druidBackstory}'
else if {class} = Fighter '{fighterBackstory}'
else if {class} = Rogue '{rogueBackstory}'
else if {class} = Wizard 'wizardBackstory}'
};
gen_data['class'] = {
'1': 'Bard',
'2': 'Cleric',
'3': 'Druid',
'4': 'Fighter',
'5': 'Rogue',
'6': 'Wizard
};
gen_data['bardBackstory'] = {
'1': 'story1',
'2': 'story2',
'3': 'etc'
};
gen_data['clericBackstory'] = {
'1': 'story1',
'2': 'story2',
'3': 'etc'
};
gen_data['druidBackstory'] = {
'1': 'story1',
'2': 'story2',
'3': 'etc'
};
gen_data['fighterBackstory'] = {
'1': 'story1',
'2': 'story2',
'3': 'etc'
};
gen_data['rogueBackstory'] = {
'1': 'story1',
'2': 'story2',
'3': 'etc'
};
gen_data['wizardBackstory'] = {
'1': 'story1',
'2': 'story2',
'3': 'etc'
};