Error: FileReadInt: File read back in wrong order (SOLVED)

Started by EnterTheStory (aka tolworthy), Wed 16/04/2008 22:30:32

Previous topic - Next topic

EnterTheStory (aka tolworthy)

I call the first function, then change games twice using RunAGSGame, then call the second function. And I get this error message:
in misc code (line 1473)
Error: FileReadInt: File read back in wrong order
Any idea what's wrong?
And why line 1473 is any different from the others?

(Global.Get and Global.Gets are from the DeNGVaT module. They call an int or a string. None of them have been set before this code is run. If DeNGVaT calls a variable that does not exist, the variable is created.)

Code: ags

function write_between_games() 
{	File	*output;
	int	i;		int	status;		int myInt;
	String str;
	output = File.Open("between games.dat", eFileWrite);
	if (output==null)	status = false;			// Open file
	else 
	{	status = true;											// Write data
		str =Global.Gets("rightClickedObject");				output.WriteString(str);
		str =Global.Gets("rightClickedObjectRoom");		output.WriteString(str);
		str =Global.Gets("cutscene_waiting");					output.WriteString(str);
		myInt =Global.Get("rightClickedObjectPerson");output.WriteInt(myInt);
		myInt =Global.Get("rightClickedPerson");			output.WriteInt(myInt);
		myInt =Global.Get("rightClickedPersonRoom");	output.WriteInt(myInt);
		myInt =Global.Get("rightClickedPersonX");			output.WriteInt(myInt);
		str 	=Global.Gets("rightClickedPersonGame");	output.WriteString(str);
		output.Close();
	}
	return status;
}
function read_between_games() 
{	File	*input;
	int	i;		int	status;		int myInt;
	String str;
	input = File.Open("between games.dat", eFileRead);
	if (input==null)	status = false;			// open file
	else 																	// Read data				
	{	status = true;
		if(input.EOF)return; str	= input.ReadStringBack(); Global.Sets("rightClickedObject",str);			
		if(input.EOF)return; str	= input.ReadStringBack(); Global.Sets("rightClickedObjectRoom",str);	
		if(input.EOF)return; str	= input.ReadStringBack(); Global.Sets("cutscene_waiting",str);				
		if(input.EOF)return; str	= input.ReadStringBack();																				
		if(input.EOF)return; myInt = input.ReadInt();      Global.Set("rightClickedObjectPerson",myInt);				
		if(input.EOF)return; myInt = input.ReadInt();      Global.Set("rightClickedPerson",myInt);		
		if(input.EOF)return; myInt = input.ReadInt();      Global.Set("rightClickedPersonRoom",myInt);
		if(input.EOF)return; myInt = input.ReadInt();      Global.Set("rightClickedPersonX",myInt);		// line 1473
		if(input.EOF)return; str	= input.ReadStringBack(); Global.Sets("rightClickedPersonGame",str);
						if(testmode) Display("right clicked person is '%d', RightClickObject is '%s'",Global.Get("rightClickedPerson"),Global.Gets("rightClickedObject"));
		input.Close();	
	}
	return status;
}

Taking a cue from the error message, I tried reading back the lines in the opposite order, but got the same error message from the same line, 'rightClickedPersonX'. Any suggestions?

Pumaman

You've got this line:

Code: ags

if(input.EOF)return; str = input.ReadStringBack(); 


which doesn't correspond to a WriteString line in the other block of code.

Therefore you're writing 3 strings, 4 ints and a string.
But then reading back 4 strings, 4 ints and a string.

EnterTheStory (aka tolworthy)

Ah! it's obvious now you point it out! I'd added that line because I intended to leave a "spare" string for future use, then never paid attention to it. Thanks!

SMF spam blocked by CleanTalk