forums

TNT Basic Forums > Bugs!
Local Variable bug!
< Last Thread     Next Thread >
Author
Thread        Post A Reply

01-01-2004 15:29

Posted by:
kemalyun

Location:
Frankfurt/Germany

Find more posts by kemalyun

In my program, the local variable i isn't really local. When checkarrowcollision() is called, it recognizes, for example, the collision between sprite i=3 and 21, adds the score, but turns off another sprite (i.e. number 5) instead of number 3, because i is used in procedure showvalues(), which is being called by showvaluescore(). When I replace the variable i in checkarrowcollision() with another name, then it works. This means, although i is a local variable and should be usable in both procedures with different values, it somehow influences each other.

I also had some problem with something like this:

a=a+3

which didn't work, but when I wrote it like this

a = a + 3

then it worked. Strange!

Here's the code:
'----------------------------------------------------------
procedure checkarrowcollision()
int i
for i=1 to 20
if killable=true and sprite col (i,21)=21
score=score+100 'this is a global int
showvaluescore()
arrowunterwegs=1 'this is a global int!
sprite off i
end if
next i
end proc
'----------------------------------------------------------
procedure showvaluescore()
showvalues(570,576,score,6,20)
end proc
'----------------------------------------------------------
procedure showvalues(int xp, int yp, int value, int digits, int breite)
int laenge=string length(as string(value))
int i
if laenge<digits
for i=1 to digits-laenge
paste image xp,yp,57
xp=xp+breite
next i
end if
for i=1 to laenge
paste image xp,yp,57+as number(get char(as string(value),i))
xp=xp+breite
next i
end proc

01-01-2004 19:22

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

Can you reproduce this using a simple program that just assigns and prints out the variable 'i' from different procedures?

Mark

01-01-2004 21:57

Posted by:
kemalyun

Location:
Frankfurt/Germany

Find more posts by kemalyun

Strange ...

Seems strange, but when I write a simple test program with 3 procedures calling each other in the same style like the code above, everything is fine.

But also, when I use the above code and put the SPRITE OFF i before the call showvaluescore(), then it also works, means it must have something to do with showvaluescore().

01-02-2004 23:51

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

If you can come up with a concise reproducable example of this bug it would be very much appreciated. Until then, check that variables haven't been declared as global or shared without you realising.

Cheers,

Mark

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.