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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 09 Mar 2015 05:49 AM |
| op adds 1k lines of pointless output |
|
|
| Report Abuse |
|
|
|
| 09 Mar 2015 06:02 AM |
Who even needs the function lol?
x = 3+4+5+5+6+3+2+1 |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 18 Nov 2009 |
| Total Posts: 2361 |
|
| |
|
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 |
|
|
|
| 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 |
|
|
|
| 09 Mar 2015 01:31 PM |
| @ForeverDev, that's pretty much what I did :3 |
|
|
| Report Abuse |
|
|
|
| 09 Mar 2015 01:34 PM |
| lol amanda failed(nice namesnipe btw) |
|
|
| Report Abuse |
|
|