Jump to content

Easy Papyrus Question, Looking for help.


CEO 0S

Recommended Posts

Hi and thank you,

 

I'm having a script problem that seems to most likely have a simple solution. Thank you for the help and time!

 

Problem: I'd like to have a function set the value of a string to something specific.  If I set the value in the Event it works fine but if I do the same thing from a function the string is not changed. (Examples are below.)

 

The function will live in a different script which is why I'm using global. I can't have the function just change xScene it has to change any string that's input in the function.

 

This is what I'd like to do: (It's not working however, the string is not changed when it runs through the function)

Scriptname MyScript extends activemagiceffect  

String Property xScene Auto

Event Oneffectstart (actor xActTarget, actor xActCaster)
     xDoSetString(xScene)
     Debug.Notification(xScene)
EndEvent

Function xDoSetString (string zString) Global
     zString = "Testing"    
EndFunction

This version below was for testing and works if I set the String in the Event itself: (But not what I am looking to do, I'd like the external function to set the string.)

Scriptname MyScript extends activemagiceffect  

String Property xScene Auto

Event Oneffectstart (actor xActTarget, actor xActCaster)
     xScene = "Testing"
     Debug.Notification(xScene)
EndEvent
Link to comment

b3lisario I want to say thanks, your mods and information you've put online have been a huge help to me along the way, all so excellent, and for giving me your time on this problem.

 

I think that would work but it's in the reverse of what I'm trying to do. I'd like the function to take in any string and set it to a specific value instead of the new value being input to the function to change the string. Also the function will live in a different script so I can't call <xScene> directly from it. I made the above as an abbreviated version of my script to show only the problem I'm having.

 

It's confusing to me why it doesn't work I think i'm missing a principle of papyrus that's making it not connect. I do a similar more complicated function that works on an array and it sets the values just fine but setting the string to a specified value does not. Example of the similar function that works:

Function xPrepareScene(actor zA, Float[] zLoc) global
                 zLoc [0] = zA.GetPositionX()    
                 zLoc [1] = zA.GetPositionY()
                 zLoc [2] = zA.GetPositionZ()
                 zLoc [3] = zA.GetAngleX()
                 zLoc [4] = zA.GetAngleY()
                 zLoc [5] = zA.GetAngleZ()
EndFunction

If it helps I'm making "choose your own adventure" animation scenes that play in an onupdate loop, every scene has a number of choices bound to keypress on what to do next. I want a bunch of variables to be set by this function everytime the loop starts based on the name of the animation. These will tell it the length of the animation, set special event flags and what animation to go to next when certain keys are pressed. I could put it all in one big script but it would get really large and complicated as all my "scenes" are using the same onupdate loop being able to use a function to set a variable to an exact value would help a lot to organize the project.

Link to comment

then

String[] myStrings ; initialized somewhere
Function xDoSetString (int whichOne)
    myStrings[whichOne] = "valueToSet"
EndFunction
or

String myFirstString
String mySecondString
Function xDoSetString (int whichOne)
    String value = "valueToSet"
    If whichOne == 0
        myFirstString = value
    ElseIf whichOne == 1
        mySecondString = value
    EndIf
EndFunction
String parameters work a bit different than arrays. Inside the function, the string argument is a copy of the string, not a reference to a variable
Link to comment

Thanks very much B3lisario,

This helped me understand it a bit. After reading this It seems like I'm Basically telling a copy of the string to have a new value which is then lost when the function ends instead of sending it through.

 

It seems not possible to set a variable to a specific value from a function to be updated in a loop without having it already defined then in the script. I think if I use a string function it would only return it a single time the first time the property is set?

 

With this info I'm going to just try to set it up as organized as possible all in one script then so I can reference the actual variables directly. Thank you again for all your help. Here's a more in depth example of what I'm trying to do maybe there's a better way all together. I'm planning on just making a long list like this now with one entry per animation scene setting up it's variables.

Event OnUpdate ()
     xPrepareLoopSegment()
     "Animation Stuff and Variables Used in here"
     RegisterForSingleUpdate(AnimationLength)
EndEvent   

Function xPrepareLoopSegment()
     If xSceneName = "Scene1"
         AnimationLength = 2.0
         HasSpecialEvent = True
         SpecialEventWaitTime = 5.0
         SpecialEventInt = 5
         TransitionAnimation = True
         HasKeyPress205 = True
         205SetNextScene = "Scene2"
         HasKeyPress206 = True
         206SetNextScene = "Scene3"
         MoralValueChange = 1 
     
     ElseIf xSceneName = "Scene2"
         AnimationLength = 5.0
         Etc. Etc.       

EndFunction	
Link to comment

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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