Totaly lost and tired and HELP WITH SAVE AND LOAD

Okay i am going down. I cannot find the problem for this game.
I created save and load functions and checkpoint function who are bugged.
Here is the save:
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
void save_game()
{
	string filen;

	filen = name + ".sav";
	
		ofstream fout(filen);
		fout << name << endl;
		fout << primary_weapon << endl;
		fout << second_weapon << endl;
		fout << pistol_acc[0] << endl;
		fout << pistol_acc[1] << endl;
		fout << pistol_acc[2] << endl;
		fout << pistol_acc[3] << endl;
		fout << pistol_acc[4] << endl;
		fout << smg_acc[0] << endl;
		fout << smg_acc[1] << endl;
		fout << smg_acc[2] << endl;
		fout << rifle_acc[0] << endl;
		fout << rifle_acc[1] << endl;
		fout << rifle_acc[2] << endl;
		fout << rifle_acc[3] << endl;
		fout << rifle_acc[4] << endl;
		fout << accuracy_level << endl;
		fout << cash << endl;
		fout << player_damage << endl;
		fout << player_damage_smg << endl;
		fout << player_health << endl;
		fout << player_granate << endl;
		fout << player_ammo << endl;
		fout << player_ammo_smg << endl;
		fout << player_got_rifle[0] << endl;
		fout << player_got_rifle[1] << endl;
		fout << player_got_rifle[2] << endl;
		fout << player_got_rifle[3] << endl;
		fout << player_got_rifle[4] << endl;
		fout << player_got_smg[0] << endl;
		fout << player_got_smg[1] << endl;
		fout << player_got_smg[2] << endl;
		fout << player_got_pistol[0] << endl;
		fout << player_got_pistol[1] << endl;
		fout << player_got_pistol[2] << endl;
		fout << player_got_pistol[3] << endl;
		fout << player_got_pistol[4] << endl;
		fout << player_position[0] << endl;
		fout << player_position[1] << endl;
		fout << player_position[2] << endl;
		fout << player_position[3] << endl;
		fout << player_position[4] << endl;
		fout << scenes[0] << endl;
		fout << scenes[1] << endl;
		fout << scenes[2] << endl;
		fout << scenes[3] << endl;
		fout << scenes[4] << endl;
		fout << player_in_position[0] << endl;
		fout << player_in_position[1] << endl;
		fout << player_in_position[2] << endl;
		fout << player_in_position[3] << endl;
		fout << player_in_position[4] << endl;
		for(int i = 0; i < 10; i++)
		fout << mainb_missions[i] << endl;
		fout.close();
	return;
}


Here is the load -_-:

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
void load_game(string n)
{
	
	string filen;

	filen = n + ".sav";
	ifstream fin(filen);
	if(!fin)
	{
		system("cls");
		cout << "Error occured. " << endl;
		cout << "Saved file could not be opened. " << endl;
		
		system("PAUSE");
		return;
	}
	else
	{
		fin >> name;
		fin >> primary_weapon;
		fin >> second_weapon;
		fin >> pistol_acc[0];
		fin >> pistol_acc[1];
		fin >> pistol_acc[2];
		fin >> pistol_acc[3];
		fin >> pistol_acc[4];
		fin >> smg_acc[0];
		fin >> smg_acc[1];
		fin >> smg_acc[2];
		fin >> rifle_acc[0];
		fin >> rifle_acc[1];
		fin >> rifle_acc[2];
		fin >> rifle_acc[3];
		fin >> rifle_acc[4];
		fin >> accuracy_level;
		fin >> cash;
		fin >> player_damage;
		fin >> player_damage_smg;
		fin >> player_health;
		fin >> player_granate;
		fin >> player_ammo;
		fin >> player_ammo_smg;
		fin >> player_got_rifle[0];
		fin >> player_got_rifle[1];
		fin >> player_got_rifle[2];
		fin >> player_got_rifle[3];
		fin >> player_got_rifle[4];
		fin >> player_got_smg[0];
		fin >> player_got_smg[1];
		fin >> player_got_smg[2];
		fin >> player_got_pistol[0];
		fin >> player_got_pistol[1];
		fin >> player_got_pistol[2];
		fin >> player_got_pistol[3];
		fin >> player_got_pistol[4];
		fin >> player_position[0];
		fin >> player_position[1];
		fin >> player_position[2];
		fin >> player_position[3];
		fin >> player_position[4];
		fin >> scenes[0];
		fin >> scenes[1];
		fin >> scenes[2];
		fin >> scenes[3];
		fin >> scenes[4];
		fin >> player_in_position[0];
		fin >> player_in_position[1];
		fin >> player_in_position[2];
		fin >> player_in_position[3];
		fin >> player_in_position[4];
		for(int i = 0; i < 10; i++)
		fin >> mainb_missions[i];
		fin.close();
		
	}
}


And here is the checkpoint*holding gun on my face*:
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
void checkpoint()
{
	
	string filen;

	filen = name + ".sav";
	
	
		ofstream fout(filen);
		fout << name << endl;
		fout << primary_weapon << endl;
		fout << second_weapon << endl;
		fout << pistol_acc[0] << endl;
		fout << pistol_acc[1] << endl;
		fout << pistol_acc[2] << endl;
		fout << pistol_acc[3] << endl;
		fout << pistol_acc[4] << endl;
		fout << smg_acc[0] << endl;
		fout << smg_acc[1] << endl;
		fout << smg_acc[2] << endl;
		fout << rifle_acc[0] << endl;
		fout << rifle_acc[1] << endl;
		fout << rifle_acc[2] << endl;
		fout << rifle_acc[3] << endl;
		fout << rifle_acc[4] << endl;
		fout << accuracy_level << endl;
		fout << cash << endl;
		fout << player_damage << endl;
		fout << player_damage_smg << endl;
		fout << player_health << endl;
		fout << player_granate << endl;
		fout << player_ammo << endl;
		fout << player_ammo_smg << endl;
		fout << player_got_rifle[0] << endl;
		fout << player_got_rifle[1] << endl;
		fout << player_got_rifle[2] << endl;
		fout << player_got_rifle[3] << endl;
		fout << player_got_rifle[4] << endl;
		fout << player_got_smg[0] << endl;
		fout << player_got_smg[1] << endl;
		fout << player_got_smg[2] << endl;
		fout << player_got_pistol[0] << endl;
		fout << player_got_pistol[1] << endl;
		fout << player_got_pistol[2] << endl;
		fout << player_got_pistol[3] << endl;
		fout << player_got_pistol[4] << endl;
		fout << player_position[0] << endl;
		fout << player_position[1] << endl;
		fout << player_position[2] << endl;
		fout << player_position[3] << endl;
		fout << player_position[4] << endl;
		fout << scenes[0] << endl;
		fout << scenes[1] << endl;
		fout << scenes[2] << endl;
		fout << scenes[3] << endl;
		fout << scenes[4] << endl;
		fout << player_in_position[0] << endl;
		fout << player_in_position[1] << endl;
		fout << player_in_position[2] << endl;
		fout << player_in_position[3] << endl;
		fout << player_in_position[4] << endl;
		for(int i = 0; i < 10; i++)
		fout << mainb_missions[i] << endl;
		fout.close();
		return;
	}


AND HERE IS PIECE OF CODE THAT IS PROBLEMATIC:
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
int main(int argc, char *argv[])
{
	bool load = false;

	string name2;

	srand(time(nullptr));
	

	
	
	
	system("cls");
	cout << "W ";
	Sleep(500);
	cout << "e ";
	Sleep(500);
	cout << "l ";
	Sleep(500);
	cout << "c ";
	Sleep(1000);
	cout << "o ";
	Sleep(1000);
	cout << "m ";
	Sleep(1000);
	cout << "e. " << endl;

	cout << "Main menu: " << endl;
	cout << "1> New game " << endl;
	cout << "2> Load last saved checkpoint " << endl;
	cout << "3> Exit " << endl;
	x = make_selection(3);
	x = make_selection(3);
	while(x < 1 || x > 3)
	{
		cout << "Re-select : " << endl;
		x = make_selection(3);
	}
if(x == 3)
	return 0;

if(x == 1 || x == 2)
while(true) //Game starts here
{
	if(x == 1)
	{
		cout << "WARNING: IF you enter the same name for the profile " << endl;
	cout << "everything will be erased. " << endl;
	cout << "Enter your name for the profile: "; cin >> name;
	
	save_game();
	}
	if(x == 2)
	{
		cout << "Enter your profile name: " << endl;
		cin >> name2;
		load = true;
		load_game(name2);
	}

	

	if(scenes[0]) //Scene 1
	{
		scenes[0] = false;
		scenes[1] = true;
		cout << "Year is 2012, 21 of December. " << endl;
		cout << "Russian special forces, spetsnaz, have been sent " << endl;
		cout << "to a ufo crash location. " << endl;
		cout << "Unidentified flying object was open. " << endl;
		cout << "It was laying down in snow with no body. " << endl;
		cout << "Spetsnaz leader called trucks to ship the ufo. " << endl;
		cout << "He however had to leave the site to face the terrorists. " << endl;
		cout << "He left 50 people to guard the crash site. " << endl;
		cout << "After two days of waiting for trucks, trucks came. " << endl;
		cout << "Military trucks with tank following them, all in line. " << endl;
		cout << "There were 5 trucks and 10 tanks. " << endl;
		cout << "One of the spetsnaz was slowly approaching ufo with his gas mask. " << endl;
		cout << "He was wearing Kalashnikov RPG Light Machine Gun. " << endl;
		cout << "Light just went off on every of truck. Everyone started panicking. " << endl;
		cout << "Spetsnaz that was near ufo had his gun, well how to say, \"upgraded\". " << endl;
		cout << "His eyes were however whole light blue. " << endl;
		cout << "He pulled out his LMG and that is where this report stops. " << endl;
		system("PAUSE");
       } //Scene 1 end

	if(scenes[1]) //Scene 2 start
	{
		system("cls");
		scenes[1] = false;
		scenes[2] = true;
		cout << "TIME: One day ago " << endl;
		cout << "LOCATION: Russian military helicopter " << endl;
		cout << "Spetsnaz #1: Hey boss i heard some shit was down there. " << endl;
		cout << "Spetsnaz #2: You are full of information number one! Don't scare me. " << endl;
		cout << "Spetsnaz leader: You guys are going to be fine. " << endl;
		cout << "Spetsnaz leader: Nothing to worry about...[PILOT STOPPED LEADER FROM TALKING]. " << endl;
		cout << "Pilot: Sir we are here. " << endl;
		cout << "Scene: " << endl;
		cout << "Chopper is slowly landing on big H. " << endl;
		system("PAUSE");
	}//End of scene 2

	    
	while(player_position[0]) //While player is in main base
	{
		checkpoint(); //<< HERE IS THE CHECKPOINT! DO YOU SEE IT!?!? 
             //Down there i deleted the unecesary code 


Problem is when i run the load function it shows me the scene1 and helicopter is landing scene then i press enter then it asks me again for name input and always like that >.<.


bump!
You posted a lot of unnecessary code and probably deleted what we needed to see.

The way you're using player_position and it's (presumed) definition seem suspect.

checkpoint could be rewritten from a 66 line function to:

1
2
3
4
void checkpoint()
{
	save_game();
}


Using system calls is not good.
you should really learn about struct/class...

From what I see your problem is that x doesn't change. I'd say that either lines 28 -> 40 needs to be inside the while loop or lines 45 -> 59 outside.

@coder777 I know that. I am doing this for something else :D. I wont be inserting classes here.
That did not worked i tried that :(.
Last edited on
@cire No no. This is all. :/
I know using system calls is not good but i will stick to it for now.
player_position is fine :/.
Last edited on
I did it! The problem was the variables. I declared them extern xD. My error
@cire, i did not include the important piece of code. Guys i am so sorry for this.
Thank you for your help.
Topic archived. No new replies allowed.