Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

no functions seem to be running anyone know why?

Asked by 7 years ago

i have a script where in the middle of the script there is a function that starts like this:

1function play()
2    print("playing...")

it never says "playing..."

and i have put a play() at the bottom

full code:

01local loop_phase = 1
02local playing = false
03local id = script.Id
04 
05while true do
06    wait()
07    if playing then
08        if loop_phase == 1 then
09            print("now playing: "..id.Value..".start")
10            script.Library[id.Value].start:Play()
11            wait(script.Library[id.Value].start.TimeLength)
12            loop_phase = 1
13        elseif loop_phase == 2 then
14            script.Library[id.Value].loop:Play()
15            wait(script.Library[id.Value].loop.TimeLength)
View all 43 lines...

the local id = script.Id is a string value set to "adventure"

the script will locate: script.Library[id.Value]["start"] at some point which basicly means script.Library.start

and start is a sound in a folder called adventure in the script

no errors, or the "playing..." i seriously need help

0
Because you have a loop and until that loop ends you cannot do anything... greatneil80 2647 — 7y
0
its working fine now, thanks! (i have learned something very important: loops that never end should come last) fanofpixels 718 — 7y

1 answer

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
7 years ago
Edited 7 years ago

Remember that a script is linear and performs tasks sequentially. In your problem, the problem arises because the script will start the infinite while loop and never end. Thus, the script can't progress to the code after it. If you want to fix this, the simplest and easiest way is to simply move the infinite loop after everything else. This would look like this:

01local loop_phase = 1
02local playing = false
03local id = script.Id
04 
05function play()
06    print("playing...")
07    for i=0,50,1 do
08        wait(0.01)
09        if loop_phase == 1 then
10            script.Library[id.Value].start.Volume = script.Library[id.Value].start.Volume - 0.2
11        elseif loop_phase == 2 then
12            script.Library[id.Value].loop.Volume = script.Library[id.Value].loop.Volume - 0.2
13        end
14    end
15    playing = false
View all 43 lines...
0
Adding to this, if for some reason you can't move the while loop to the end, you could use spawn() or coroutines to run them in a separate thread. mattscy 3725 — 7y
Ad

Answer this question