Old 16th November 2005, 15:20   #1
LaneinBC
Junior Member
 
Join Date: Nov 2005
Location: Delta, BC
Posts: 23
Lightbulb 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
LaneinBC is offline   Reply With Quote
Old 16th November 2005, 16:07   #2
iceman_k
NSIS Dev
 
iceman_k's Avatar
 
Join Date: Feb 2003
Location: Boston, MA, U.S.A.
Posts: 455
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.,
code:

!macro INCREMENT VAR
IntOp ${VAR} ${VAR} + 1
!macroend

Section
!insertmacro INCREMENT $vr1
SectionEnd



At runtime, you can probably use a Function

code:

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?

Cheers,
Iceman_K

EclipseNSIS - An NSIS IDE for the Eclipse Platform | My contributions to the wiki
iceman_k is offline   Reply With Quote
Old 16th November 2005, 16:16   #3
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
If you're trying to do an array of data, you can try my NSISArray plugin.

http://nsis.sf.net/File:NSISArray.zip

-Stu
Afrow UK is offline   Reply With Quote
Old 16th November 2005, 16:25   #4
LaneinBC
Junior Member
 
Join Date: Nov 2005
Location: Delta, BC
Posts: 23
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.


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
LaneinBC is offline   Reply With Quote
Old 16th November 2005, 16:45   #5
flyakite
Member
 
Join Date: Dec 2003
Location: Chicago
Posts: 50
Send a message via AIM to flyakite Send a message via Yahoo to flyakite
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.
flyakite is offline   Reply With Quote
Old 16th November 2005, 16:47   #6
LaneinBC
Junior Member
 
Join Date: Nov 2005
Location: Delta, BC
Posts: 23
Yes, that was a "typo" on my part..
It should have been $vr$0
LaneinBC is offline   Reply With Quote
Old 16th November 2005, 16:52   #7
flyakite
Member
 
Join Date: Dec 2003
Location: Chicago
Posts: 50
Send a message via AIM to flyakite Send a message via Yahoo to flyakite
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.
flyakite is offline   Reply With Quote
Old 16th November 2005, 16:55   #8
iceman_k
NSIS Dev
 
iceman_k's Avatar
 
Join Date: Feb 2003
Location: Boston, MA, U.S.A.
Posts: 455
The best suggestion is probably Afrow UK's NSISArray plugin.

Cheers,
Iceman_K

EclipseNSIS - An NSIS IDE for the Eclipse Platform | My contributions to the wiki
iceman_k is offline   Reply With Quote
Old 16th November 2005, 16:57   #9
LaneinBC
Junior Member
 
Join Date: Nov 2005
Location: Delta, BC
Posts: 23
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
LaneinBC is offline   Reply With Quote
Old 16th November 2005, 17:04   #10
iceman_k
NSIS Dev
 
iceman_k's Avatar
 
Join Date: Feb 2003
Location: Boston, MA, U.S.A.
Posts: 455
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.

Cheers,
Iceman_K

EclipseNSIS - An NSIS IDE for the Eclipse Platform | My contributions to the wiki
iceman_k is offline   Reply With Quote
Old 16th November 2005, 17:09   #11
LaneinBC
Junior Member
 
Join Date: Nov 2005
Location: Delta, BC
Posts: 23
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
LaneinBC is offline   Reply With Quote
Old 16th November 2005, 18:11   #12
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 24th November 2005, 17:21   #13
dandaman32
Senior Member
 
dandaman32's Avatar
 
Join Date: Jan 2005
Location: Look behind you.
Posts: 209
Upgrade to NSIS 2.11 and use the !tempfile, !appendfile, and !delfile commands to dynamically generate script files.

-dandaman32

ExperienceUI for NSIS | Latest project: Enano CMS
Do not PM me on the Winamp forums, I hardly ever check my messages here; you are more likely to get my attention through the ExperienceUI forum.
dandaman32 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump