Developer forums (C::B DEVELOPMENT STRICTLY!) > Contributions to C::B
The script about “if” statement bug
(1/1)
Chun Jiu:
Test in the script console :
-----------------------------
if (1) print(_T("1")); else print(_T("2")); print(_T("3"));
or
if (1) {print(_T("1"));} else {print(_T("2"));} print(_T("3"));
------------------------
Will produce an error:
------------------------
Filename: ScriptConsole
Error:end of statement expected (; or If)
Details: ScriptConsole line = (1) column = (49) : error end of statement expected (; or If)
=================
As long as the "IF" statement does not follow the statement, there will be no error.
For example:
print(_T("3"));if (1) print(_T("1")); else print(_T("2"));
====================================================
I originally wanted to insert the version number of the library file in the path, so I used the following settings.
If the project does not provide a version number variable "wx_ver", the global variable "wx.ver" is used:
The compile variable :
path_inc =
$(CODEBLOCKS)\..\..\include\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\include" -I"$(CODEBLOCKS)\..\..\lib\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\shared\dll_i686\mswu$(debug_wx)
My project build option -> search directories ->Compiler :
$(path_inc)
-------------------------------------------
No error if there is no second [[ ... ]] .
--------------------------------------------
After a lot of combination tests, I found that it was the kind of error I encountered earlier.
I couldn't add any script content after the "if" statement, otherwise it would go wrong.
Jenna:
--- Quote from: Chun Jiu on April 08, 2018, 10:43:03 am ---Test in the script console :
-----------------------------
if (1) print(_T("1")); else print(_T("2")); print(_T("3"));
or
if (1) {print(_T("1"));} else {print(_T("2"));} print(_T("3"));
------------------------
Will produce an error:
------------------------
Filename: ScriptConsole
Error:end of statement expected (; or If)
Details: ScriptConsole line = (1) column = (49) : error end of statement expected (; or If)
=================
As long as the "IF" statement does not follow the statement, there will be no error.
For example:
print(_T("3"));if (1) print(_T("1")); else print(_T("2"));
====================================================
I originally wanted to insert the version number of the library file in the path, so I used the following settings.
If the project does not provide a version number variable "wx_ver", the global variable "wx.ver" is used:
The compile variable :
path_inc =
$(CODEBLOCKS)\..\..\include\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\include" -I"$(CODEBLOCKS)\..\..\lib\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\shared\dll_i686\mswu$(debug_wx)
My project build option -> search directories ->Compiler :
$(path_inc)
-------------------------------------------
No error if there is no second [[ ... ]] .
--------------------------------------------
After a lot of combination tests, I found that it was the kind of error I encountered earlier.
I couldn't add any script content after the "if" statement, otherwise it would go wrong.
--- End quote ---
You should copy and paste the error message, if ever possible.
The error message is:
--- Quote ---ScriptConsole line = (1) column = (49) : error end of statement expected (; or lf)
--- End quote ---
and not
--- Quote ---ScriptConsole line = (1) column = (49) : error end of statement expected (; or If)
--- End quote ---
It misses a linefeed (or a semicoln), not an If-statement.
If you add a semicolon after the else-clause or place curly brackets ({and}) around the whole If-statement, it works:
--- Code: ---> {if (1) {print(_T("1"));} else {print(_T("2"));}} print(_T("3"));
1
3
> if (1) print(_T("1")); else print(_T("2"));; print(_T("3"));
1
3
--- End code ---
I assume, that only the first print belongs to the if-statement, otherwise you need to put the whole else-clause in curly-brackets.
--- Code: ---> if (1) {print(_T("1"));} else {print(_T("2")); print(_T("3"));};
1
> if (0) {print(_T("1"));} else {print(_T("2")); print(_T("3"));};
2
3
--- End code ---
Chun Jiu:
--- Quote from: jens on April 08, 2018, 11:36:12 am ---
--- Quote from: Chun Jiu on April 08, 2018, 10:43:03 am ---Test in the script console :
-----------------------------
if (1) print(_T("1")); else print(_T("2")); print(_T("3"));
or
if (1) {print(_T("1"));} else {print(_T("2"));} print(_T("3"));
------------------------
Will produce an error:
------------------------
Filename: ScriptConsole
Error:end of statement expected (; or If)
Details: ScriptConsole line = (1) column = (49) : error end of statement expected (; or If)
=================
As long as the "IF" statement does not follow the statement, there will be no error.
For example:
print(_T("3"));if (1) print(_T("1")); else print(_T("2"));
====================================================
I originally wanted to insert the version number of the library file in the path, so I used the following settings.
If the project does not provide a version number variable "wx_ver", the global variable "wx.ver" is used:
The compile variable :
path_inc =
$(CODEBLOCKS)\..\..\include\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\include" -I"$(CODEBLOCKS)\..\..\lib\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\shared\dll_i686\mswu$(debug_wx)
My project build option -> search directories ->Compiler :
$(path_inc)
-------------------------------------------
No error if there is no second [[ ... ]] .
--------------------------------------------
After a lot of combination tests, I found that it was the kind of error I encountered earlier.
I couldn't add any script content after the "if" statement, otherwise it would go wrong.
--- End quote ---
You should copy and paste the error message, if ever possible.
The error message is:
--- Quote ---ScriptConsole line = (1) column = (49) : error end of statement expected (; or lf)
--- End quote ---
and not
--- Quote ---ScriptConsole line = (1) column = (49) : error end of statement expected (; or If)
--- End quote ---
It misses a linefeed (or a semicoln), not an If-statement.
If you add a semicolon after the else-clause or place curly brackets ({and}) around the whole If-statement, it works:
--- Code: ---> {if (1) {print(_T("1"));} else {print(_T("2"));}} print(_T("3"));
1
3
> if (1) print(_T("1")); else print(_T("2"));; print(_T("3"));
1
3
--- End code ---
I assume, that only the first print belongs to the if-statement, otherwise you need to put the whole else-clause in curly-brackets.
--- Code: ---> if (1) {print(_T("1"));} else {print(_T("2")); print(_T("3"));};
1
> if (0) {print(_T("1"));} else {print(_T("2")); print(_T("3"));};
2
3
--- End code ---
--- End quote ---
Thank you!
I did not notice the difference between "if" and "lf"!
=============================
$(CODEBLOCKS)\..\..\include\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\include
=============================
I used the "print" statement in the options script may have generated unnecessary LF, so I got an error.
I continue to study how to generate the required complete compilation symbol string without the LF.
Navigation
[0] Message Index
Go to full version