Jump to content

Setting a ref variable based on a string variable


psychoorc99

Recommended Posts

So long story short, I'm trying to use the command SetNthEffectBase on a custom ability in the body of a loop with a different index and effect each time. However, the names of the effects I want to use are stored in string variables and the command only accepts ref variables to specify new effects. I figured fine, whatever, I'll make a ref variable and Let it to my string variable and use that instead. Unfortunately, Let does not accept string arguments either (gives an invalid operands error). So, the next question is how to create a ref variable using a string variable to set where it points. Unfortunately, I have not found an easy way to do this.

 

I've tried several different methods for making a ref variable that matches the string variable but have had no success yet, what I've figured out through way too much time messing around:

 

Using "let rTest := increaseskillbarter" with "SetNthEffectBase TestAbility iIndex rTest" works correctly, so logically if I can find a way to set a ref variable with a string variable instead of a specified string then the rest should work.

Using "let rTest := svTest" with "SetNthEffectBase TestAbility iIndex rTest" won't compile, invalid operands for :=.

Using "set rTest to svTest" with "SetNthEffectBase TestAbility iIndex rTest" will compile but won't set the effect ingame.

Using commands like setName or setBaseForm that act on an existing reference doesn't seem to work

Using StringToRef to set the ref variable doesn't work, even if I pick a specific base effect and run it through RefToString (or GetFormIDString, or GetRawFormIDString) then convert it right back.

 

Note: I'm using the same string variables that specify the effect names for other things so I would rather not be creating a bunch of ref variables instead, although I guess I could use GetName on them to get the string back (this would be less than ideal because this effect-setting loop is only called once but the array of effect names is often referred back to and I'd rather not be frequently running Get functions unnecessarily).

 

Haven't had any luck with Google fu. I realize that I could just set each effect individually, but I would be surprised if there's really no way to do it with variables.

 

Tl;dr: how can I create a ref variable using a string variable to determine what it points to? (e.g. create a ref variable that points to the increaseskillbarter base effect based on a string that says "increaseskillbarter", the same way that you can use "let rTest := increaseskillbarter" if you type it in yourself.)

Link to comment
Share on other sites

If your string variable is just storing the string "increaseskillbarter", then I'm pretty certain it is not possible to get a reference from that. However, if your string variable stored the formid as a string which would be "00031D6A", then you could modify that string to be usable with the BuildRef function.

 

Is there a reason why the effects you want to use are stored as strings?

Link to comment
Share on other sites

So basically I have a stringmap that uses skill and attribute names as keys to store data for a penalty system that I'm applying with a custom perk. The purpose of this particular loop is to both add data to some elements of that stringmap and to set the corresponding entries of the custom perk's ability to the correct base effect (I was originally setting the effects in the GECK but it kept changing around their order, I thought it was just alphabetizing but it seemed more unpredictable than that in reality).

 

Right now I'm running this loop with a second population array that is just a list of various skills that are used as the keys for each element of the stringmap, then manipulated to the name of the base effects for, I thought, setting the perk's ability. Basically:

 

let TestModVars.penaltyInfo[entry["value"]] := Ar_list iCount, 0, 0, 0

let svTemp := "increaseskill" + $TestModVars.penaltyInfo[entry["value"]]

;make rEffect point to the base effect specified by svTemp
SetNthEffectBase TMStatPenalty iCount rEffect

 

I suppose what I could do is make the population array into a stringmap with each element having the skill as the key and the formid as the value so I could convert it into something BuildRef could use, it just seemed odd to me that there wasn't a simple way to use a string to set the reference.

Link to comment
Share on other sites

I was trying to have the effects be in a predictable order so that I could easily use integer keys that denote effects' positions in the list for logic in other functions rather than using the string names. I'm doing it that way because I figured there's less overhead just calling the array once at the beginning of a UDF, pulling the key, and storing it in a local variable rather then using string functions every time I want to check something. It's also way less work to check if an int is between 0 and 13 inclusive than to check if it matches any of 14 different numbers or to check if a string matches any of fourteen different words.

I could use GetNthEffectBase like you said and just add another value in each element of the array that stores the real key in addition to a value for a predictable number order, but I did end up getting the loop to work using a stringmap population array that holds the decimal converted formids for the various effects so I think I'm going to just move on.

Edited by psychoorc99
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...