Archive: Frustrating errors


Frustrating errors
Hi.

I'm attempting to build an installer which i would like to keep as dynamic as possible by either declaring a bunch of globals and reading from them or simply getting the info from an ini file.

I keep getting the following message every time i try to use any sort of useful command at the top of my code:

Error: command not valid outside section or function

Now, i understand exactly what it means i would just like to know how to get around this.

For example i'd like to have a dynamic variable which would allow me to change the Name, BrandingName, OutFile etc.

Thanks for your help


As the error says you can't use run time instructions outside a Section or a Function.

For example, StrCpy is a run time instruction, so you can't use it outside a Section or Function for compile time purposes.

If you need to execute NSIS run time code at compile time, see this article:
http://nsis.sourceforge.net/Invoking...n_compile-time

-Stu

-Stu


Now that you mentioned it, the distinction between compile-time tools (use macros!) and run time tools (use functions!) becomes clear.

>> As the error says you can't use run time instructions outside a Section or a Function.

I think that error diagnostic does not say exactly that, but probably it should. Newbies would appreciate.

Rudif


It's not a matter of whether to use macros or functions. Macros can be used inside of function just fine.

The actual error is a result of trying to use a run-time command outside of a function.

For example, ReadIniStr is a runtime function. You could include this command in a macro and that would still be legal.

If you then used !insertmacro to insert that macro outside of any function or section, you would recieve the error. But, if you used the same !insertmacro call from within a function or section, then the compiler would be perfectly happy.

The general rule is that anything in the help files under "instructions" (section 4.9) should be considered a runtime instruction.

If all this seems confusing, my recommendation would be to study the examples and start experimenting with some simple scripts of your own. Eventually, it'll all make sense. I know because I was once a newbie, too! ;)