Source language: Translate to:

Calling a subroutine from a subroutine

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Calling a subroutine from a subroutine

Postby dpayer » Thu Dec 08, 2011 9:22 am

Besides the issue of looping, is there a technical problem of calling subroutines from within another subroutine?

I am finding it clearer to separate out all my processes into functions or subroutines and then just call them. I find I need some of those processes within a sub routine that are part of another subroutine.

David P.
User avatar
dpayer
 
Posts: 1384
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Gaev » Thu Dec 08, 2011 11:32 am

David P.:

I use GoSub within GoSub all the time ... sometimes nested 4 deep ... no problem at all.

Just make sure you don't start chasing your tail e.g.
Code: Select all
:John
GoSub "Mary"
Return

:Mary
GoSub "John"
Return
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Nesting gosubs

Postby carlos torres » Thu Dec 08, 2011 2:59 pm

Hi dpayer

I thing that the Gaev suggestion is a good one and mandatory!

More than 4 levels of nesting meke difficult to follow the program logic.

regards

carlost
User avatar
carlos torres
 
Posts: 289
Joined: Mon May 02, 2005 8:14 am
Location: Pamplona, Colombia

Postby andybrock » Fri Dec 23, 2011 6:40 am

I've got some code that calls gosubs recursively without any issue.

Andy
User avatar
andybrock
 
Posts: 181
Joined: Mon Apr 20, 2009 1:38 pm
Location: Somerset, UK

Postby Gaev » Fri Dec 23, 2011 10:27 am

Andy:

You can call subroutines recursively ... what you need to avoid is ... a never ending loop ... like the simple example in my previous post ... something like this is fine ...
Code: Select all
:Recursive
If "[myCount]" ">=" "5"
   SetVar "[myCount]" "[myCount]-1"
   GoSub "Recursive"
Else
   Return
EndiIf
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 2 guests

cron