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-Quelltext
|
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:
|
Quellcode
|
1
2
|
Switch ist: An
Switch ist: Aus
|
Equivalenter Code:
|
PHP-Quelltext
|
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:
|
Quellcode
|
1
2
|
Switch ist: An
Switch ist: Aus
|
Wichtig hierbei ist zu beachten:
|
PHP-Quelltext
|
1
2
|
? == then
: == else
|
Zudem darf kein if davor stehen.
Hier noch ein weiteres Beispiel.
|
PHP-Quelltext
|
1
2
3
4
5
6
|
new int;
int = 5;
PrintToServer("Int %s ueber 5", int > 5 ? "ist" : "ist nicht");
int = 15;
PrintToServer("Int %s ueber 5", int > 5 ? "ist" : "ist nicht");
|
Ausgabe:
|
Quellcode
|
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