Jump to content

Short if statements


Recommended Posts



because i'm very bored and i don't know what i should do till i'll go to bed i decided to publish a lua guide about short if statements.


Maybe you know the short if statements from other languages like C++.



cout << (a == true ? "1" : "2");

At this example the console would write "1" if a would be true.

If a would be false it will write "2".


In lua the short if statements are a little bit different but basicly they are very easy.


Imagine you want to give a information about a event.

For example if it's running or something else.


There are many ways to show the current status of a event.

You can use the long version with a text output two different if/else blocks.



Another way is to use a table.



say("The event is ".. ({"inactive","active"})[game.get_event_flag("event")])

But it's also to much text if you don't use a special function.


So the shortest version for something like this is a short if statement.



The construction is very simple.



The short if version of the shown table method is:

say("The event is ".. (game.get_event_flag("event") == 1 and "active" or "inactive"))

On the first view it's maybe a little bit longer but if you'll use it everytime you will see it's shorter to use this method.





You have a variable to check the value. (game.get_event_flag("event"))

Now you use the datatype boolean to get true or false (game.get_event_flag("event") == 1).


The datatype boolean includes nothing else as a normal if statement.


Now you must set two possibilities ("active" and "inactive")


If the boolean statement returns true the possibility which was set to "and" will be used. ("active")

But if it returns false the other possibility will be used. ("inactive")



I hope i helped somebody with this tutorial.

If you have any questions just ask me.





P.S: Please don't publish this tutorial on elitepvpers. They don't deserve it.

  • Love 9
Link to comment
Share on other sites

  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.