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: Scripting tutorial: How to add 2 numbers in ROBLOX Lua

Previous Thread :: Next Thread 
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
09 Mar 2015 01:34 AM
For those beginner scripters, I have layed out a basic template on the preferred way on adding 2 numbers.

This example prints the product directly to the output, note that in more advanced scripting you would most likely be returning the number instead.

--

function theAdditionOfOnePlusOneThatIsRightCountEmTwoNumbers(NumeroUno, NumeroDos)
if type(NumeroUno) == "number" and type(NumeroDos) == "number" then
--if NumeroUno and NumeroDos, both have no objections(nor does anyone else)
wait(1)
print("processing.")
wait(1)
print("processing..")
wait(1)
print("processing...")
wait(math.random(7))
--now preforming test addition to make sure nothing goes wrong
if 1 + 1 == 2 then
--test addition complete!
--you are ready to proceed!
if type(NumeroUno) == "number" and type(NumeroDos) == "number" then
--they could of been changed in this time, so now we must double check
--NOW WE CAN GET DOWN TO ADDING
wait(3)
local theAnswerYouHaveAllBeenWaitingFor = NumeroUno + NumeroDos
print(NumeroUno.." + "..NumeroDos.." = "..theAnswerYouHaveAllBeenWaitingFor)
end
else
print("WOOOOOOOOOAHHHHHHHHHHHHHHHHHHHHHHHHHH")
wait(.7)
print("THE UNIVVERESEEEEE")
wait(.5)
print("ISSS REJECCCTINGGG!!!")
wait(1)
print("BASIC...")
wait(.5)
print("MAAATTHHHHH")
end
else
error("Error: attempted to preform arithmetic with something other than numbers.", 0)
end
end

theAdditionOfOnePlusOneThatIsRightCountEmTwoNumbers(2, 2)
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
09 Mar 2015 01:39 AM
What she means in a nutshell is;

function add(x,y)
        return x + y;
end

add(2,5) -->7
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
09 Mar 2015 05:43 AM
Or even better

function Add(...)
local tab = {...}
local i = 0
for _,a in pairs(tab) do
i=i+a
end
print(i)
end

Add(1,2,3)

>6
Report Abuse
SummerEquinox is not online. SummerEquinox
Joined: 25 Jun 2013
Total Posts: 2088
09 Mar 2015 05:49 AM
op adds 1k lines of pointless output
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
09 Mar 2015 06:02 AM
Who even needs the function lol?

x = 3+4+5+5+6+3+2+1
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
09 Mar 2015 10:37 AM
I think this was a really helpful and informative tutorial.
Report Abuse
DrJonJ is not online. DrJonJ
Joined: 18 Nov 2009
Total Posts: 2361
09 Mar 2015 10:48 AM
print(1+1)
Report Abuse
anaIyze is not online. anaIyze
Joined: 29 May 2014
Total Posts: 2048
09 Mar 2015 12:29 PM
repeat until(1 and 2 and 3 and 4 and 5 and 6 and 7 and 8 and 9 or 0);
Report Abuse
ForeverDev is not online. ForeverDev
Joined: 04 Oct 2008
Total Posts: 13300
09 Mar 2015 12:56 PM
function a(...)local i=0;for _,v in ipairs{...}do i=i+v;end;return(i)end

print(a(5, 10, 20, 10))--> 45
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
09 Mar 2015 01:31 PM
@ForeverDev, that's pretty much what I did :3
Report Abuse
FalconLoverGiraffe is not online. FalconLoverGiraffe
Joined: 24 Jun 2014
Total Posts: 456
09 Mar 2015 01:34 PM
lol amanda failed(nice namesnipe btw)
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