text based rougelike help with load function


loading save files wont work

p.s. don't have save function contents of text file are EXACTALY as follows:

5
5

//end of text file

#include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <sstream>

using namespace std;




int main()
{
string command ;

string save;

//menu

menu:

cout << " say newgame to start or, load to load new game " << endl;

cin >> command;
if (command == "newgame" );

if (command == "load" ) goto load;

system("cls");

//end

dstart:



//stats

int hp = 100;

int maxhp = 100;

int xp = 0;

//end

//spawn pos.

int x = 10;
int y = 10;

//end

start:

//map

int world [100] [100] = {0};

world [11] [10] = 9;

if (x == 17) x = 3;

if (x == 2) x = 16;

if (y == 17) y = 3;

if (y == 2) y = 16;

//end

//avatar

world[x][y] = 1 ;

//end

//death

if (hp < 1)
{
cout << "you died" << endl << endl;
goto dstart;
}

//end

//graphics script

cout << world[x+2][y+1];
cout << world[x-1][y+1];
cout << world[x][y+1];
cout << world[x-1][y+1];
cout << world[x-2][y+1];
cout << endl;
cout << world[x+2][y];
cout << world[x+1][y];
cout << world[x][y];
cout << world[x-1][y];
cout << world[x-2][y];
cout << endl;
cout << world[x+2][y-1];
cout << world[x+1][y-1];
cout << world[x][y-1];
cout << world[x-1][y-1];
cout << world[x-2][y-1];
cout << endl <<endl;
cout << "Health:" << hp << endl << endl;
//end

//movement script

cin >> command;
cout << endl;
if (command == "w" && world[x][y+1] != 9) y = y + 1;
if (command == "s" && world[x][y-1] != 9) y = y - 1;
if (command == "d" && world[x-1][y] != 9) x = x - 1;
if (command == "a" && world[x+1][y] != 9) x = x + 1;

//end

system("cls");

goto start;

load:

cout << "add .txt to the end of save name" << endl;

cin >> save;

ifstream inputFile(save);

string line;

while (getline(inputFile, line))
{
istringstream ss(line);

ss >> x >> y;

}


goto start;

return 0;
}

THNX
you are trying to load something in x and y variables before they were declared. Also in some cases xp, maxhp hp and world[][] variables can be used uninitializated too.

My advice: stop using goto. Really. Just stop. In the last 40 years many coding principles were invented. Even in 1968 using goto were a sign of bad programming.
http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html
I thought I did do that can you show me??? and what else do I use for goto???
Topic archived. No new replies allowed.