# Scripts That Call Themselves

**URL:** https://the.fmsoup.org/t/scripts-that-call-themselves/4533
**Category:** Lounge (Discussions)
**Tags:** scripting
**Created:** [December 7, 2024, 11:12am UTC](https://the.fmsoup.org/t/scripts-that-call-themselves/4533 "2024-12-07T11:12:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![steverichter](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/steverichter/32/1022_2.png) [@steverichter](https://the.fmsoup.org/u/steverichter)
#### Post date: [December 7, 2024, 11:12am UTC](https://the.fmsoup.org/t/scripts-that-call-themselves/4533/1 "2024-12-07T11:12:58Z")

</div>

The solution I inherited includes many scripts that check or set a parameter, and then call (re-run) the same script.

In one case, script A intentionally bypasses several pages of code. The script then sets a parameter (customer ID) and calls script A. The second time through, the script executes the previously bypassed code.

This seems somewhat inelegant, but on the plus side, this structure prevents creating two scripts when one will do the job.

Wondering if this is (or is not) considered a “best practice”?

---

<div class="post-metadata">

### Author: ![cheesus](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/cheesus/32/182_2.png) [@cheesus](https://the.fmsoup.org/u/cheesus)
#### Post date: [December 7, 2024, 1:02pm UTC](https://the.fmsoup.org/t/scripts-that-call-themselves/4533/2 "2024-12-07T13:02:54Z")

</div>

If it works it might be very clever. As long as you can handle the complexity of the script. I know this technique from PSOS Scripts, that recall themselves with a PSOS Script step, when not running on Server.

---

<div class="post-metadata">

### Author: ![bdbd](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/bdbd/32/620_2.png) [@bdbd](https://the.fmsoup.org/u/bdbd)
#### Post date: [December 7, 2024, 2:30pm UTC](https://the.fmsoup.org/t/scripts-that-call-themselves/4533/3 "2024-12-07T14:30:29Z")

</div>

This is known as re-entrant code. It has its uses. I use re-entrant code regularly, especially when dealing with global variables.

---

<div class="post-metadata">

### Author: ![steverichter](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/steverichter/32/1022_2.png) [@steverichter](https://the.fmsoup.org/u/steverichter)
#### Post date: [December 7, 2024, 2:38pm UTC](https://the.fmsoup.org/t/scripts-that-call-themselves/4533/4 "2024-12-07T14:38:02Z")

</div>

Yes, I have one such script with three branches, each of which sets a global variable to hide various buttons. The whole thing is somewhat complicated, which is what prompted me to inquire about whether this structure is recommended or not.

---

<div class="post-metadata">

### Author: ![Malcolm](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/malcolm/32/196_2.png) [@Malcolm](https://the.fmsoup.org/u/Malcolm)
#### Post date: [December 7, 2024, 8:59pm UTC](https://the.fmsoup.org/t/scripts-that-call-themselves/4533/5 "2024-12-07T20:59:25Z")

</div>

> [@steverichter](#):
>
> The solution I inherited includes many scripts that check or set a parameter, and then call (re-run) the same script.

Using these scripts, it's possible to generate queues that are slower, when run like this, than when you break out the code into subscripts. I'm not sure what is going on in the compiler - and it may have changed since - but in v14 - v16 I was finding that re-entrant scripts ran more slowly than scripts that called sub-scripts.

Since then I have favoured "controller" or "router" scripts. The controller scripts do the initial checking and setting of parameters, then they call sub-scripts. Often the sub-scripts do a second round of routing.
