can anyone explain what this means:
if(( something > 0 ? --something : 0) == 0){
someevent();
}
can anyone explain what this means:
if(( something > 0 ? --something : 0) == 0){
someevent();
}
That makes no sence. if you mean like this:
if(playername.startswith("delta)) {
Isnoob = true;
}
then.
1. the if statement is a way to open it
2. playerName is what your getting/using
3 .startswith means...startswith
4. name
5. { basically means then
6. isnoob = true; means your declaring sommet. but lets just say addItem(995, 1); all it is is adding that. but dont use that coz it would keep looping.
7. } means "end"
Quote:
Originally Posted by cows1471 [Only registered and activated users can see links. Click Here To Register...]
if(playername.startswith("delta)) {
to
if(playername.startswith("delta")) {
lol what you said is obvious... thats not i want.. but thanks anyway
it meansQuote:
Originally Posted by xaves7 [Only registered and activated users can see links. Click Here To Register...]
I'm not sure on the very last part though ) == 0), i think it just means if it's not bigger than 0, is it 0.Code:if (something > 0) {
something -= 1;
} else {
something = 0; (0 would give errors, so i edited it)
}
i saw this in devo source and didnt know what this could be used for so i asked.
i will test some things and then i say if its what you said(luke)
oh, almost forgot, THANKS :D
It's basically an if/else statement in 1 line ;).
hmm thanks im trying to use devo 2.7 melee combat in delta cleaned and it attacks one time, and keeps attacking with no stop, i need some timers and one is this thing i asked.lol
What Luke132 said wasn't entirely right but close:
Code:if(( something > 0 ? --something : 0) == 0){
someevent();
}
This (?) is what we call the ternary operator, it's a short version of a 'simple if-else statement':Code:( something > 0 ? --something : 0)
You see the ternary operator stands together with "== 0" in the if-statement. As I just told you the ternary operator returns the result of the statement to the outside giving 2 possible choices in this case:Code:if(something > 0)
--something; //(which is the same as something = something -1; or something -= 1;)
else
0 //altough 0 isn't a statement, the ternary operator returns the result if-part or else-part to the outside
if(something > 0):
Note that --something IS NOT the same as something--Code:if(--something == 0)
With something-- the subtraction happens after the rest of the line is executed, with --something, the subtraction happens before the line is executed. This is important when used in if-else, while, for, ... structures.
if(something <= 0)
After seeing the possibilities, the most exact statements (for this piece of code) are the following:Code:if(0 == 0) //this is always true
Ofcourse a possible shorter version could be:Code:if(something > 0){
if(--something == 0){ //something has to be one and will be subtracted
someevent();
}
} else {
if(0 == 0) //always yields true so not necesary
someevent();
}
In short:Code:if(something <= 0 || --something == 0)
someevent();
If something is lesser than 1, someevent() will be triggered.
If this is not the case the value of something will lower by 1 and if the value of something (so after the subtraction) equals to 0, someevent() will be triggered.
Its a ternary statement, there is an informative thread on them.