- NSIS Discussion
- Dynamic NSIS variables?
Archive: Dynamic NSIS variables?
LaneinBC
16th November 2005 16:20 UTC
Dynamic NSIS variables?
I tried this and it did not work. I thought I would ask here to see if there was a way to do this..
Lets say we have some variables:
Var vr1
Var vr2
Var vr3
Now I wish to access variable "$vr1" like this:
StrCpy $0 "1"
IntOp $vr$1 $vr$1 + 1
(should be the same as "IntOp $vr1 $vr1 + 1" )
Is there a way to achieve this?
Thanks
Lane
iceman_k
16th November 2005 17:07 UTC
I don't think what you want is possible the way you have shown it.
If you want to do this during compiletime, use macros.
e.g.,
!macro INCREMENT VAR
IntOp ${VAR} ${VAR} + 1
!macroend
Section
!insertmacro INCREMENT $vr1
SectionEnd
At runtime, you can probably use a Function
Function increment
Exch $0
IntOp $0 $0 + 1
Exch $0
FunctionEnd
Section
Push $vr1
Call increment
Pop $vr1
SectionEnd
However, I am not sure if this is what you are looking for.
What exactly are you trying to do with these "dynamic" variables?
Afrow UK
16th November 2005 17:16 UTC
If you're trying to do an array of data, you can try my NSISArray plugin.
http://nsis.sf.net/File:NSISArray.zip
-Stu
LaneinBC
16th November 2005 17:25 UTC
I should have explained better.
What I am trying to do, is to read 16 different values from an INI file (State and Text) and place each one into a matching named NSIS variable. I have this working, but it would be really nice if I could just put it into a "loop". Would make the scipt easier to read and more maintainable.
:D
To put this into a program loop, I need to be able to use what I was calling "dynamic" NSIS variables.
Can you suggest a method to do this?
Thanks
Lane
flyakite
16th November 2005 17:45 UTC
StrCpy $0 "1"
IntOp $vr$1 $vr$1 + 1
Shouldn't $0 actually be $1? You're setting the integer 1 to the variable $0.
But in the next line, when you're trying to run an integer operation on it, you're trying to run it on $vr$1, and you never set anything to $1.
Maybe I'm missing something here, but I don't see where else $0 comes into play.
LaneinBC
16th November 2005 17:47 UTC
Yes, that was a "typo" on my part..
It should have been $vr$0
flyakite
16th November 2005 17:52 UTC
Okay, well in that case, I think you are using the IntOp operation on the wrong variable. You are using it on $vr$1, expecting it to increment the variable vr1 to become vr2. That won't happen, because it can not add an integer "1" to a string "vr1".
You should run IntOp on $0.
IntOp $0 $0 + 1
This way, the initial value "1", on the next loop becomes 2, and therefore the new variable that $vr$0 would access is "vr2".
At least I think that's what should be happening.
iceman_k
16th November 2005 17:55 UTC
The best suggestion is probably Afrow UK's NSISArray plugin.
LaneinBC
16th November 2005 17:57 UTC
Yes, that is what I initially thought too.
But it seems the substituting "$vr$0" for "$vr1", does not work. (where $0 was set to "1").
It works in normal string substitution, but not when you need it to refer to an NSIS variable.
That is what I have been trying to get going...
Lane
iceman_k
16th November 2005 18:04 UTC
That's because the substitution is being done at compiletime, not runtime.
At compile time, the compiler extracts a token named $vr$0 from the command.
It then tries to resolve the token and sees that it consists of two variables: $vr and $0.
When it tries to resolve $vr it fails.
LaneinBC
16th November 2005 18:09 UTC
Yes, I understand what is happenig now.
Perhaps a future NSIS release could support something like this, or could have native array support!
Thanks
Lane
Afrow UK
16th November 2005 19:11 UTC
I think that that would just add to the installer overhead.
Edit: If you want to clean up your code, use a macro and insert it multiple times.
-Stu
dandaman32
24th November 2005 18:21 UTC
Upgrade to NSIS 2.11 and use the !tempfile, !appendfile, and !delfile commands to dynamically generate script files.
-dandaman32