You are not logged in.

Impact

Super Moderator

  • "Impact" started this thread

Posts: 1,276

wcf.user.option.userOption53: Nein

  • Send private message

1

Tuesday, February 14th 2012, 6:59am

Abfragen als abgekürzten Schreibweise

Manchmal hat man kleine Teile im Code, für die sich eine Abfrage nicht lohnt, sei es zur übersetzung von On/Off switches, kurzen Phrases oder ähnlichem.
Hier 2 Beispiele.

PHP Source code

1
2
3
4
5
6
new bool:bswitch;
bswitch true;
PrintToServer("Switch ist: %s"bswitch "An" "Aus");

bswitch false;
PrintToServer("Switch ist: %s"bswitch "An" "Aus");

Ausgabe:

Source code

1
2
Switch ist: An
Switch ist: Aus

Equivalenter Code:

PHP Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
new bool:bswitch;
bswitch true;

if(bswitch)
{
    PrintToServer("Switch ist: An");
}
else
{
    PrintToServer("Switch ist: Aus");
}

bswitch false;
if(bswitch)
{
    PrintToServer("Switch ist: An");
}
else
{
    PrintToServer("Switch ist: Aus");
}

Ausgabe:

Source code

1
2
Switch ist: An
Switch ist: Aus


Wichtig hierbei ist zu beachten:

PHP Source code

1
2
? == then
: == else

Zudem darf kein if davor stehen.

Hier noch ein weiteres Beispiel.

PHP Source code

1
2
3
4
5
6
new int;
int 5;
PrintToServer("Int %s ueber 5"int "ist" "ist nicht");

int 15;
PrintToServer("Int %s ueber 5"int "ist" "ist nicht");

Ausgabe:

Source code

1
2
Int ist nicht ueber 5
Int ist ueber 5


Geht natürlich auch mit integern, ich hatte nur leider kein passendes Beispiel.

MfG
Impact

This post has been edited 1 times, last edit by "Impact" (Feb 14th 2012, 7:09am)


HSFighter

Administrator

Posts: 1,517

Location: Flensburg

Occupation: Industrieelektroniker

wcf.user.option.userOption53: Nein

  • Send private message

2

Monday, March 5th 2012, 7:03pm

Anbei noch ein Beispiel einer abgekürzten Schreibweise für IF-THEN-ELSE-Konstruktionen.

"?" = "Then" = "{"
":" = "Else" = "} Else {"

PHP Source code

1
(count ($links) > 1) ? ($links join (" | ",$links)) : ($links "");
=

PHP Source code

1
2
3
4
5
6
if (count ($links) > 1)
{
$links join (" | ",$links);
} else {
$links "";
}



-
Anti Cheat: www.smacbans.com
Kein direkter Support per PM (nur auf Anforderung)