Computer Science Canada Help with Interger Overflow |
Author: | ZeroPaladn [ Fri May 12, 2006 8:17 am ] | ||||
Post subject: | Help with Interger Overflow | ||||
Hi guys, been a long time since I've made a post here, but here it is. I have a bunch of variables inside a record, most of which are ints and reals. One of them just so happens to be a max hp one. maxhp is defined by a formula...
of course, this is a game where you can save your stats, so I have the stamina stat being read form the text file...
anyways, to the point, after reading from the file, and crunching the number to get maxhp, there is an Interger Overflow in "round". Can anyone help me out here? |
Author: | codemage [ Fri May 12, 2006 8:41 am ] |
Post subject: | |
Have you "put" out the value you're trying to round (before rounding) to make sure it's a valid int? |
Author: | ZeroPaladn [ Fri May 12, 2006 11:43 am ] | ||||
Post subject: | |||||
this problem only happens when i try to get players (1).sta from a text file. This doesn't happen when i declare the variable inside the program itself. I will post the source code i have now, as it may make it much more clear. NOTE The text file should look as follows...
Here is the source code.
Thanks for the help guys. |
Author: | do_pete [ Fri May 12, 2006 11:49 am ] | ||
Post subject: | |||
No, if it wasn't an integer it would say "Argument is wrong type". If it says "Overflow in Integer expression" then the integer is greater than maxint. For example:
will give you this error |
Author: | Delos [ Fri May 12, 2006 11:57 am ] |
Post subject: | |
For now go with codemage's suggestion and put the values of the player(1). record. In other words, dump the contents at the end of readstats. Post up what you get...might shed some light on this. |
Author: | ZeroPaladn [ Fri May 12, 2006 12:01 pm ] |
Post subject: | |
hm... so your saying that my program is giving the variable players (1).maxhp a number higher than maxint... impossible. It isnt going higher than 100! |
Author: | ZeroPaladn [ Fri May 12, 2006 12:06 pm ] |
Post subject: | |
disturbing... 168367746 for str 168367746 for sta 168367746 for spd -2147470030 for dex |
Author: | Cervantes [ Fri May 12, 2006 4:00 pm ] | ||
Post subject: | |||
ZeroPaladn wrote: disturbing...
168367746 for str 168367746 for sta 168367746 for spd -2147470030 for dex That character is strong like bull. Agile like fence post. Try breaking your code up into chunks. I haven't looked closely at the code, but my first suspicion is there's something wacky with the file. Try eliminating (copy and paste all the code into a new file first) the excess code and just see what happens with reading the data in then outputting it. Are you sure you need that : 2 in the read lines?
Are you sure you should be using read as opposed to get? ie. Did you manually input the data, or did you use Turing to input it with write? |
Author: | NikG [ Fri May 12, 2006 5:58 pm ] | ||
Post subject: | |||
This seems to work... so the problem is definately with the read. |
Author: | MysticVegeta [ Sat May 13, 2006 8:11 pm ] |
Post subject: | |
Turing Reference wrote: The read statement inputs each of the readItems from the specified file. These items are input directly using the binary format that they have on the file. In other words, the items are not in source (ASCII or EBCDIC) format. In the common case, these items have been output to the file using the write statement.
By contrast, the get and put statements use source format, which a person can read using an ordinary text editor. Well as you can see until you write to the text file using the write command, you wont be able to read it with the read command. so just use the flexible get and put like NikG did |
Author: | ZeroPaladn [ Sat May 13, 2006 9:09 pm ] |
Post subject: | |
Thanks guys, ill fix that up when i get to school on monday, and ill post the results. |
Author: | ZeroPaladn [ Mon May 15, 2006 11:35 am ] |
Post subject: | |
Thanks guys, It worked! |