Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: matt on Tue 23/12/2008 22:54:52

Title: script keeps getting 0 for an int but i have told it to ad one to the int before
Post by: matt on Tue 23/12/2008 22:54:52
this is the script :
distance++;
int help1 = int1/distance*size_of_the_object;

int1, distance and size_of_the_object are all ints

distance keeps coming out as zero and i don't know why.
i cheaked that distance couldn't be a negitve.

please help.
Title: Re: script keeps getting 0 for an int but i have told it to ad one to the int before
Post by: Pumaman on Tue 23/12/2008 23:38:53
If distance was 0, that line would be crashing with a divide by zero error.

How do you know that distance is 0? Have you placed a line like this before and after the "distance++" line?
Display("distance = %d", distance);
Title: Re: script keeps getting 0 for an int but i have told it to ad one to the int before
Post by: Dualnames on Wed 24/12/2008 00:28:24
int help1 = int1/distance*size_of_the_object;

distance keeps coming out as zero and i don't know why.

I do know why.

int help1 = int1/distance*size_of_the_object;

First which math should happen first?
this?
int help1 = (int1/distance)*size_of_the_object;
or this:
int help1 = int1/(distance*size_of_the_object);


Title: Re: script keeps getting 0 for an int but i have told it to ad one to the int be
Post by: matt on Wed 24/12/2008 00:49:16
Thanks both of you I will try this and see if it works ;D
Title: Re: script keeps getting 0 for an int but i have told it to ad one to the int before
Post by: Dualnames on Wed 24/12/2008 00:52:07
you can also set distance initial value to 1
int distance=1;
Title: Re: script keeps getting 0 for an int but i have told it to ad one to the int be
Post by: matt on Wed 24/12/2008 03:54:46
Thanks but the distance is calculated by the players pos and the object pos
Title: Re: script keeps getting 0 for an int but i have told it to ad one to the int before
Post by: Dualnames on Fri 26/12/2008 23:17:20
There's a probability(i'm just guessing) that the distance integer doesn't get a value before the if statement.
Title: Re: script keeps getting 0 for an int but i have told it to ad one to the int be
Post by: matt on Sat 27/12/2008 06:57:20
Thanks but I have managed to fix Ito