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 » Scripting Helpers
Home Search
 

Re: Ternary Operators

Previous Thread :: Next Thread 
IlIll is not online. 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
XxChopSlaperxX is not online. XxChopSlaperxX
Joined: 09 Nov 2010
Total Posts: 3112
31 May 2014 10:56 AM
What's a ternary operator?
Report Abuse
1234Christopher is not online. 1234Christopher
Joined: 21 Oct 2008
Total Posts: 1715
31 May 2014 10:58 AM
The keys already equal to the letters if they're the right numbers?
Report Abuse
IlIll is not online. 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
XxChopSlaperxX is not online. XxChopSlaperxX
Joined: 09 Nov 2010
Total Posts: 3112
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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