| Author | Message | 
	
		| Cheese Wow Cheese is so helpful!
 
  
 Joined: Mar 18 2007
 Posts: 1017
 Offline
 
 | 
			
			  | 
				
					|  Posted: Sun Nov 25, 2007 3:54 am     Post subject: file reading |  |   |  |  
				| 
 |  
				| i was looking to write a dll for mervbot. just a simple staff list from staff.txt...
 
 
 	| 
void botInfo::gotCommand(Player *p, Command *c)
 ...
 case OP_Player:
 {
 if (c->check("staff"))
 {
 sendPrivate(p, "start");
 char line [256];
 ifstream staff;
 staff.open("staff.txt");
 if (!staff)
 {
 sendPrivate(p, "Error loading staff.txt");
 }
 staff>>line;
 while (!EOF)
 {
 sendPrivate(p, line);
 staff>>line;
 sendPrivate(p, "loop");
 }
 staff.close();
 sendPrivate(p, "end");
 }
 
 | 
 
 i added start, loop, and end for debugging.
 so it compiles and loads, but only pms you start and end.
 which means its completely ignoring my loop.
 
 also, when i remove staff.txt, theres no error.
 which means its ignoring my error too.
 
 what am i missing?
 _________________
 SSC Distension Owner
 SSCU Trench Wars Developer
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| k0zy Server Help Squatter
 
  
 Gender:
  Joined: Jan 11 2003
 Posts: 571
 Location: Germany
 Offline
 
 | 
			
			  | 
				
					|  Posted: Sun Nov 25, 2007 6:46 pm     Post subject: |  |   |  |  
				| 
 |  
				| try 
 _________________
 It's a shark! Oh my god! Unbelievable!
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Bak ?ls -s
 0 in
 
  
 Age:26
 Gender:
  Joined: Jun 11 2004
 Posts: 1826
 Location: USA
 Offline
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Cheese Wow Cheese is so helpful!
 
  
 Joined: Mar 18 2007
 Posts: 1017
 Offline
 
 | 
			
			  | 
				
					|  Posted: Sun Nov 25, 2007 8:17 pm     Post subject: |  |   |  |  
				| 
 |  
				| for some reason, those dont work =S mine dont either...
 
 also,
 why can i use sendPrivate(p, "loop");
 with "loop" and not a string?
 using char ignores whitespace in my file...
 
 ----
 
 so all that was too complicated and didnt work.
 i tried this, and it worked.
 
 however,	| case OP_Player:
{
 if (c->check("about"))
 {
 sendPrivate(p, "I display the staff list.");
 }
 if (c->check("version"))
 {
 sendPrivate(p, "staff.dll by Cheese");
 }
 if (c->check("staff"))
 {
 ifstream staff;
 staff.open("staff.txt");
 char line [256];
 while (staff.getline(line, 256))
 {
 sendPrivate(p, line);
 }
 staff.close();
 }
 }
 | 
 didnt.	|             if (staff.bad())
{
 sendPrivate(p, "Staff.txt is missing");
 }
 | 
 renaming or deleting the file didnt make anything happen.
 i tried staff.bad(), !staff.good(), !staff.exist(), and !staff.
 nothing at all
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| k0zy Server Help Squatter
 
  
 Gender:
  Joined: Jan 11 2003
 Posts: 571
 Location: Germany
 Offline
 
 | 
			
			  | 
				
					|  Posted: Mon Nov 26, 2007 5:02 am     Post subject: |  |   |  |  
				| 
 |  
				| What about staff.is_open() ? |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Bak ?ls -s
 0 in
 
  
 Age:26
 Gender:
  Joined: Jun 11 2004
 Posts: 1826
 Location: USA
 Offline
 
 | 
			
			  | 
				
					|  Posted: Mon Nov 26, 2007 8:06 am     Post subject: |  |   |  |  
				| 
 |  
				| sendPrivate needs a String, which is one of catid's classes and not built-in. If you look in mervbot source you'll see theres a constructor that takes in a const char* so it can cast it implicitly. 
 If you want to use a string, try
 
 sendPrivate(p,(String)stringVar.c_str());
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		|  |