Listen, I know this code is absolute garbage, and I know it can be shortened down more than 100+ lines. I've spent two hours expanding and debugging everything until I finally decided to wave the white flag and attempt to get some help on a forum. Essentially, I am trying to get as much info about the parabola of a quadratic to test my abilities. The problem doesn't actually have to do with the math though.

Shield your eyes, because this will be the most unnecessarily long code you'll ever see.

local plr = game:GetService("Players").LocalPlayer
local main = script.Parent.Background
local input = main.InputStation
local output = main.OutputStation
local a_in = input.aInput.Text
local b_in = input.bInput.Text
local c_in = input.cInput.Text
local dir_output = output.dir.Text
local mip_output = output.mip.Text
local vert_output = output.vert.Text
local y_int_output = output.y_int.Text
local aos_output = output.aos.Text
local button = input.calculate
local dir
local mip
local vert
local y_int
local aos
local notnil = true
local a_input = "debug_a"
local b_input = "debug_b"
local c_input = "debug_c"
--22 lines dedicated to just defining variables. (god please help me)
--a,b,c_inputs are set to debug values so I can see if the if statement never sets them.

button.MouseButton1Click:Connect(function()
	if a_in == "0" then
		a_input = 0
	elseif a_in == "1" then
		a_input = 1
	elseif a_in == "2" then
		a_input = 2
	elseif a_in == "3" then
		a_input = 3
	elseif a_in == "4" then
		a_input = 4
	elseif a_in == "5" then
		a_input = 5
	elseif a_in == "6" then
		a_input = 6
	elseif a_in == "7" then
		a_input = 7
	elseif a_in == "8" then
		a_input = 8
	elseif a_in == "9" then
		a_input = 9
	elseif a_in == "10" then
		a_input = 10
	elseif a_in == "11" then
		a_input = 11
	elseif a_in == "12" then
		a_input = 12
	elseif a_in == "13" then
		a_input = 13
	elseif a_in == "14" then
		a_input = 14
	elseif a_in == "15" then
		a_input = 15
	elseif a_in == "16" then
		a_input = 16
	elseif a_in == "17" then
		a_input = 17
	elseif a_in == "18" then
		a_input = 18
	elseif a_in == "19" then
		a_input = 19
	elseif a_in == "20" then
		a_input = 20
	end
	if b_in == "0" then
		b_input = 0
	elseif b_in == "1" then
		b_input = 1
	elseif b_in == "2" then
		b_input = 2
	elseif b_in == "3" then
		b_input = 3
	elseif b_in == "4" then
		b_input = 4
	elseif b_in == "5" then
		b_input = 5
	elseif b_in == "6" then
		b_input = 6
	elseif b_in == "7" then
		b_input = 7
	elseif b_in == "8" then
		b_input = 8
	elseif b_in == "9" then
		b_input = 9
	elseif b_in == "10" then
		b_input = 10
	elseif b_in == "11" then
		b_input = 11
	elseif b_in == "12" then
		b_input = 12
	elseif b_in == "13" then
		b_input = 13
	elseif b_in == "14" then
		b_input = 14
	elseif b_in == "15" then
		b_input = 15
	elseif b_in == "16" then
		b_input = 16
	elseif b_in == "17" then
		b_input = 17
	elseif b_in == "18" then
		b_input = 18
	elseif b_in == "19" then
		b_input = 19
	elseif b_in == "20" then
		b_input = 20
	end
	if c_in == "0" then
		c_input = 0
	elseif c_in == "1" then
		c_input = 1
	elseif c_in == "2" then
		c_input = 2
	elseif c_in == "3" then
		c_input = 3
	elseif c_in == "4" then
		c_input = 4
	elseif c_in == "5" then
		c_input = 5
	elseif c_in == "6" then
		c_input = 6
	elseif c_in == "7" then
		c_input = 7
	elseif c_in == "8" then
		c_input = 8
	elseif c_in == "9" then
		c_input = 9
	elseif c_in == "10" then
		c_input = 10
	elseif c_in == "11" then
		c_input = 11
	elseif c_in == "12" then
		c_input = 12
	elseif c_in == "13" then
		c_input = 13
	elseif c_in == "14" then
		c_input = 14
	elseif c_in == "15" then
		c_input = 15
	elseif c_in == "16" then
		c_input = 16
	elseif c_in == "17" then
		c_input = 17
	elseif c_in == "18" then
		c_input = 18
	elseif c_in == "19" then
		c_input = 19
	elseif c_in == "20" then
		c_input = 20
	end
	print("debug "..tostring(a_input))
	print("debug "..tostring(b_input))
	print("debug "..tostring(c_input))
	print("debug2 "..input.aInput.Text)
	print("debug2 "..input.bInput.Text)
	print("debug2 "..input.cInput.Text)
	--Just some debug code because of course I messed up somewhere. (edit: the bug literally causes a paradox... how???)
	
	if a_input == nil then
		notnil = false
	else
		notnil = true
	end
	--[[ Tests to see if only 'a' is nil, because I'm too lazy to have it check each one. (aka I'm expecting that
																						   the user will have all
																						   of them blank and not
																						   just 'a' filled out. 
																						   I suck and I should 
																						   feel bad for writing 
																						   this garbage code.    ]]--
	
	if notnil == true then
		if a_input > 0 then
			dir = "up"
		else
			dir = "down"
		end
		--If 'a' is positive then the dir is set to up. Else down.
		
		y_int = c_input
		--Since the y-intercept is always c, it is defined here as the c value.
		
		aos = -1*b_input/(2*a_input)
		--Does some boring math and then, boom, the axis of symmetry has been calculated.
		
		vert = a_input*(aos^2)+(b_input*aos)+c_input
		--Does even more boring math, and then the vertex has been defined.
		
		if aos == 0 then
			mip = "(0,"..y_int..") MIP is same as y-int because AOS is 0"
		else
			mip = "("..b_input*(-1)..","..y_int..")"
		end
		--Who even cares anymore... Defines the mirror image point.
		
		dir_output = "The parabola will point "..dir.."wards."
		y_int_output = "The Y-intercept will be (0,"..y_int..")"
		aos_output = "The axis of symmetry is "..aos.."."
		vert_output = "The vertex of the parabola is ("..aos..","..vert..")"
		mip_output = "The mirror image point is at "..mip
		--Sets text in the TextLabels appropriately.
		
		
		
	else
		print("User put in a nil value.")
	end
	--If my garbage code returns that it's not blank, it runs the code, else it prints that the user put in a nil value.
end)

Output:

18:26:50.624  debug debug_a  -  Client - main:155
  18:26:50.624  debug debug_b  -  Client - main:156
  18:26:50.625  debug debug_c  -  Client - main:157
  18:26:50.625  debug2 1  -  Client - main:158
  18:26:50.625  debug2 2  -  Client - main:159
  18:26:50.625  debug2 3  -  Client - main:160
  18:26:50.626  Players.EnderVolts.PlayerGui.Container.main:177: attempt to compare number and string  -  Client - main:177
  18:26:50.626  Stack Begin  -  Studio
  18:26:50.627  Script 'Players.EnderVolts.PlayerGui.Container.main', Line 177  -  Studio - main:177
  18:26:50.627  Stack End  -  Studio

Object structure (if that comes to any use:) https://prnt.sc/11h54qu


Essentially what the contradictory thing is, is that a,b,c_inputs never actually get set by the if statements. a_in is 1, b_in is 2, and c_in is 3. This should theoretically stimulate the if statement and have it set the value to one as if a_in == "1" then a_input = 1. But it doesn't, and I don't understand why. Help would be tremendous, as nobody would probably even want to after reading the code.

2 comments

0

I don't think you need the tostring function since they were already a string since the beggining. The way you defined them using a "" <- this thing will make them a string. (I THINK)

0

Yeah i'm PRETTY sure that's because you used a "" instead of just straight forward defining it as a_input = 1