if put a at the end or not
I saw some script with ; at the end of a if, working. Some script if you put a ; at the end the script ignore the if.
Working with 3d Rad. Angle Script code.
First, I cannot understand what you were saying. Second, you're not being specific enough, you need to write down what exactly the snippet of code was. Once you do that, I am sure somebody can help you.
Owner and Creator of CGML, along with Phynix. CGML, a 3d, 2d, event library. Version 1.0 is being released, too. Cross platform, windows, OS X, linux, unix. So visit cgml.webs.com today!
He seems pretty clear to me. Since he does live in the USA, he ought to learn to write better, but the question wasn't vague at all.
He said, "I saw a script with a semi-colon ';' at the end of a if() statement, and it worked. Some scripts ignore the if() statement, when you but a semi-colon at the end."
He's also posting in the AngelCode development forum, so we can assume he's talking about the AngelScript scripting language, which makes it a very direct question.
@asterix12:
I'm not familiar with AngelScript, but I do know that it mimics C++ functionallity. In C++ when you have a if() statement, it works like this:
If 'stuff()' returns 'true' or something equal to true, then the code in the brackets run.
If there is a semicolon after a if() statement, it cuts it off beforehand. The code inside the if() runs. The code in the brackets also runs, regardless of whether the if-statement is true or not. Like this:
Look at it this way:
But if you do this:
The compiler sees it like this:
And then this happens:
That's how it happens in C++, AngelScript may work differently.
He said, "I saw a script with a semi-colon ';' at the end of a if() statement, and it worked. Some scripts ignore the if() statement, when you but a semi-colon at the end."
He's also posting in the AngelCode development forum, so we can assume he's talking about the AngelScript scripting language, which makes it a very direct question.
@asterix12:
I'm not familiar with AngelScript, but I do know that it mimics C++ functionallity. In C++ when you have a if() statement, it works like this:
if(stuff()){ otherStuff();}
If 'stuff()' returns 'true' or something equal to true, then the code in the brackets run.
If there is a semicolon after a if() statement, it cuts it off beforehand. The code inside the if() runs. The code in the brackets also runs, regardless of whether the if-statement is true or not. Like this:
if(stuff()) ; //Semicolon after the if-statement. 'stuff()' still gets called.{ otherStuff(); //Otherstuff also runs.}
Look at it this way:
if(stuff()) //Runs, no matter what. otherStuff(); //Only runs if the if() statement is true.evenMoreStuff(); //Runs, no matter what.
But if you do this:
if(stuff()) ; //semicolon otherStuff();evenMoreStuff();
The compiler sees it like this:
if(stuff()) ; //Empty statement.otherStuff();evenMoreStuff();
And then this happens:
if(stuff()) //Runs, no matter what. ; //Empty statement.otherStuff(); //Runs, no matter what.evenMoreStuff(); //Runs, no matter what.
That's how it happens in C++, AngelScript may work differently.
Oh! Thank you for explaining that better. The reason is, when you have an if statement, the next line and it's own line, is compiled. When there is a plain semi-colon, it is a blank line, it does nothing. I don't understand why somebody would do this, but it ignores the if statement because:
Say you had an if statement with no brackets.
if(condition)
;
doThis();
anotherDoThis();
The line after the if statement, is compiled without doing anything, as if it was ignoring it. Then, the lines after it are called, outside the if statement. However, if it had brackets, it would not be ignored.
if(condition){
;
doThis();
anotherDoThis();
}
It will compile all of these lines, if the condition is true.
Say you had an if statement with no brackets.
if(condition)
;
doThis();
anotherDoThis();
The line after the if statement, is compiled without doing anything, as if it was ignoring it. Then, the lines after it are called, outside the if statement. However, if it had brackets, it would not be ignored.
if(condition){
;
doThis();
anotherDoThis();
}
It will compile all of these lines, if the condition is true.
Owner and Creator of CGML, along with Phynix. CGML, a 3d, 2d, event library. Version 1.0 is being released, too. Cross platform, windows, OS X, linux, unix. So visit cgml.webs.com today!
Servant of the Lord is correct.
However, I should probably add a compiler warning, or perhaps even an error for scripts like these. Thanks for bringing it up.
However, I should probably add a compiler warning, or perhaps even an error for scripts like these. Thanks for bringing it up.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
I am a C++ programmer, also, and it might be different, with the scripting language you use, (which you did not specify).
Owner and Creator of CGML, along with Phynix. CGML, a 3d, 2d, event library. Version 1.0 is being released, too. Cross platform, windows, OS X, linux, unix. So visit cgml.webs.com today!
As Servant of the Lord mentioned, this is the AngelCode forum, so any question about unspecified languages default to AngelScript. :)
Also, from asterix12 previous posts he's most likely refering to 3DRads use of AngelScript.
Also, from asterix12 previous posts he's most likely refering to 3DRads use of AngelScript.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
Quote: Original post by WitchLord
However, I should probably add a compiler warning, or perhaps even an error for scripts like these. Thanks for bringing it up.
Don't have an error for while() or for() loops, though (a warning still would be nice). Sometimes it's an intentional choice.
while(doStuff()); //Continue to call doStuff() until it returns true.
Sorry for the confusion, I wrote fast. English is not my first language. It is angleScript obvisously I am talking about. Used in 3d Rad game engine.
Here is a example that the if require a ; at the end of the line.
int count = 0;
void Main()
{
OUT_0 = iFloatRand(0,1);
if (count == 200) iObjectHide(OBJ_0);
count++;
}
And on this one, if you put a ; at the end of the if, it will not work.
float energy_monster= 100;
void Main()
{
if (IN_22 > 0); //Si il y a collision l'impact est plus forte que 0
{
energy_monster = energy_monster -1; //Dommage créé par l'arme, peut être une variable représentant sa force.
}
OUT_0 = energy_monster; //Print l'énergie restant au monstre ValuePrint
iObjectHide(OBJ_44);//Monstre disparaît
iObjectShow(OBJ_66); //Fait aparaître particles
iObjectStart(OBJ_66); //Particle part
}
Thanks
Here is a example that the if require a ; at the end of the line.
int count = 0;
void Main()
{
OUT_0 = iFloatRand(0,1);
if (count == 200) iObjectHide(OBJ_0);
count++;
}
And on this one, if you put a ; at the end of the if, it will not work.
float energy_monster= 100;
void Main()
{
if (IN_22 > 0); //Si il y a collision l'impact est plus forte que 0
{
energy_monster = energy_monster -1; //Dommage créé par l'arme, peut être une variable représentant sa force.
}
OUT_0 = energy_monster; //Print l'énergie restant au monstre ValuePrint
iObjectHide(OBJ_44);//Monstre disparaît
iObjectShow(OBJ_66); //Fait aparaître particles
iObjectStart(OBJ_66); //Particle part
}
Thanks
Working with 3d Rad. Angle Script code.
My post higher up, explains it.
You are getting confused, I think, because the code isn't properly tabbed and newlined.
An if() statement expects one of either two things:
A) A code statement after it, which ends in a semi-colon ';'.
B) A block of code, wrapped in curly-brackets { }.
So a statement either looks like this:
Or it looks like this:
Let's look at the two examples you gave. (The code in blue is ran only if the if statement is true. Everything else, such as 'count++', is always ran)
Let's now look at the next chunk of code.
You need to remove the red semi-colon after the blue text, to fix your problem. A if-statement either controls one statement with one semi-colon ending the statement, or it controls one chunk of code, beginning and ending with curly-brackets like '{' and '}'.
You can't have a if-statement control a chunk of code in curly brackets, and a semi-colon ended statement. (But you can have as many semi-colon ended statements as you like, inside the curly brackets)
By removing the extra semi-colon, you get this code, which is what you want:
Remember, an if() statement is not a function, so it does not end with a semi-colon like ';'.
Understand? If not, keep asking, until you do understand, we're glad to help.
Your second post has very good english; if english isn't your first language, that is perfectly fine. People only get irritated when english is someone's first language, and they just don't bother to to type well. [smile]
You are getting confused, I think, because the code isn't properly tabbed and newlined.
An if() statement expects one of either two things:
A) A code statement after it, which ends in a semi-colon ';'.
B) A block of code, wrapped in curly-brackets { }.
So a statement either looks like this:
if(...) one-statement-only;
Or it looks like this:
if(...){ as-many-statements; as-you-want; until-the-end; of-the-curly-brackets;}
Let's look at the two examples you gave. (The code in blue is ran only if the if statement is true. Everything else, such as 'count++', is always ran)
int count = 0;void Main(){ OUT_0 = iFloatRand(0,1); if (count == 200) iObjectHide(OBJ_0); //Blue code is ran only if 'count' is equal to '200'. count++;}
Let's now look at the next chunk of code.
float energy_monster= 100; void Main(){ if (IN_22 > 0) nothing-is-here!; //Si il y a collision l'impact est plus forte que 0 { energy_monster = energy_monster -1; //Dommage créé par l'arme, peut être une variable représentant sa force. } OUT_0 = energy_monster; //Print l'énergie restant au monstre ValuePrint iObjectHide(OBJ_44);//Monstre disparaît iObjectShow(OBJ_66); //Fait aparaître particles iObjectStart(OBJ_66); //Particle part}
You need to remove the red semi-colon after the blue text, to fix your problem. A if-statement either controls one statement with one semi-colon ending the statement, or it controls one chunk of code, beginning and ending with curly-brackets like '{' and '}'.
You can't have a if-statement control a chunk of code in curly brackets, and a semi-colon ended statement. (But you can have as many semi-colon ended statements as you like, inside the curly brackets)
By removing the extra semi-colon, you get this code, which is what you want:
float energy_monster= 100; void Main(){ if (IN_22 > 0) //Si il y a collision l'impact est plus forte que 0 { energy_monster = energy_monster -1; //Dommage créé par l'arme, peut être une variable représentant sa force. } OUT_0 = energy_monster; //Print l'énergie restant au monstre ValuePrint iObjectHide(OBJ_44);//Monstre disparaît iObjectShow(OBJ_66); //Fait aparaître particles iObjectStart(OBJ_66); //Particle part}
Remember, an if() statement is not a function, so it does not end with a semi-colon like ';'.
Understand? If not, keep asking, until you do understand, we're glad to help.
Your second post has very good english; if english isn't your first language, that is perfectly fine. People only get irritated when english is someone's first language, and they just don't bother to to type well. [smile]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement