Jump to content

Short if statements


Remix

Recommended Posts

Hey,

 

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:

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.

 

Example:

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.

 

 

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: Please don't publish this tutorial on elitepvpers. They don't deserve it.

  • Love 8
Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • 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.