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

Bool function not working?

Asked by 10 years ago

So I created this function to fire a missile and then fire the second missile if the function was called again but it only seems to fire the first missile then ceases to work

http://pastebin.com/xzADrhHX

1
Please post your code in a Lua block in your question. NotsoPenguin 705 — 10y

2 answers

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
10 years ago
01function fire() -- Pew pew
02    local mWasMissileFired = false
03 
04    if mWasMissileFired == false then
05        mWasMissileFired = true
06        main.Parent.Safe.Missiles.Missile:BreakJoints()
07        wait (0.05)
08        main.Parent.Safe.Missiles.Missile.Launch.Disabled = false       -- This is not a good way to run scripts
09    else
10        print 'Worked!'
11        main.Parent.Safe.Missiles.Missile2:BreakJoints()
12        wait (0.05)
13        main.Parent.Safe.Missiles.Missile2.Launch.Disabled = false  -- This is not a good way to run scripts
14        mWasMissileFired = false
15    end
16end

I recommend putting the whole launch missile script as a separate function, then add a plethora of boolean variables (assuming you only want the 2 missiles to fire and those 2 missiles only. You could add a regen function to restart the whole process):

01function Launch()
02    --[[ Your launch function here ]]
03end
04 
05function Launch2()
06    --[[ Your launch function here ]]
07end
08 
09function fire() -- Pew pew
10    local mWasMissileFiredOnce = false
11    local mWasMissileFiredTwice = false
12    local debounce = true
13    if mWasMissileFiredOnce == false and mWasMissileFiredTwice == false and debounce == true then
14        debounce = false
15        main.Parent.Safe.Missiles.Missile:BreakJoints()
View all 31 lines...

But assuming that you don't want a regen function, that you wanted to reload the missiles after a set amount of time or something. Well, you'd have to get rid of the BreakJoints() method and instead make a new part as a missile.

01mWasMissileFiredOnce = false
02mWasMissileFiredTwice = false
03debounce = true
04FinishedShooting = script.Parent.FinishedShooting
05FinishedShooting.Value = false
06-- Setting these variables to global (outside of a code block) will let other functions manipulate the variables
07 
08function Launch()
09    --[[ Your launch function here ]]
10end
11 
12function Launch2()
13    --[[ Your launch function here ]]
14end
15 
View all 46 lines...
0
So I used your first option as the second one ended up breaking the rest of the script (Don't know exactly why, think it was something regarding the Boolean not being local) but for some reason it just keeps running the Launch() function and doesn't move onto Launch2() new code can be found below. Blackbrick2896 0 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

So I used your first option as the second one ended up breaking the rest of the script (Don't know exactly why, think it was something regarding the Boolean not being local) but for some reason it just keeps running the Launch() function and doesn't move onto Launch2()

*Note chached "Missile" to "Missile1" dissolved "Launch" script & merged with Launch() functions

01function Launch()
02        wait (0.2)
03 
04        main.Parent.Safe.Missiles.Missile1.Fired:Play()
05 
06    local a = Instance.new('BodyThrust')
07        a.force = Vector3.new(0, 4105, 125000)
08        a.location = Vector3.new(0, 0, 0)
09        a.Parent = main.Parent.Safe.Missiles.Missile1
10 
11    wait (0.5) -- Safety percaution to avoid self destruction
12 
13    main.Parent.Safe.Missiles.Missile1.Explode.Disabled = false
14end
15 
View all 51 lines...
0
Do not use the Answers to reply to somone; It signifies that the Question has been answer, use Comments instead. TheeDeathCaster 2368 — 10y

Answer this question