How do functions work loop-wise?

I'm building a robot that can do multiple jobs so in my void loop() I'll have a menu to select which option the user wants to do which I have yet to program. I have all my code pasted below but the main focus is friendSafari() and analogValue(). My scenario is this: Let's say I got my menu working and I select the option Friend Safari which calls friendSafari(), I want friendSafari to keep looping constantly until either A. The user terminates the program or B. It finds a shiny Pokemon which calls shinyPokemon() which just makes an RGB light go different colors and stop the program essentially (Indicated by the photoresistor getting a read of under a certain light level after 11.3 seconds of the light level dropping the first time) During the friendSafari() function I need to result my variable "Value" over and over and over and over so that I get the timing right so I wanted to make it its own function.

My big question is:

How do I get my program to keep looping friendSafari() after getting redirected from void loop() while getting my "value" variable updated from another function while still running friendSafari() but then once the special case happens quit friendSafari() and go to shinyPokemon() for the rest of time.

Code: (Most of it is a WIP and I'm sorry if it's messy I figured it's best to post all of the code so I don't miss anything)

https://pastebin.com/WKyKhQkD

I figured it's best to post all of the code so I don't miss anything

That is true. But, post it HERE, unless you plan to post your problem in the rubbish bin, too, and ask the moderators to delete this post.

VulcanSpawnWolf: How do I get my program to keep looping friendSafari() after getting redirected from void loop() while getting my "value" variable updated from another function while still running friendSafari()

I suspect you have somewhat the wrong concept in mind. Your friendSafari() function should be called repeatedly from loop() - as should all the other functions that you want to operate.

Have a look at how the code is organized in Several Things at a Time

Note how each function runs very briefly and returns to loop() so the next one can be called. None of the functions tries to complete a task in one call. And there may be dozens of calls to a function before it is actually time for it to do anything.

...R

PS ... please post your code in this Forum so we don't have to go to some other website on your behalf.

My apologies about the pastebin link, I thought it was the best go-to for posting code. So if I'm understanding correctly I should only have part of my code in my function while the rest is in my loop? Under my menu option (Still not sure how that code is going to work as I'm waiting for my LCD Button Shield to ship in) I should have it call the first part of friendSafari() on loop until it finds the rare occurence in which it should go back to the main loop under X Section of my LCD menu loop and make it do something like "flag = 1;" with a "while flag == 1 {RGB Light Function} to essentially terminate the program.

VulcanSpawnWolf: waiting for my LCD Button Shield to ship in)

I'm going OT a wee bit, but is that one of these or similar? Those are very wasteful of pins, using many of your digital pins for the screen.

adafruit have I2C ones.

VulcanSpawnWolf: So if I'm understanding correctly I should only have part of my code in my function while the rest is in my loop?

That question is too vague for me to be able to answer it.

If you look at the code in the link I gave you you will see that very little of the total program code is in loop().

Also have a look at Planning and Implementing a Program for a longer example.

...R

Maybe step back to an earlier lesson Learn what a function() is, then develop separate functions to perform your individual fractional tasks. A complex task may implement several operations, which in turn could use one or more functions to perform a complex activity.

Once you have that function working, test your operating mode in loop(), and call the required function/s until that task is complete, or interrupted to do something else (has little or nothing to do with ‘interrupts’).