Mod Tutorial: Part 7

Whoo boy, CYOA.

Step 20. Choose Your Own Adventure

'CYOA', 'Choose Your Own Adventure', or 'literally any custom js code'. This feature goes by many names. It is quite powerful, but used in a minimal manner in most mods. That's fine. Don't use CYOA just for the sake of it. This section is meant to understand CYOA a bit better.

Visual Template

Awhile back, Danxv made a cool visual tutorial for CYOA. Here's the Code 1. There's also a Code 2, of course.

You should take a look at the top of the Code 2. I have comments in the code - as shown with two slash symbols - that explains everything, but play through this tutorial and you should be good.

e=campaignTrail_temp // this is redundant, but Decstar uses this because it looks nicer in the code.

campaignTrail_temp.cyoa = true

Both of these lines are (generally) needed to enable CYOA.

cyoAdventure = function (a)

This line of code is crucial. All CYOA must be within a single function.

Next, the If statement. This is what determines which questions have CYOA. You need an IF statement, or something akin to it, like a SWITCH statement.

In the code, it says, IF ans==3805, then go to question 24. This is the question that sends the mod to the end. The next one says, IF ans=3086 OR 3902, go to question -1 (which is essentially restarting the mod)

The final one is IF ans==99999, go to question 8, which due to the rules of modding, goes to question 10. (If you want to know why, answer that question in the mod)

The bottom has an ELSE return False, which just means "if none of these criteria are met, AKA none of the questions answered need CYOA, just continue as normal"

Changing Questions Based Upon Previous Answers

This is the code from 2016 Democratic Primaries. Essentially, if your answer is 3501, which is where Sanders attempts to primary Obama in 2012, the question on Obama's legacy is changed signifigantly. This code is within the CYOA function inside the Sanders code. Put all your CYOA-only questions after the final question. Rather than jumping to around questions, like older CYOA, it's swapping out the cyoa questions. You can have as many questions as you wish change, and do this for multiple answers.

if (campaignTrail_temp.player_answers[0] == 3501) { // do the thing campaignTrail_temp.questions_json[23] = { "model": "campaign_trail.question", "pk": 200660, "fields": { "priority": 1, "description": "With Barack Obama being the current president, many are wondering just how you plan to address his legacy as you campaign for the Democratic nomination, especially considering your attempt at primarying him just four years ago.", "likelihood": 1 } } } else { // do the thing later campaignTrail_temp.questions_json[23] = { "model": "campaign_trail.question", "pk": 385, "fields": { "priority": 1, "description": "With Barack Obama being the current president, many are wondering just how you plan to address his legacy as you campaign for the Democratic nomination.", "likelihood": 1 } } }

This is probably one of the most useful CYOA features. It's versatile, and allows you to set up major changes to the map early on.

Actual RNG

Spoilers- but straight from 2016DNC as well. If you pick one of three answers for question 6, you'll have 30% chance that it leaks. It's use is more limited but I found this more enjoyable than regular RNG.

// CYOA if you choose to strike a deal with DNC, 30% chance if ([200566, 200570, 200926].includes(campaignTrail_temp.player_answers[5]) && Math.random()<0.3) { // Cause emails to leak early campaignTrail_temp.questions_json[36] = { "model": "campaign_trail.question", "pk": 200930, "fields": { "priority": 1, "description": "Looks like it's hit the fan. Earlier today, WikiLeaks has published thousands of emails from the Democratic National Committee, some of which show that party insiders were favoring you over Senator Bernie Sanders. With the final primaries coming up, this could be a serious 'June Surprise'. What on earth will you do?", "likelihood": 1 } } }

Optional: Re-enable Further Reading

RecReading=true

Put this at the top of your Code 1. I would reccomend using Liquid Astro's further reading tool to make a fancy looking further reading tab. Citing your sourcs is always great.