Alice Community Passing Variables in a Recursive method

 Passing Variables in a Recursive method
 gransalamandra Guest   Status: Posts: n/a Passing Variables in a Recursive method - 05-31-2011, 08:38 AM 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 Last edited by gransalamandra; 05-31-2011 at 08:39 AM. Reason: added information
TauTrumpsPi
Senior Member

Status: Offline
Posts: 399
Join Date: Mar 2011
Location: The diamond layer
05-31-2011, 01:25 PM

Quote:
 Originally Posted by gransalamandra 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
If you post your world, I could probably be more help, but from your description it seems like you are using class-level variables instead of world-level. With a class-level variable it resets itself to its original value every time you play the method. Make your variables world level instead, see if that works.

--------------------------------------------------------------------------------------------------------------------------
I have plenty of common sense. I just choose to ignore it.
-Calvin and Hobbes

 Tau: You are a genious
 gransalamandra Guest   Status: Posts: n/a Tau: You are a genious - 05-31-2011, 04:45 PM That worked... I pull the variables out to the world-level 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 :-)
TauTrumpsPi
Senior Member

Status: Offline
Posts: 399
Join Date: Mar 2011
Location: The diamond layer
05-31-2011, 07:01 PM

Quote:
 Originally Posted by gransalamandra That worked... I pull the variables out to the world-level 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 :-)

--------------------------------------------------------------------------------------------------------------------------
I have plenty of common sense. I just choose to ignore it.
-Calvin and Hobbes

 i need help keep getting a error
datgurlindia96
Junior Member

Status: Offline
Posts: 2
Join Date: Oct 2015
i need help keep getting a error - 12-02-2015, 08:40 AM

i cant get rid of the error and it wont calculate.
Attached Files
 Fibonacci Numbers.a2w (1.44 MB, 4 views)

 MrMoke Senior Member     Status: Offline Posts: 501 Join Date: Sep 2007 Location: Austin, Texas 12-02-2015, 12:58 PM 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. Last edited by MrMoke; 12-02-2015 at 01:02 PM.

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops General Discussion     Questions and Comments     The Lounge