| |
|
| |
|
|
| 03 Oct 2013 06:55 AM |
Instead of
if a == "a" then b = 1 elseif a == "b" then b = 2 elseif a == "c" then b = 3 end
You can write
b=(a=="a")+2(a=="b")+3(a=="c") |
|
|
| Report Abuse |
|
|
|
| 03 Oct 2013 06:57 AM |
| Oh yeah I use those sometimes. Not too too often because they're often not applicable for what I'm doing, but sometimes. |
|
|
| Report Abuse |
|
|
| |
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 03 Oct 2013 07:05 AM |
Yeah. Except I don't try add numbers to Booleans. At least not in Lua (well, you can in cake... I mean... muffin...)
- As, return n < 10 and "0" or "" |
|
|
| Report Abuse |
|
|
|
| 03 Oct 2013 07:11 AM |
"b=(a=="a")+2(a=="b")+3(a=="c")"
Would error. |
|
|
| Report Abuse |
|
|
|
| 03 Oct 2013 08:05 AM |
| That's why ROBLOX should make bool=int |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 03 Oct 2013 08:34 AM |
try replacing +n with ( and n or ) <<< just without the parenthesis. Then it would give the result you expected.
- As, I like not having Booleans doing the stuff you want it to. That makes things interesting. Argh, zig... |
|
|
| Report Abuse |
|
|
bohdan77
|
  |
| Joined: 10 Aug 2008 |
| Total Posts: 7944 |
|
|
| 03 Oct 2013 02:19 PM |
| But it looks so unreadable doing that. :( I do it sometimes for quick stuff, I guess. |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 03 Oct 2013 02:33 PM |
b="a" b=(b=="a" and 1) or (b=="b" and 2) or (b=="c" and 3) print(b) >1 |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
sncplay42
|
  |
| Joined: 27 Nov 2008 |
| Total Posts: 11891 |
|
|
| 03 Oct 2013 03:00 PM |
Oysi: I think he wants you to read it like mathematical notation with == returning 0 or 1
>That's why ROBLOX should make bool=int
Please no.
Actually I think I recall hearing that the creators of Lua actually regret even letting nil be false (they didn't introduce an actual boolean type for several versions, so originally nil was *the* false value). |
|
|
| Report Abuse |
|
|
|
| 03 Oct 2013 09:48 PM |
c = {'a', 'b', 'c'}
...
for i,v in pairs(c) do b = (a == v and i) end
I don't see why not |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
|
| 04 Oct 2013 05:34 AM |
| You do know that I just gave examples, right? |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
|
| 04 Oct 2013 05:52 AM |
| Yeah, my mistake, it wasn't really meant to be for Lua, but some other languages, I just wrote it in Lua syntax. |
|
|
| Report Abuse |
|
|