Jump to content

Is it possible in Papyrus to reference a variable with a string identifier?


Recommended Posts

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

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

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

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 valueArray

endif

Link to comment
Share on other sites

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] = newVarValue

Instead, 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 valueArray

endif

 

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

  • Recently Browsing   0 members

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