Passing Variables in a Recursive method
I'm experimenting with Alice to create a recursive method.
I created a frog that is supposed to say a Fibonacci sequence (10 levels using recursiveness). A Fibonacci sequence is 1, 1, 2, 3, 5, 8, et cetera, where the two last numbers are added together to create the next number. I created the recursive method and set two variables to record the current value and the next number, but I'm failing to pass the number to the variables. I tried _FibNumber set value to (_FibNumber + _FibLastNumber) for the next iteration, did not work, I even tried with 3 variables but when I test, the variable doesn't change. Any ideas? I even tried to pass a regular number value to the variables but it just keeps coming back with the original value of one 
[QUOTE=gransalamandra;36708]I'm experimenting with Alice to create a recursive method.
I created a frog that is supposed to say a Fibonacci sequence (10 levels using recursiveness). A Fibonacci sequence is 1, 1, 2, 3, 5, 8, et cetera, where the two last numbers are added together to create the next number. I created the recursive method and set two variables to record the current value and the next number, but I'm failing to pass the number to the variables. I tried _FibNumber set value to (_FibNumber + _FibLastNumber) for the next iteration, did not work, I even tried with 3 variables but when I test, the variable doesn't change. Any ideas? I even tried to pass a regular number value to the variables but it just keeps coming back with the original value of one[/QUOTE] If you post your world, I could probably be more help, but from your description it seems like you are using classlevel variables instead of worldlevel. With a classlevel variable it resets itself to its original value every time you play the method. Make your variables world level instead, see if that works. 
Tau: You are a genious
That worked... I pull the variables out to the worldlevel and it worked.
I have now a frog that calculates a Fibonacci sequence using a recursive method and also created another one that uses and Astronaut using iteration. Is not homework, but I'm learning about programming concepts and the more you do, the more you understand. Best regards, Juan Primo :) 
[QUOTE=gransalamandra;36718]That worked... I pull the variables out to the worldlevel and it worked.
I have now a frog that calculates a Fibonacci sequence using a recursive method and also created another one that uses and Astronaut using iteration. Is not homework, but I'm learning about programming concepts and the more you do, the more you understand. Best regards, Juan Primo :)[/QUOTE] Glad to help! 
i need help keep getting a error
1 Attachment(s)
i cant get rid of the error and it wont calculate.

The purpose of a function is to return a value. The big problem I see is that you have created an endless string of calls to the same function.

All times are GMT 5. The time now is 09:38 PM. 
Copyright ©2017, Carnegie Mellon University
Alice 2.x © 19992012, Alice 3.x © 20082012, Carnegie Mellon University. All rights reserved.