My code breaks and returns the error: “This function returns a value of type ?creative_prop, but the function body’s result is an incompatible value of type void.” This error only occurs when I use an else if statement. It works perfectly fine with an else statement.
Working Code:
SpawnPlatform2(Position:vector3)<transacts>: ?creative_prop =
var RandomAmount: int= 0
# places the pinball devices randomly
set RandomAmount = GetRandomInt(low:int = 1, high:int = 3)
if (RandomAmount = 1):
var SpawnedProp1: tuple(?creative_prop,spawn_prop_result) = SpawnProp(PinballTrap, vector3{X := GetRandomFloat(min:float = -200.0, max:float = 200.0), Y := GetRandomFloat(small:float = -200.0, big:float = 200.0), Z := 50.0}, MakeRotationFromYawPitchRollDegrees(Pitch := 90.0, Yaw := 0.0, Roll := 0.0))
return SpawnedProp1(0)
else:
var SpawnedProp2: tuple(?creative_prop,spawn_prop_result) = SpawnProp(PinballTrap, vector3{X := GetRandomFloat(min:float = -200.0, max:float = 200.0), Y := GetRandomFloat(small:float = -200.0, big:float = 200.0), Z := 50.0}, MakeRotationFromYawPitchRollDegrees(Pitch := 90.0, Yaw := 0.0, Roll := 0.0))
set SpawnedProp2 = SpawnProp(PinballTrap, vector3{X := GetRandomFloat(min:float = -200.0, max:float = 200.0), Y := GetRandomFloat(small:float = -200.0, big:float = 200.0), Z := 50.0}, MakeRotationFromYawPitchRollDegrees(pitch := 90.0, yaw := 0.0, roll := 0.0))
return SpawnedProp2(0)
Error Code:
SpawnPlatform2(Position:vector3)<transacts>: ?creative_prop =
var RandomAmount: int= 0
# places the pinball devices randomly
set RandomAmount = GetRandomInt(low:int = 1, high:int = 3)
if (RandomAmount = 1):
var SpawnedProp1: tuple(?creative_prop,spawn_prop_result) = SpawnProp(PinballTrap, vector3{X := GetRandomFloat(min:float = -200.0, max:float = 200.0), Y := GetRandomFloat(small:float = -200.0, big:float = 200.0), Z := 50.0}, MakeRotationFromYawPitchRollDegrees(Pitch := 90.0, Yaw := 0.0, Roll := 0.0))
return SpawnedProp1(0)
else if (RandomAmount = 2):
var SpawnedProp2: tuple(?creative_prop,spawn_prop_result) = SpawnProp(PinballTrap, vector3{X := GetRandomFloat(min:float = -200.0, max:float = 200.0), Y := GetRandomFloat(small:float = -200.0, big:float = 200.0), Z := 50.0}, MakeRotationFromYawPitchRollDegrees(Pitch := 90.0, Yaw := 0.0, Roll := 0.0))
set SpawnedProp2 = SpawnProp(PinballTrap, vector3{X := GetRandomFloat(min:float = -200.0, max:float = 200.0), Y := GetRandomFloat(small:float = -200.0, big:float = 200.0), Z := 50.0}, MakeRotationFromYawPitchRollDegrees(pitch := 90.0, yaw := 0.0, roll := 0.0))
return SpawnedProp2(0)
Does anyone know how to correctly use else if statements in functions that return a value? Thank You!