Jump to content

math operation issues


testgenord1
 Share

You are about to reply to a thread that has been inactive for 1046 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi!
I've got the following function:

integer distance = 20;
float move = 5.0;
integer imove;
integer way;
integer count;


step()
{
    oldPosition = llGetPos();
    llSetLinkPrimitiveParamsFast(1, [PRIM_POSITION, oldPosition + <move,0.0,0.0>]);
    ++count;
    llOwnerSay("count = " + (string)count);
    imove = (integer)move;
    llOwnerSay("imove = " + (string)imove);
    way = imove * count;
    llOwnerSay("way = " + (integer)count);
    if(way >= distance)
    {
      ... do something

Each time the object moves forward in the x-direction,
a counter counts this step ("count").

The integer "way" is supposed to be the distance the object is travelling ("move"/ "imove") multiplied by the number of steps ("count") .

This means the function is supposed to measure the way the object has travelled from its starting point as follows:

(integer imove is "5".)

way = 5 * 1 = 5

(++count)

way = 5 * 2 = 10

(++count)

way = 5 * 3 = 15

When the "way" has reached a certain length ("distance"), something else is supposed to happen.

 

However, for whatever reason, the result of "way = imove * count" always turns out to be:

way = 1 * 1 = 1

(++count)

way = 1 * 2 = 2

(++count)

way = 1 * 3 = 3

 

I just can't find out why "imove" always turns out as equal to "1".

Do you maybe have an idea?

Thank you very much in advance!

Link to comment
Share on other sites

So imove is always ending up as 1, not 5? If you set imove explicitly to 5 does it work as expected?

 

By the way, in your llOwnerSay statements, when you chat out the final value of way, you are actually chatting out count?

Edited by Profaitchikenz Haiku
  • Like 1
Link to comment
Share on other sites

Thank you very much for your quick reply.

I ended up writing the script once more from scratch and the problem seems to be solved.

I still haven't found out why this occured, but I guess it was more caused by other parts of the script.

Should I run into more trouble, I'll come back again.
 

So far it's looking good.

So, thank you very much, once again! 🙂

  • Like 1
Link to comment
Share on other sites

Should you find yourself facing this sort of problem again, the way to try and track down what's happening is similar to putting a trace or watch on a variable in a debugger:

Go through the script looking for every place where that particular variable has a value assigned to it or it's value changed, and add an llOwnerSay statement to identify where in the script it is, and what the value is. Quite often, this exercise will uncover the mistake and you won't even need to run with the llOwnerSay outputs.

The sort of situation you are looking for is where you have passed a global variable to a function and that function tries to alter it by assigning a new value to the input argument (questionable action), or where you have thought you are using a local variable with the same name ( one of the biggest recipes for disaster), or where you hav e assignd tthe right value but then in a subsequent function call, a default value is re-assigned as part of another operation.

More often than not, however, the problem is as simple as getting confused between similar sounding names

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1046 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...