News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

The script about “if” statement bug

Started by Chun Jiu, April 08, 2018, 10:43:03 AM

Previous topic - Next topic

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.





I love my girlfriend like c++!    :-)

[url="http://pan.baidu.com/s/1feNwU"]http://pan.baidu.com/s/1feNwU[/url]
easilygcc is a gmail's email.

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.

You should copy and paste the error message, if ever possible.
The error message is:
QuoteScriptConsole line = (1) column = (49) : error end of statement expected (; or lf)
and not
QuoteScriptConsole line = (1) column = (49) : error end of statement expected (; or If)

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:

> {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


I assume, that only the first print belongs to the if-statement, otherwise you need to put the whole else-clause in curly-brackets.

> 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

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.

You should copy and paste the error message, if ever possible.
The error message is:
QuoteScriptConsole line = (1) column = (49) : error end of statement expected (; or lf)
and not
QuoteScriptConsole line = (1) column = (49) : error end of statement expected (; or If)

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:

> {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


I assume, that only the first print belongs to the if-statement, otherwise you need to put the whole else-clause in curly-brackets.

> 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



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.
I love my girlfriend like c++!    :-)

[url="http://pan.baidu.com/s/1feNwU"]http://pan.baidu.com/s/1feNwU[/url]
easilygcc is a gmail's email.