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++.
Example:
Code:
cout << (a == true ? "1" : "2");
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.
Example:
Code:
say("The event is ".. ({"inactive","active"})[game.get_event_flag("event")])
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:
Code:
say("The event is ".. (game.get_event_flag("event") == 1 and "active" or "inactive"))
Construction:
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.
Sincerely,
iRemix
P.S: Hatte keine Lust es nochmal in's Deutsche zu übersetzen







