dagobaking Posted June 12, 2018 Share Posted June 12, 2018 This is possible in most languages. In Actionscript, for example, it looks like this: theVar = theObject["theVarYouWant"];Is there an equivalent of this in Papyrus? Link to comment Share on other sites More sharing options...
Hoamaii Posted June 12, 2018 Share Posted June 12, 2018 Yes, it is, as long of course as later you use it with a function which will take strings. you just reference it as: string MyString = "SomeString" Link to comment Share on other sites More sharing options...
dagobaking Posted June 12, 2018 Author Share Posted June 12, 2018 Thank you. That is not what I am needing. I need MyString to be used to dynamically reference any number of other variables. Link to comment Share on other sites More sharing options...
Hoamaii Posted June 12, 2018 Share Posted June 12, 2018 Sorry for misunderstanding - I used it a couple of times to attach an Int variable to it and that works, but that's as far as my experience goes on this. Not sure it answers you question. Link to comment Share on other sites More sharing options...
Reneer Posted June 13, 2018 Share Posted June 13, 2018 If I understand what you're looking for properly, you want something like GetPropertyValue, which returns a script property based on the string name of the property. Link to comment Share on other sites More sharing options...
dagobaking Posted June 13, 2018 Author Share Posted June 13, 2018 Thank you. Yes! That is what I need. But, I need it for regular variables rather than properties. Is that available? Link to comment Share on other sites More sharing options...
Reneer Posted June 13, 2018 Share Posted June 13, 2018 Unfortunately, only properties. Why are you restricted to variables only? What are you trying to accomplish? Link to comment Share on other sites More sharing options...
steve40 Posted June 13, 2018 Share Posted June 13, 2018 Variables are private, so Like Reneer said, they aren't accessible. You can only access variables indirectly via a property or function, if available. That said, there are functions such as GetAnimationVariableBool, GetAnimationVariableInt and GetAnimationVariableFloat that can access certain variables using string identifiers. Link to comment Share on other sites More sharing options...
pra Posted June 13, 2018 Share Posted June 13, 2018 So you basically want a hashMap/associative array? Papyrus doesn't support that.You could approximate that by using two arrays, one being a string array, containing the keys, and the other one containing the values.Then you do something like int i = keyArray.find(myString)if(i >= 0)do something with valueArrayendif Link to comment Share on other sites More sharing options...
dagobaking Posted June 13, 2018 Author Share Posted June 13, 2018 Unfortunately, only properties. Why are you restricted to variables only? What are you trying to accomplish? I have a settings system that uses an XML file to hold all settings. I don't want to create a direct dependency on MCM. But, I want other modders to be able to make MCM, holotape or whatever they want to affect the settings if they wish as an add-on. So, I made an API function to change settings externally through Papyrus. They send in the name of the setting as a string along with the new value. This is ok for most of the settings because they work in Flash. But, I also extend some of them out to act as Quest script level settings in Papyrus. So, I want to add a check in to apply changes to those too. It would be elegant to simply have something like: questScriptScope[varTitle] = newVarValueInstead, I have to have a large If statement like this: If (varTitle == "setting_to_change") setting_to_change = newVarValue Else If (varTitle == "blah_de_blah") blah_de_blah = newVarValue ... ...It's not the end of the world. But, just clunky as I am often adding/removing settings in this phase of development. I CAN use properties. But, then I would have to mess around with the CK whenever I add/remove settings which is probably worse. Variables are private, so Like Reneer said, they aren't accessible. You can only access variables indirectly via a property or function, if available. That said, there are functions such as GetAnimationVariableBool, GetAnimationVariableInt and GetAnimationVariableFloat that can access certain variables using string identifiers. Thank you. So you basically want a hashMap/associative array? Papyrus doesn't support that.You could approximate that by using two arrays, one being a string array, containing the keys, and the other one containing the values.Then you do something like int i = keyArray.find(myString)if(i >= 0)do something with valueArrayendif Thank you. That would work. Though, I think a big If statement is probably a similar amount of effort with a little less processor cost. Link to comment Share on other sites More sharing options...
Recommended Posts