Advertisement Jump to content
Sign in to follow this  

Read from a file

This topic is 1758 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



I'm trying to read a some int values from a file but I'm getting wrong values. Here is my code:

			width = parseInt(line);
			height = parseInt(line);
			for(int i = 0; i < height; i++){

				for(int j = 0; j < width; j++){
					int num;
					uint num2 = 32;
					num = bg.readInt(8);
					//background[i][j] = i;
					print(num2 + " " + num + "\n");
			print("Não foi possível abrir o arquivo.");

Share this post

Link to post
Share on other sites

Is the file in binary format or text format?


readLine is meant to be used for files in text format, and readInt for files in binary format. You most likely don't want to use both for the same file, unless the file is mixing text and binary formats.


readInt(8) will read an integer number stored in 8 bytes from the file and return it as an int64.


You may also want to check the byte-order of the file, you can tell the file object which order to use with the member mostSignificantByteFirst.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!