"If and" statements

Started by kathryn, Fri 22/01/2010 09:59:03

Previous topic - Next topic

kathryn

Hello. I'm trying to figure out if AGS is capable of "if and" statements. I have read the help manual (accessed from within the software itself), and have searched this forum.

The title of one post appeared relevant (see http://www.adventuregamestudio.co.uk/yabb/index.php?topic=8270.0), but a moderator has moved the post, deleted the content and provided a link which is now dead.

A live link to some assistance on this issue would be much appreciated.

Thanks.

abstauber

Sure it does. It doesn't have switch-case, but the "IF" feature is there since day one :)

This is from the built in AGS manual.

Quote
if, else statements

if ( expression ) {
statements1
}
[ else {
statements2
} ]
If expression is true, then statements1 are run.

If expression is not true, and there is an else clause present, then statements2 are run instead.

For example:


if (GetGlobalInt(5) == 10) {
  Display("Globalint 5 is 10.");
}
else {
  Display("Globalint 5 is not 10.");
}

In this example, the first message will be displayed if the return value from GetGlobalInt(5) is 10, and the second message will be displayed if it is not.
if statements can be nested inside else statements to produce an "else if" effect. For example:


if (GetGlobalInt(5) == 1) {
  Display("Globalint 5 is 1.");
}
else if (GetGlobalInt(5) == 2) {
  Display("Globalint 5 is 2.");
}
else {
  Display("Globalint 5 is not 1 or 2.");
}


kathryn

So in fact the answer is "no". Based on the manual, then, AGS is only capable of "else if" statements.

Thanks.

Quote from: abstauber on Fri 22/01/2010 10:03:26
Sure it does. It doesn't have switch-case, but the "IF" feature is there since day one :)

This is from the built in AGS manual.



abstauber

Hehe - yeah I should have read your post properly.

Khris

If by "if and", you're talking about testing "if (condition1 and condition2)", then sure, that's perfectly possible.

Code: ags
  if (a == 3 && mouse.Mode == eModeInteract) {


Take a look at the operators section of the manual:
http://www.adventuregamestudio.co.uk/manual/Operators.htm

kathryn

Thanks, Khris. Just found the operators section on the Wiki page.

Is there any way to search for operators (for example) in the manual? Most of my troubles stem from not being able to find what I'm looking for.

Khris

Searching for something else than plain text is hard or even impossible sometimes.
Best thing is to peruse the manual once.

I assume you're aware of the helpfile that comes with AGS?

Crimson Wizard

#7
I think you should search for "operators" on Index page of AGS manual.

Anyway, don't want to sound rude and all, but... heh, I always have uneasy feeling when people asking questions like "does AGS have <some ultra-basic-which-every-programming-language-has code feature here>".
I would be seriously terrified if AGS didn't have them.

Ryan Timothy B

I've mentioned this before, but I believe this is a sound suggestion since not every programming language is the same:
For the basic programmers who don't/didn't know that these are called Operators (including me when I started with AGS ::)), I would like to see 'or' and 'and' in the manual, which could then direct you to the Operators page.

Crimson Wizard

Quote from: Ryan Timothy on Fri 22/01/2010 22:57:03
I've mentioned this before, but I believe this is a sound suggestion since not every programming language is the same:
For the basic programmers who don't/didn't know that these are called Operators (including me when I started with AGS ::)), I would like to see 'or' and 'and' in the manual, which could then direct you to the Operators page.
Or maybe add "conditions" topic, which could be also part of "if/else" article.

kathryn

Quote from: Khris on Fri 22/01/2010 12:01:58
I assume you're aware of the helpfile that comes with AGS?

Yeah, that's my first point of reference when I encounter problems or questions. Since the online manual and the AGS help file appear to be the same, in future I'll use Google to search the online manual instead. (For example, type site:http://www.adventuregamestudio.co.uk/manual along with my key words of interest.) I suspect many of the newbie "can I do this?" questions wouldn't be necessary if the help documentation were more accessible to text searches. (And more flexible searching; as Ryan Timothy pointed out, not everyone is experienced enough to know to search for "operators".)

Quote from: Crimson Wizard on Fri 22/01/2010 14:14:20
Anyway, don't want to sound rude and all, but... heh, I always have uneasy feeling when people asking questions like "does AGS have <some ultra-basic-which-every-programming-language-has code feature here>".
I would be seriously terrified if AGS didn't have them.

Me too, but we're only asking these questions because we expect the AGS language to have such functionality, but can't find documentation about it. At least some of us know exactly what we're looking for, but can't find it with ease. After all, this is the Beginners' Technical Forum.

SMF spam blocked by CleanTalk