Creating a storyline with multiple directions

So i want to create a storyline that goes different ways depending on your choices. I cant seem to get it quite right. When i script it to pick the second reaction it still goes for the first reaction.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  cout <<"Please pick your past\n";

cout <<"1 - Poor\n";
cout <<"2 - Middle Class\n";
cout <<"3 - Rich\n";

int pickPast;
	cout <<"Pick your past: ";

cin >>pickPast;

	switch (pickPast)
{
	case 1:
		cout <<"You awaken in the slums of Labsung to find your house robbed and your family missing.\n";
			break;
	case 2:
		cout <<"You awaken to the loud noises of commerce near the bazzar in your two story house, upon waking up someone knocks on your door.\n";
		    break;
	case 3:
		cout <<"You awaken in your velvet robe and you are greeted by your butler, he requests that you go downstairs immediately.\n";
			break;
}
	while(true)
	
	{
		cout <<"Re-enter your Past value (1,2,or 3)";

		char userInput;
		cin >> userInput;

		if(userInput == 1); 

			cout <<"You quickly leave the house and discover that a riot is in progress inside the slums, you see a woman being attacked but you also hear your sister calling for help in the distance.\n\n";
			cout <<"Do you...\n";

			cout <<"1 - Help the damsel in distress.\n";
			cout <<"2 - Run instantly towards your sisters screams.\n";
			int pickReaction;
			cout <<"Pick your Reaction: ";

			cin >>pickReaction;
				switch (pickReaction)
				{
				case 1: 
					cout <<"You swing a hammer down on the attacker and save the woman who thanks and joins you in the search for your sister\n";
					break;
				case 2: 
					cout <<"You abandon the woman being attacked and run down the street towards your sister to find her being dragged away by the police, you try to wrestle the police off but you fail and end up getting beaten by the police.\n";
					break;
				}
						
		if(userInput == 2);
			 
			cout <<"You walk outside to help your mother at the family store and as soon as you arrive a thief runs off with merchandise from your shop\n\n";
			cout <<"Do you...\n";

			cout <<"1 - Chase the thief.\n";
			cout <<"2 - Attack the thief.\n";
			cout <<"3 - Ignore the thief.\n";
			int pickReaction2;
			cout <<"Pick your reaction: ";
			
			cin >>pickReaction2;
				switch (pickReaction2)
			{
				case 1:
					cout <<"You run after the thief only to run into an ambush set up by the thiefs band of ruffians, they swiftly attack and rob you!\n";
					break;
				case 2:
					cout <<"You shoot the thief down and reclaim your merchandise, you leave the thief on the floor and enter your family's store.\n";
					break;
				case 3:
					cout <<"The thief makes off with the merchandise but dont worry, no one saw you ignore the robbery.\n";
					break;
			}
Your if statements should not have semicolons after them; that makes the if statement run nothing if that condition is true.
If i take the semi colons away it completely ignores the text right after.

These

cout <<"You quickly leave the house and discover that a riot is in progress inside the slums, you see a woman being attacked but you also hear your sister calling for help in the distance.\n\n";

cout <<"You walk outside to help your mother at the family store and as soon as you arrive a thief runs off with merchandise from your shop\n\n";

no longer appear
ok try this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
.
.
.  // rest of ur code
.// line 32.......
if(userInput == 1) 
                         {   //use this
			cout <<"You quickly leave the house and discover that a riot is in progress inside the slums, you see a woman being attacked but you also hear your sister calling for help in the distance.\n\n";
			cout <<"Do you...\n";

			cout <<"1 - Help the damsel in distress.\n";
			cout <<"2 - Run instantly towards your sisters screams.\n";
			int pickReaction;
			cout <<"Pick your Reaction: ";

			cin >>pickReaction;
				switch (pickReaction)
				{
				case 1: 
					cout <<"You swing a hammer down on the attacker and save the woman who thanks and joins you in the search for your sister\n";
					break;
				case 2: 
					cout <<"You abandon the woman being attacked and run down the street towards your sister to find her being dragged away by the police, you try to wrestle the police off but you fail and end up getting beaten by the police.\n";
					break;
				}
                       } // and dis....
.//do the same to all ur if/if-else statements
.
.


as Zhuge told u the if statement wont run.U will also have to enclose
if statement in a { } if it has more than one commands/statements inside
it
HOPE THIS WILL HELP YOU
cheers,
cyberdude








I did this but now it doesnt give me any of these options when the game is ran.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
	cout <<"You walk outside to help your mother at the family store and as soon as you arrive a thief runs off with merchandise from your shop\n\n";
			cout <<"Do you...\n";

			cout <<"1 - Chase the thief.\n";
			cout <<"2 - Attack the thief.\n";
			cout <<"3 - Ignore the thief.\n";
			int pickReaction2;
			cout <<"Pick your reaction: ";
			
			cin >>pickReaction2;
				switch (pickReaction2)
			{
				case 1:
					cout <<"You run after the thief only to run into an ambush set up by the thiefs band of ruffians, they swiftly attack and rob you!\n";
					break;
				case 2:
					cout <<"You shoot the thief down and reclaim your merchandise, you leave the thief on the floor and enter your family's store.\n";
					break;
				case 3:
					cout <<"The thief makes off with the merchandise but dont worry, no one saw you ignore the robbery.\n";
					break;
			}



the thing I said depends on the structure of the full problem .U know like how much statements are there inside the if
The way you designed your code will make it hard for you do do stuff.
I have a recommendation.
You could put the actions that should be done based on the answers in diferent functions. If action 1 happens you call function1, if the other thing happends then you call the other function.
For exemple you could have a part of all of this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
cout <<"You quickly leave the house and discover that a riot is in progress inside the slums, you see a woman being attacked but you also hear your sister calling for help in the distance.\n\n";
			cout <<"Do you...\n";

			cout <<"1 - Help the damsel in distress.\n";
			cout <<"2 - Run instantly towards your sisters screams.\n";
			int pickReaction;
			cout <<"Pick your Reaction: ";

			cin >>pickReaction;
				switch (pickReaction)
				{
				case 1: 
					cout <<"You swing a hammer down on the attacker and save the woman who thanks and joins you in the search for your sister\n";
					break;
				case 2: 
					cout <<"You abandon the woman being attacked and run down the street towards your sister to find her being dragged away by the police, you try to wrestle the police off but you fail and end up getting beaten by the police.\n";
					break;
				}

in a function and just call it there. Othetwise you should put the whole code for what is to be done inside the switch, there is no point in asking the user to enter the same answer 2 times, right?
Last edited on
For if statements, when there is one statement after, do this:
1
2
3
 if(example == true)
                cout<<It's true \n";
//notice how I put the statement right after the if statement, no semicolons or brackets 


However, if there are multiple statements, you need brackets:
1
2
3
4
5
if(example == false){
cout<<"It's false \n"; 
cout<<"lol";
}
//notice that the brackets {} are there because there are multiple statements  
Topic archived. No new replies allowed.