generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Why doesnt tonumber("0") work?

Previous Thread :: Next Thread 
litalela is not online. litalela
Joined: 30 Mar 2010
Total Posts: 6267
29 Jul 2015 08:56 PM
Okay, so I made this really simple script to solve the quad formula:

script.Parent.MouseButton1Down:connect(function()
local a = tonumber(script.Parent.Parent.aVal.Text)
local b = tonumber(script.Parent.Parent.bVal.Text)
local c = tonumber(script.Parent.Parent.bVal.Text)
local answer1 = (((0 - b) + (math.sqrt((b * b) - (4 * a * c)))) / 2)
local answer2 = (((0 - b) - (math.sqrt((b * b) - (4 * a * c)))) / 2)
print(answer1, answer2)

end)

However if one of the values is 0 it breaks. Any reason why?
Report Abuse
litalela is not online. litalela
Joined: 30 Mar 2010
Total Posts: 6267
29 Jul 2015 09:01 PM
crap i forgot its 2a not 2
Report Abuse
baldo46 is not online. baldo46
Joined: 28 Jul 2008
Total Posts: 1254
29 Jul 2015 09:01 PM
Discriminant must be > 0.

There are no imaginary numbers in programming.
Report Abuse
litalela is not online. litalela
Joined: 30 Mar 2010
Total Posts: 6267
29 Jul 2015 09:03 PM
Even when discriminant is > 0 this doesnt work. e.e roblox why, this was way easier with java.

For y=x^2 + 4*x - 16 it says the roots are -2 and -2, wtf did I do wrong
Report Abuse
baldo46 is not online. baldo46
Joined: 28 Jul 2008
Total Posts: 1254
29 Jul 2015 09:08 PM
try looking at what cval is set to.. WINK WINK
Report Abuse
litalela is not online. litalela
Joined: 30 Mar 2010
Total Posts: 6267
29 Jul 2015 09:09 PM
DANG IT CHRIST I HATE MY LIFE
Report Abuse
Marzlyn is not online. Marzlyn
Joined: 15 Jun 2014
Total Posts: 4431
29 Jul 2015 09:13 PM
good catch @baldo
Report Abuse
litalela is not online. litalela
Joined: 30 Mar 2010
Total Posts: 6267
29 Jul 2015 09:14 PM
now to make it work with imaginary numbers
Report Abuse
baldo46 is not online. baldo46
Joined: 28 Jul 2008
Total Posts: 1254
29 Jul 2015 09:24 PM
answer = math.sqrt(math.abs(discriminant));

if (discriminant < 1) then
answer = "i" .. answer;
end
Report Abuse
litalela is not online. litalela
Joined: 30 Mar 2010
Total Posts: 6267
29 Jul 2015 09:25 PM
baldo i was about to make a complicated ass thing

thank you
Report Abuse
baldo46 is not online. baldo46
Joined: 28 Jul 2008
Total Posts: 1254
29 Jul 2015 09:28 PM
Make sure you don't make the answer equal that though. Remember it's (-b +- (that value)) / (2a)

So obviously some fiddling to do with it, but yourwelcome.
Report Abuse
litalela is not online. litalela
Joined: 30 Mar 2010
Total Posts: 6267
29 Jul 2015 09:36 PM



script.Parent.MouseButton1Down:connect(function()
local a = tonumber(script.Parent.Parent.aVal.Text)
local b = tonumber(script.Parent.Parent.bVal.Text)
local c = tonumber(script.Parent.Parent.cVal.Text)

local i = false
local part1 = (0-b)
local part2 = (b * b)
local part3 = (4 * a * c)
local part4 = (part2 - part3)
if part4 < 1 then
part4 = math.abs(part4)
i = true
end
local discriminant = (math.sqrt(part4))


local part6a = (part1 + discriminant)
local part6b = (part1 - discriminant)
local part7 = (2 * a)
local part8a = (part6a / part7)
local part8b = (part6b / part7)
if i == true then
local part6a = (part1 + discriminant .. "i")
local part6b = (part1 - discriminant .. "i")
local part7 = (2 * a)
local part8a = (part6a .. "/" .. part7)
local part8b = (part6b .. "/" .. part7)
print(part8a, part8b)
end
if i == false then
print(part8a, part8b)
end


end)

not perf but itll do
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image