if statement scope

inside other if statements besides the first, player.name is not initialized!

help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include "storyboard.h"

using namespace std;


int main (int argc, const char * argv[])
{
    
    sleep(1);
    storyboard::cutscene(1);
    storyboard::cutscene(2);
    return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include "character.h"

character character::create_user(string nme, int frc, int blk, int sta)
{
    character user;
    
    user.name = nme;
    user.force = frc;
    user.block = blk;
    user.stamina = sta;

    return user;  
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef full_rpg_text_based_character_h
#define full_rpg_text_based_character_h


#include <strings.h>

using namespace std;

class character 
{
public:
    
    string name;
    int force;
    int block;
    int stamina;
    
    static character create_user(string nme, int frc, int blk, int sta);
};

#endif 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef full_rpg_text_based_storyboard_h
#define full_rpg_text_based_storyboard_h

#include <strings.h>
#include "character.h"

using namespace std;

class storyboard 
{
public:
    
    static void cutscene(int segment);
    
};


#endif
[code]
[/code]
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include "storyboard.h"

using namespace std;
int o = 0;

void storyboard::cutscene(int segment)
{
    
    string temp_s;

    if (o == 0) 
    {
        cout << "??? wakes up in a grassy field..." << endl;
        cout << "and sees three blurred figures run up amidst loud noises" <<endl;
        sleep(1);
        cout << "hey, what's your name?" << endl;
        cin >> temp_s;
        o++;
    }
    
    character player = character::create_user(temp_s, 0, 0, 0);
    
    if (segment == 1)
    {
        cout << "hey, " << player.name << endl;
        sleep(1);
        cout << "how'd you get here? this is the in middle of a battlefield!" << endl;
        cout << "we need to get you back to base so we can get you some food and drink..." << endl;
        sleep(3);
    }
    if (segment == 2)
    {
        cout << "back at base... three days later" << endl;
        sleep(1);
        cout << "so you have no recollection of anything???" << endl;
        sleep(1);
        cout << "and you don't even know about the war? about how the dark ruler sent his troops across the dark rift" << endl;
        cout << "to take over earth after his 1,000 year slumber?" << endl;
        sleep(1);
        cout << "wierd..." << endl;
        sleep(1);
        cout << "so do you want to fight for us?" << endl;
        cin >> temp_s;
        if (temp_s == "yes") 
        {
            cout << "great!" << endl;
            storyboard::cutscene(3);
        }
        else
        {
            cout << "no, well thats fine too i gue-" << endl;
            sleep(1);
            cout << "just then a huge black dragon swoops down and crashes through the ceiling" << endl;
            sleep(1);
            cout << player.name << ", i'll take care of- AAAAAAHHHHHHHH!" << endl;
            storyboard::cutscene(4);
        }
        
    }
    if (segment == 3) 
    {
        cout << "our army has three guilds that you can join:" << endl;
        sleep(1);
        cout << "archer" << endl;
        cout << "healer" << endl;
        cout << "swordsman" << endl;
        sleep(2);
        cout << "choose carefully" << endl;
        cin >> temp_s;
        if (temp_s == "archer") 
        {
            cout << "nice choice!" << endl;
            cout << "archers have a high force stat... whatever that is" << endl;
            player.force += 15;
            player.block -= 5;
        }
        if (temp_s == "healer") 
        {
            cout << "nice choice!" << endl;
            cout << "healers have a high stamina stat... whatever that is" << endl;
            player.force = 10;
            player.stamina += 50;
        }
        if (temp_s == "swordsman") 
        {
            cout << "nice choice!" << endl;
            cout << "swordsmen have a high block stat... whatever that is" << endl;
            player.stamina -= 20;
            player.block += 15;
        }
    }
    if (segment == 4) 
    {
        cout << "the dragon, with its huge tail, knocks the man into the wall - unconcious..." << endl;
        sleep(1);
        cout << "just then, a dark aura glows in the dragon's eyes and it begins to speak a human's voice." << endl;
        sleep(1);
        cout << "i... i knew you were destined... destined to join our cause... fufufufu..." << endl;
        sleep(1);
        cout << "i shall... i shall imbue you with this... the dark seal of the underworld... fufufufu..." << endl;
        sleep(1);
        cout << "the dragon spews a cloud of dark mist at you; you feel a tingling sensation on your shoulder, " << endl;
        cout << "but it turns to a burning feeling as the mist becomes thicker..." << endl;
        sleep(1);
        cout << "all of a sudden, everything fades to black..." << endl;
        sleep(3);
        cout << "hey, hey " << player.name << ", wake up!" << endl;
        cout << "did you just faint? that was wierd..." << endl;
        sleep(1);
        cout << "nevermind - what guild will you join?" << endl;
        sleep(1);
        cout << "archer" << endl;
        cout << "healer" << endl;
        cout << "or swordsman" << endl;
        sleep(2);
        cout << "choose carefully" << endl;
        cin >> temp_s;
        if (temp_s == "archer") 
        {
            cout << "nice choice!" << endl;
            cout << "archers have a high force stat... whatever that is" << endl;
            player.force += 15;
            player.block -= 5;
        }
        if (temp_s == "healer") 
        {
            cout << "nice choice!" << endl;
            cout << "healers have a high stamina stat... whatever that is" << endl;
            player.force -= 10;
            player.stamina += 50;
        }
        if (temp_s == "swordsman") 
        {
            cout << "nice choice!" << endl;
            cout << "swordsmen have a high block stat... whatever that is" << endl;
            player.stamina -= 20;
            player.block += 15;
        }
    }
    
}
Hi I had to go through and change quite a bit so I'm just going to post up the code and if you have question, ask.

Tested and it works, up to the point where you choose your Worker class I guess?

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
#include "storyboard.h"

using namespace std;


int main(int argc, const char * argv[])
{
	this_thread::sleep_for(chrono::seconds(1));
	storyboard::cutscene(1);
	storyboard::cutscene(2);
	return 0;
}


character.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once
#include <string>

using namespace std;

#ifndef full_rpg_text_based_character_h
#define full_rpg_text_based_character_h

class character
{
public:
	string name;
	int force;
	int block;
	int stamina;

	character(string nme, int frc, int blk, int sta) : 
	       name(nme), force(frc), block(blk), stamina(sta){}
	
};

#endif  


storyboard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#pragma once
#include <iostream>
#include <string>
#include <thread>
#include "character.h"

using namespace std;

#ifndef full_rpg_text_based_storyboard_h
#define full_rpg_text_based_storyboard_h

class storyboard
{
public:

	static void cutscene(int segment);

};

#endif 


storyboard.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "storyboard.h"

using namespace std;

int o = 0;
void storyboard::cutscene(int segment)
{

	string temp_s;

	if (o == 0)
	{
		cout << "??? wakes up in a grassy field..." << endl;
		cout << "and sees three blurred figures run up amidst loud noises" << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "hey, what's your name?" << endl;
		cin >> temp_s;
		o++;
	}

	character *player = new character(temp_s, 0, 0, 0);

	if (segment == 1)
	{
		cout << "hey, " << player->name << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "how'd you get here? this is the in middle of a battlefield!" << endl;
		cout << "we need to get you back to base so we can get you some food and drink..." << endl;
		this_thread::sleep_for(chrono::seconds(3));
	}
	if (segment == 2)
	{
		cout << "back at base... three days later" << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "so you have no recollection of anything???" << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "and you don't even know about the war? about how the dark ruler sent his troops across the dark rift" << endl;
		cout << "to take over earth after his 1,000 year slumber?" << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "wierd..." << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "so do you want to fight for us?" << endl;
		cin >> temp_s;
		if (temp_s == "yes")
		{
			cout << "great!" << endl;
			storyboard::cutscene(3);
		}
		else
		{
			cout << "no, well thats fine too i gue-" << endl;
			this_thread::sleep_for(chrono::seconds(1));
			cout << "just then a huge black dragon swoops down and crashes through the ceiling" << endl;
			this_thread::sleep_for(chrono::seconds(1));
			cout << player->name << ", i'll take care of- AAAAAAHHHHHHHH!" << endl;
			storyboard::cutscene(4);
		}

	}
	if (segment == 3)
	{
		cout << "our army has three guilds that you can join:" << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "archer" << endl;
		cout << "healer" << endl;
		cout << "swordsman" << endl;
		this_thread::sleep_for(chrono::seconds(2));
		cout << "choose carefully" << endl;
		cin >> temp_s;
		if (temp_s == "archer")
		{
			cout << "nice choice!" << endl;
			cout << "archers have a high force stat... whatever that is" << endl;
			player->force += 15;
			player->block -= 5;
		}
		if (temp_s == "healer")
		{
			cout << "nice choice!" << endl;
			cout << "healers have a high stamina stat... whatever that is" << endl;
			player->force = 10;
			player->stamina += 50;
		}
		if (temp_s == "swordsman")
		{
			cout << "nice choice!" << endl;
			cout << "swordsmen have a high block stat... whatever that is" << endl;
			player->stamina -= 20;
			player->block += 15;
		}
	}
	if (segment == 4)
	{
		cout << "the dragon, with its huge tail, knocks the man into the wall - unconcious..." << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "just then, a dark aura glows in the dragon's eyes and it begins to speak a human's voice." << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "i... i knew you were destined... destined to join our cause... fufufufu..." << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "i shall... i shall imbue you with this... the dark seal of the underworld... fufufufu..." << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "the dragon spews a cloud of dark mist at you; you feel a tingling sensation on your shoulder, " << endl;
		cout << "but it turns to a burning feeling as the mist becomes thicker..." << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "all of a sudden, everything fades to black..." << endl;
		this_thread::sleep_for(chrono::seconds(3));
		cout << "hey, hey " << player->name << ", wake up!" << endl;
		cout << "did you just faint? that was wierd..." << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "nevermind - what guild will you join?" << endl;
		this_thread::sleep_for(chrono::seconds(1));
		cout << "archer" << endl;
		cout << "healer" << endl;
		cout << "or swordsman" << endl;
		this_thread::sleep_for(chrono::seconds(2));
		cout << "choose carefully" << endl;
		cin >> temp_s;
		if (temp_s == "archer")
		{
			cout << "nice choice!" << endl;
			cout << "archers have a high force stat... whatever that is" << endl;
			player->force += 15;
			player->block -= 5;
		}
		if (temp_s == "healer")
		{
			cout << "nice choice!" << endl;
			cout << "healers have a high stamina stat... whatever that is" << endl;
			player->force -= 10;
			player->stamina += 50;
		}
		if (temp_s == "swordsman")
		{
			cout << "nice choice!" << endl;
			cout << "swordsmen have a high block stat... whatever that is" << endl;
			player->stamina -= 20;
			player->block += 15;
		}
	}

}
Topic archived. No new replies allowed.