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: I need a new way to write a calculator code.

Previous Thread :: Next Thread 
WolfgangVonPrinz is not online. WolfgangVonPrinz
Joined: 24 Oct 2013
Total Posts: 4656
06 Jul 2015 11:11 AM
So, I've written a fairly ugly, length (211 lines) bit of code, which is capable of simple arithmetic. i.e It can multiply, divide, subtract and add one digit numbers. But I want a new way to write the calculator, using cleaner, more efficient code. I also need a way to do multi digit sums.

Instead of the code to do it, I would prefer the methodology and maybe an tiny extract of the code I would use.
You can find the script I originally wrote here, I haven't pasted it out as it just looks like a mass of text: https://scriptinghelpers.org/questions/19403/
▲☭⎊▲Obama is a giant overlord space lizard▲⎊☭▲
Report Abuse
lateregistration is not online. lateregistration
Joined: 02 Apr 2013
Total Posts: 2630
06 Jul 2015 11:15 AM
ADDITION: X+Y
SUBTRACTION: X-Y
MULTIPLICATION: X*Y
DIVISION: X/Y

--IF YOU'RE ADVANCED (ONLY TRY THIS ONE IF YOU'RE FEELING DARING):

EXPONENT: X^Y
Report Abuse
WolfgangVonPrinz is not online. WolfgangVonPrinz
Joined: 24 Oct 2013
Total Posts: 4656
06 Jul 2015 11:18 AM
... I wrote a calculator which actually does that, but I struggle to assign x and y their values beyond a single digit.

▲☭⎊▲Obama is a giant overlord space lizard▲⎊☭▲
Report Abuse
Locard is not online. Locard
Joined: 13 Apr 2014
Total Posts: 3516
06 Jul 2015 11:18 AM
MODULUS, DON'T FORGET MODULUS

X%Y
Report Abuse
WolfgangVonPrinz is not online. WolfgangVonPrinz
Joined: 24 Oct 2013
Total Posts: 4656
06 Jul 2015 11:18 AM
Is everyone on this forum like this?

▲☭⎊▲Obama is a giant overlord space lizard▲⎊☭▲
Report Abuse
Locard is not online. Locard
Joined: 13 Apr 2014
Total Posts: 3516
06 Jul 2015 11:24 AM

No, we're just speaking like this because calculation is extremely easy. If you need to add more digits then just add more digits.

1 + 10 = 11

1 + 100 = 101

etc etc etc

Are you sure you'e not talking about decimal places? They're pretty easy too.

Also, if you want us to help out with any code you may already have, it's best to show us so we can point out the issue.
Report Abuse
WolfgangVonPrinz is not online. WolfgangVonPrinz
Joined: 24 Oct 2013
Total Posts: 4656
06 Jul 2015 11:29 AM
No, I wrote a code for a calculator. So when you touch 9, 8 and the divide sign, it divides 9 by 8.

It's pretty ugly.

Num1 = workspace.No1
Num2 = workspace.No2
Num3 = workspace.No3
Num4 = workspace.No4
Num5 = workspace.No5
Num6 = workspace.No6
Num7 = workspace.No7
Num8 = workspace.No8
Num9 = workspace.No9
Sub = workspace.Su
Add = workspace.Ad
Multi = workspace.Ti
Div = workspace.Di
h = Instance.new("Hint", workspace)

i = 0

x = 0

y = 0

db1 = false
function onTouched()
if db1 == true then end
db1 = true
if i == 0 then
i = 1
elseif x == 0
then x = 1
end
wait(2)
db1 = false
end

Num1.Touched:connect(onTouched)

db2 = false
function onTouched2()
if db2 == true then end
db2 = true
if i == 0 then
i = 2
elseif x == 0 then
x = 2
end
wait(2)
db2 = false
end

Num2.Touched:connect(onTouched2)

db3 = false
function onTouched3()
if db3 == true then end
db3 = true
if i == 0 then
i = 3
elseif x == 0 then
x = 3
end
wait(2)
db3 = false
end

Num3.Touched:connect(onTouched3)

db4 = false
function onTouched4()
if db4 == true then end
db4 = true
if i == 0 then
i = 4
elseif x == 0 then
x = 4
end
wait(2)
db4 = false
end

Num4.Touched:connect(onTouched4)

db5 = false
function onTouched5()
if db5 == true then end
db5 = true
if i == 0 then
i = 5
elseif x == 0 then
x = 5
end
wait(2)
db5 = false
end

Num5.Touched:connect(onTouched5)

db6 = false
function onTouched6()
if db6 == true then end
db6 = true
if i == 0 then
i = 6
elseif x == 0 then
x = 6
end
wait(2)
db6 = false
end

Num6.Touched:connect(onTouched6)

db7 = false

function onTouched7()
if db7 == true then end
db7 = true
if i == 0 then
i = 7
elseif x == 0 then
x = 7
end
wait(2)
db7 = false
end

Num7.Touched:connect(onTouched7)

db8 = false
function onTouched8()
if db8 == true then end
db8 = true
if i == 0 then
i = 8
elseif x == 0 then
x = 8
end
wait(2)
db8 = false
end

Num8.Touched:connect(onTouched8)

db9 = false
function onTouched9()
if db9 == true then end
db9 = true
if i == 0 then
i = 9
elseif x == 0 then
x = 9
end
wait(2)
db9 = false
end

Num9.Touched:connect(onTouched9)

function M()
if y == 0 then
y = 1
end
end

workspace.Ti.Touched:connect(M)

function D()
if y == 0 then
y = 2
end
end

workspace.Di.Touched:connect(D)

function A()
if y == 0 then
y = 3
end
end

workspace.Ad.Touched:connect(A)

function S()
if y == 0 then
y = 4
end
end

workspace.Su.Touched:connect(S)






while true do
if i > 0 and x > 0 and y > 0 then
if y == 1 then
h.Text = i .. " x " .. x .. " = " .. i * x
elseif y == 2 then
h.Text = i .. " / " .. x .. " = " .. i / x
elseif y == 3 then
h.Text = i .. " + " .. x .. " = " .. i + x
elseif y == 4 then
h.Text = i .. " - " .. x .. " = " .. i - x
end
y = 0
x = 0
i = 0
end
wait(1)
end


▲☭⎊▲Obama is a giant overlord space lizard▲⎊☭▲
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
06 Jul 2015 11:35 AM
... Oh god no
Report Abuse
UFAIL2 is not online. UFAIL2
Joined: 14 Aug 2010
Total Posts: 6905
06 Jul 2015 11:37 AM
lol
Report Abuse
Lineout is not online. Lineout
Joined: 06 Nov 2012
Total Posts: 684
06 Jul 2015 11:37 AM
Ewwwww
Report Abuse
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
06 Jul 2015 11:52 AM
dam that code is bad
Report Abuse
ohno1112 is not online. ohno1112
Joined: 23 Mar 2013
Total Posts: 833
06 Jul 2015 11:57 AM
or, couple up with a server script and use loadstring.

then, you can let users type the arithmetic as text, for example '36 / 12'

then, all you need to do is assign the result from loadstring() into a variable.

print variable back. you will get 3.

Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
06 Jul 2015 12:08 PM
wtf is that. thats not even a calculator. thats just garbage


"Talk is cheap. Show me the code." - Linus Torvalds
Report Abuse
Alyte is not online. Alyte
Joined: 24 Oct 2011
Total Posts: 10090
06 Jul 2015 12:48 PM
EW YOUR CODES GROSS!!!!!!!!!!!!!1
GET IT OFF MY SCREEN EW!!!!!!!!!!!!!!!!!!!!11
*VOMITS INTERNAL ORGANS*
FINALLY SOMETHING I CAN LOOK AT THAT WONT MAKE ME FEEL LIKE IVE JUST SPENT THE EVENING WITH BILL COSBY1!!!!!!!
LOL X+Y
LOL X/Y
LOL IF YOURE FEELING LIKE AN MLG XXXSCRIPT_MASTERXXX YOU CAN DO SQUARE ROOT AS WELL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1

Regard and politeness,
Alyte aka Snoxicle | Lyt | XD_SCripters_Warefare rank IVV Genral
Report Abuse
CrescentJade is not online. CrescentJade
Joined: 07 Jul 2010
Total Posts: 5494
06 Jul 2015 12:50 PM
use string manipulation..
Report Abuse
louiskk is not online. louiskk
Joined: 31 Dec 2008
Total Posts: 228
06 Jul 2015 01:04 PM
It would have been cleaner if you had written all the possible number combinations down. I'm going to be sick.
Report Abuse
WolfgangVonPrinz is not online. WolfgangVonPrinz
Joined: 24 Oct 2013
Total Posts: 4656
06 Jul 2015 01:18 PM
I've got some pseudo code, and I'm writing a new code which is cleaner, using arrays.

▲☭⎊▲Obama is a giant overlord space lizard▲⎊☭▲
Report Abuse
K7Q is online. K7Q
Joined: 23 Mar 2013
Total Posts: 5546
06 Jul 2015 01:21 PM
can i see the calculator
also 211 lines? somethings not right
Report Abuse
lateregistration is not online. lateregistration
Joined: 02 Apr 2013
Total Posts: 2630
06 Jul 2015 01:45 PM
@Alyte, what prestige?
Report Abuse
WolfgangVonPrinz is not online. WolfgangVonPrinz
Joined: 24 Oct 2013
Total Posts: 4656
06 Jul 2015 02:23 PM
http://www.roblox.com/games/222002882/WolfgangVonPrinzs-Calculator

▲☭⎊▲Obama is a giant overlord space lizard▲⎊☭▲
Report Abuse
Alyte is not online. Alyte
Joined: 24 Oct 2011
Total Posts: 10090
06 Jul 2015 05:13 PM
PREssTIDGe you're moon
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