|
| 20 Aug 2017 11:53 AM |
Hi I'm masterluacoder4475 and in this thread I'll show you part one of how to script in ten minutes.
Part 1: Math Doing math in Lua is extremely easy. Here's how you do it:
s={}function push(...)if select('#',...)==0 then return end;s[#s+1]=(...)push(select(2,...))end;function pop()local _=s[#s]s[#s]=nil;return _;end;function add()local b=pop()local a=pop()push(a+b)end;function sub()local b=pop()local a=pop()push(a-b)end;function mul()local b=pop()local a=pop()push(a*b)end;function div()local b=pop()local a=pop()push(a/b)end;function pow()local b=pop()local a=pop()push(a^b)end;function mod()local b=pop()local a=pop()push(a%b)end;push(3,5,2)add()mul()print(pop())
As you can see from the above script Lua is very easy to understand in comparison to other languages such as C++ and Java. If you run the script (or just read it!) you should see that it prints out the solution to 3x(5+2), 21. I'm not going to spend any more time going over this as the rest of math in Lua should be self explanatory. |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2017 11:57 AM |
| Bump1. If you have any suggestions feel free to post reply with them. |
|
|
| Report Abuse |
|
|
Ultra_07
|
  |
| Joined: 22 Nov 2007 |
| Total Posts: 1594 |
|
|
| 20 Aug 2017 11:59 AM |
| All the pushes and pops make it seem like assembly |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2017 12:00 PM |
i didnt even know lua supported pushing and popping data
https://www.roblox.com/triggered-item?id=476076352 |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2017 12:02 PM |
| Don't worry, every new language looks like assembly at first. Once you get the hang of it writing Lua is no harder than writing English. |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2017 04:20 PM |
| Someone needs to make the block of code in the original post their siggy. |
|
|
| Report Abuse |
|
|
Mattxew
|
  |
| Joined: 27 Nov 2013 |
| Total Posts: 1180 |
|
|
| 20 Aug 2017 04:22 PM |
i dont understand this
im a bad scripter
its everday bro, i aint in disney any mo |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2017 04:26 PM |
| Here's a reverse polish notation version of what this script is basically doing: 3 5 2 + * |
|
|
| Report Abuse |
|
|
|
| 26 Aug 2017 09:38 PM |
| wait but you can just do print(3 * 5 + 2) right |
|
|
| Report Abuse |
|
|
|
| 26 Aug 2017 10:03 PM |
@Horrible_Pun
You could, but with a language like Lua that's only one of the many possible ways of doing it. |
|
|
| Report Abuse |
|
|