Jump to content

Variables within variables - quick question!


Aeryn Snowpaw
 Share

You are about to reply to a thread that has been inactive for 4622 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Currently I have a code set up like this

                if ((integer)llGetSubString(n,-1,-1) == 1)
                {
                    stateobjects1 = [a] + stateobjects1;
                }
                if ((integer)llGetSubString(n,-1,-1) == 2)
                {
                    stateobjects2 = [a] + stateobjects2;
                }     ...

 And I'm looking to shorten down the variable to elminate the need for constant if checks and new variables.

stateobjects((integer)llGetSubString(n,-1,-1))
//(obviously this is not proper code, but I'd like to know how to do something like this.) 

 Basically just making "stateobjects" dynamic so that I don't have to have seperate variables for each one! Normally I'd use an array for this sort of thing, but the concept of lists is slightly new and confusing to me when trying to do things like this.

Thanks for the help, I appreciate it!

Link to comment
Share on other sites

I'm sorry, I can't quite see what you're trying to do.  if "[a]" is a new element that you want added to different lists depending on the string then, obviously, there will still need to be those different lists to prepend to.  If you are instead trying to increment the list-element referenced by the string then you can use llListReplaceList().  It's not as tidy (or fast) as stateobjects[3] += x but it does the same job.

Link to comment
Share on other sites

just think of lists as a single dimensional array without any of the common shorthand operators. it's really just a chained reference for variables.

 

while it probably won't shorten your code, a strided list may be better for your case than parralel list. it uses the same variable structure, but treats lists like recordsets of the length of the stride. it's almost possible to mimic arrays that way, but all dimensions will be fixed except one.

 

you can at least shorten your code in one respect.... save the result of

(integer)llGetSubString( n, -1,-1 )

to a variable, and use the variable in each if test.

 

if you have more than 3 linear if tests, and they are all relatively likely, a binary tree of if statements  will probably save on needed tests (if not, then an unbalanced tree will, but those need to be custom built), which will shorten the flow.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4622 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...