IlIll
|
  |
| Joined: 28 Aug 2011 |
| Total Posts: 896 |
|
|
| 31 May 2014 10:55 AM |
I just started using these and they're great. As I am new to them, I don't know what you can and what you cannot do so I am wondering if it possible to use a ternary operator on the following if statement:
if key == string.char(17) then key = "w" elseif key == string.char(18) then key = "s" elseif key == string.char(19) then key = "d" elseif key == string.char(20) then key = "a" else return nil end
Thanks! |
|
|
| Report Abuse |
|
|
|
| 31 May 2014 10:56 AM |
| What's a ternary operator? |
|
|
| Report Abuse |
|
|
|
| 31 May 2014 10:58 AM |
| The keys already equal to the letters if they're the right numbers? |
|
|
| Report Abuse |
|
|
IlIll
|
  |
| Joined: 28 Aug 2011 |
| Total Posts: 896 |
|
|
| 31 May 2014 10:58 AM |
Like instead of... if cf.X < 0 then fireCannons:FireServer(-1, stats[type].Cannons, body.Torso, type) else fireCannons:FireServer(1, stats[type].Cannons, body.Torso, type) end
I can do... fireCannons:FireServer((cf.X < 0 and -1) or 1, stats[type].Cannons, body.Torso, type)
|
|
|
| Report Abuse |
|
|
|
| 31 May 2014 10:59 AM |
| If you do or, if the first one is false, even though the second one is true, the code will execute. |
|
|
| Report Abuse |
|
|
IlIll
|
  |
| Joined: 28 Aug 2011 |
| Total Posts: 896 |
|
|
| 31 May 2014 11:04 AM |
Bah nevermind, I did it! key = (key == string.char(17) and "w") or (key == string.char(18) and "s") or (key == string.char(19) and "d") or (key == string.char(20) and "a") or nil |
|
|
| Report Abuse |
|
|