Blitz Variable Crash
BlitzMax Forums/BlitzMax Programming/Blitz Variable Crash
| ||
Hi, I still use the old Blitz Basic 2D. I have a minor issue with a variable which I would like someone to explain why it is happening. Take this... a=1 a=a+1 print a the answer is 2 fine - some of the time, yet in some parts of my programme, a+a=11 thus in a loop: a=1 For n=1 to 100 a=a+1 print a next the screen thus becomes... 1 11 111 1111 11111 and so on. Likewise a=1:b=3:print a+b the answer becomes 13 print b+a the answer becomes 31 I can see what it is doing, but why is it doing it? Thus, I have had to resort to labels like APPLES=1 BANANAS=2 print Apples+bananas answer is 3 It's not an issue, just an annoying occurance of the editor. Many thanks |
| ||
It's because you've defined a and b as strings, not as integers. In B2d, whatever you use the variable as originally is the type it will always be, for as long as the variable's scope lasts. You've probably got a reference to a$ or b$ somewhere in your code, forgotten about it, and then tried to reuse the same variables as ints. It need not be both of the variables, because if one is a string, Blitz has to convert the other to a string in order to get the result. |
| ||
Hi, Many thanks for that. Hmmmm ... now that I think about it, I may have read some data off as a$. I'll check my code - writing a super cool new game :) All the best dude |