Page 1 of 1

[20 Dec 2009] Q of Function (defining value later in code, affects it earlier?)

Posted: Sat Jun 13, 2020 5:32 pm
by Bugala
Note: This is an archived post that was originally sent to the Hollywood mailing list on Sun, 20 Dec 2009 05:31:27 -0000

I just spent close to hour bug hunting until i finally hunted reason down and it surely was about last thing anymore to try.

code example:

Code: Select all

1: Function p_snowballthrowing
2: Speed = throwpower*1
3: throwpower=0
4: EndFunction
When i enter in my program to that function, value of throwpower is something between 1-100.

Strange thing is, that if i leave this program this way, it refuses to work right, but stops my snowball flying rightaway (Speed = 0).

But if i delete line 3 (throwpower=0) out of program, then it works fine.

So my question is:

How can it be, that affecting some value at later point in Function, affects that value at earlier point?

Is this a bug, have i missed something, or dont i understand the innerworks of hollywood at all?

[20 Dec 2009] Re: Q of Function (defining value later in code, affects it earlier?)

Posted: Sat Jun 13, 2020 5:32 pm
by Bugala
Note: This is an archived post that was originally sent to the Hollywood mailing list on Sun, 20 Dec 2009 05:36:59 -0000

Ah forget this...

I finally found the bug. Works right now.

[20 Dec 2009] Re: Q of Function (defining value later in code, affects it earlier?)

Posted: Sat Jun 13, 2020 5:32 pm
by Allanon
Note: This is an archived post that was originally sent to the Hollywood mailing list on Sun, 20 Dec 2009 15:31:35 -0000

Your code works for just one time because unless you set throwpower to a value after you exit the function, speed will be zero. I suppose you are calling your function inside a loop, try to add a debugprint to your code:

Code: Select all

1 : Function p_snowballthrowing
2 : Speed = throwpower*1
3 : throwpower=0
3b: DebugPrint("throwpower:", throwpower)
4 : EndFunction
You should notice that the first time you enter the function throwpower is not zero. These are only suppositions because I can't imagine how you have structured your code.

Regards, Fabio