• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

### #ActualCuajin

Posted 05 April 2012 - 05:56 AM

I am trying to read the inventory for a game in a text file. The inventory looks like this:
Sword 5
Shield 5 10
Cake
Sword 7
Shield 1 5


I need to read from a file and as I'm reading I need to know if the line read was a Sword, Shield or a Cake. Depending on what the item is I will do different things with it. It is important to know the numbers that follow the item. For example, shields have 2 ints, but swords only 1 int. The ints are the stats of the item.

Scanner read = new Scanner(new File("inventory.txt")) ;
{
infile.findInLine("Shield") ;
}


### #4Cuajin

Posted 05 April 2012 - 05:55 AM

I am trying to read the inventory for a game in a text file. The inventory looks like this:
Sword 5
Shield 5 10
Cake
Sword 7
Shield 1 5


I need to read from a file and as I'm reading I need to know if the line read was a Sword, Shield or a Cake. Depending on what the item is I will do different things with it. It is important to know the numbers that follow the item. For example, shields have 2 ints, but swords only 1.

Scanner read = new Scanner(new File("inventory.txt")) ;
{
infile.findInLine("Shield") ;
}


### #3Cuajin

Posted 05 April 2012 - 05:54 AM

I am trying to read the inventory for a game in a text file. The inventory looks like this:
Sword 5
Shield 5 10
Cake
Sword 7
Shield 1 5


I need to read from a file and as I'm reading I need to know if the line read was a Sword, Shield or a Cake. Depending on what the item is I will do different things with it. It is important to know the numbers that follow the item. For example, shields have 2 ints, but swords only 1.

Scanner read = new Scanner(new File("inventory.txt")) ;
{
infile.findInLine("Shield") ;

}


Please, how do I do this?

### #2Cuajin

Posted 05 April 2012 - 05:54 AM

I am trying to read the inventory for a game in a text file. The inventory looks like this:
Sword 5
Shield 5 10
Cake
Sword 7
Shield 1 5


I need to read from a file and as I'm reading I need to know if the line read was a Sword, Shield or a Cake. Depending on what the item is I will do different things with it. It is important to know the numbers that follow the item. For example, shields have 2 ints, but swords only 1.

Scanner read = new Scanner(new File("inventory.txt")) ;
infile.findInLine("Shield") ;


Please, how do I do this?

### #1Cuajin

Posted 05 April 2012 - 05:53 AM

I am trying to read the inventory for a game in a saved in a text file. The inventory looks like this:
Sword 5
Shield 5 10
Cake
Sword 7
Shield 1 5


I need to read from a file and as I'm reading I need to know if the line read was a Sword, Shield or a Cake. Depending on what the item is I will do different things with it. It is important to know the numbers that follow the item. For example, shields have 2 ints, but swords only 1.

Scanner read = new Scanner(new File("inventory.txt")) ;
infile.findInLine("Shield") ;


Please, how do I do this?

PARTNERS