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

Combining two functions into one?

Asked by 9 years ago

How would I go about merging the deplete() function into the fuel() function where it calls for the deplete() function to run in line 6?

local fuelFull = true
local started = false

function fuel()
        if fuelFull == true and started == false then
            deplete()
            print 'STARTING DEPLETING'
        elseif fuelFull == false then
            print 'EMPTY'
        end
end


function deplete()
    started = true
    print 'DEPLETING'
    while true do
    script.Parent.FuelValue.Value = script.Parent.FuelValue.Value -1
    wait (.1)
    if script.Parent.FuelValue.Value <15 and script.Parent.FuelValue.Value >0 then
        print 'LOW FUEL'
    elseif script.Parent.FuelValue.Value >15 and script.Parent.FuelValue.Value >0 then
        print 'SAFE'
    elseif script.Parent.FuelValue.Value <15 and script.Parent.FuelValue.Value >-1 then
        print 'EMPTY'
        fuelFull = false
        started = false
    end
    end
end

script.Parent.Touched:connect(fuel) 


0
Have you tested this? It looks fine to me. Discern 1007 — 9y
0
I have tested it withing a much, much larger script and something about it being in two different functions causes a part of the larger script to partially break. Blackbrick2896 0 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Try re-ordering when you declare functions. Declare the deplete function before declaring the fuel function.

0
How would I do that? To me it looks like it needs to be in this order. Blackbrick2896 0 — 9y
0
It's easy. Just copy paste the deplete function behind the fuel function. What you're doing is you're using deplete() before it's declared, so it results in an error. aquathorn321 858 — 9y
Ad

Answer this question