The best way to describe the problem is, well not that easy;
There are three inputs variables which contribute to three output variables.
Each input variable correlates to an output variable.
The input variables are:
self.stance["crou"]
This value gets set to the opposite of what it was before, when the C
button is pressed down (not held down), so in basic terms (I know this isn’t a real function)
C.ButtonDown:Connect(function()
self.stance["crou"] = not(self.stance["crou"])
end)
self.stance["runn"]
This value gets set to true while the shift button is being held down, and false when it is not.
self.stance["aimi"]
This value gets set to true while the right mouse button is being held down, and false when it is not.
The three output variables are:
stance.running
stance.aiming
stance.crouching
These are set by the processing functions.
let me further explain the problem:
While running is true, neither aiming or crouching can be true
While aiming is true, crouching can be true, but running must be false
While crouching is true, aiming can be true, but running must be false
Or all the values can be false.
Basically all of the possible states:
not running and not crouching and not aiming
running and not crouching and not aiming
crouching and aiming and not running
crouching and not aiming and not running
aiming and not crouching and not running
I have created functions which manipulate outputs based only on aiming and running, and the other one only on crouching and running
of course crouching and aiming can happen at the same time so I don’t need a function for that.
For aiming and running:
If they were previously idle, running can be true if shift is being held down, or aiming can be true if right mouse button is being held down
If they were previously running, they can either stop running by stop holding shift or start aiming by holding right mouse button (while still holding shift), (releasing rmb however, will return them to running state if shift is still being held down)
If they were previously aiming they can either stop aiming by stop holding right mouse button or start running by holding shift (while still holding rmb), (releasing shift however, will return them to aiming state if rmb is still being held down)
if they previously had both buttons down and now only have one, the one which they were holding down is set to true.
For crouching and running:
If they were previously idle, they can start running by holding shift, or press c to start crouching.
If they were previously running, they can stop by stop holding shift, or start crouching by pressing c (pressing c again while crouching and holding shift will not make them start running again, both will be false)
If they were previously crouching, they can stop by pressing c again, or start running by holding c (releasing shift while crouching variable is true will not return the to crouching state, both will be false)
Each function is updated every time there is an input change for either crouching, aiming or running associated buttons
My function for running and aiming (which I should point out @Dysche wrote, very kindly):
if not aiming and not running then
stance.aiming = false
stance.running = false
else
if aiming and running then
if lastaim then
stance.aiming = false
stance.running = true
elseif lastrun then
stance.aiming = true
stance.running = false
end
elseif aiming then
stance.aiming = true
if lastrun then
stance.running = false
end
elseif running then
stance.running = true
if lastaim then
stance.aiming = false
end
end
end
My function for running and crouching:
if not crouching and not running then
stance.crouching = false
stance.running = false
else
if crouching and running then
if lastcrouch then
stance.crouching = false
stance.running = true
elseif lastrun then
stance.crouching = true
stance.running = false
end
elseif crouching then
if lastrun then
self.stance["crou"] = false
stance.running = false
else
stance.crouching = true
end
elseif running then
if lastcrouch then
stance.crouching = false
else
stance.running = true
end
end
end
I need helping putting these functions together, while retaining the functionality of both, and adding functionality when putting them together.
Thank you