saschagottfried
19th October 2006 16:04 UTC
Declare variables with /global flag
Hi NSIS coders,
I started declaring variables right in the functions where I am using them afterwards. Those functions are written down below the sections, where I use those variables as well. The whole installer consists of one .nsi file.
Actually NSIS reports some warnings (unknown variable/constant detected). This is confusing. Is this allowed or not? My understanding of a GLOBAL flag would lead to no warnings. Am I right???
code:
section -main sec_idx
${If} $var1 = 1
...
${EndIf}
sectionend
function foo
var /GLOBAL var1
ReadRegStr var1 HKCU ...
functionend
CrushBug
19th October 2006 16:54 UTC
Re: Declare variables with /global flag
Sorry that I am not answering your question, but your sample code has errors.
Originally posted by saschagottfried
${If} $var1 = 1
You have to use double equals "==" otherwise you just assigned $var1 to "1" (I think?)
ReadRegStr var1 HKCU ...
$var1 not var1
Afrow UK
19th October 2006 17:33 UTC
CrushBug I think you should read the comments in the LogicLib.nsh file.
Just use Var without /global at the top of your script.
-Stu
goldy1064
19th October 2006 18:39 UTC
It generates a warning because if you have a function/section/etc. that uses the variable before the function that declares it, it is unknown and will be an error.
CrushBug
19th October 2006 21:48 UTC
Originally posted by Afrow UK
[B]CrushBug I think you should read the comments in the LogicLib.nsh file.
Yeah, that was why I through in the last minute "I think" in there. Its a coding standard here to use == since most of the other programmers are C programmers. It screws them up to see only 1 = :)