Jump to content

Tutorial: NVSE4+ Part 2: User Defined Functions (UDFs)


Recommended Posts

Before I start fiddling with this, because my brain isn't so good with this kind of thinking, if I have an event where a player normally has a token with a "removeme" at the end just so I can process that script when it's called, instead I could just do "call ScriptNameHere" and process the script without adding a token?

If you're just giving them the token in order to have the script run then yes. You put the code in your UDF script instead, and call it instead of giving them the token. It will run right then.

Link to comment
  • 4 weeks later...

Anyone know how this handles things if more than one script calls it at once?

 

Say I have 2 Pregnant nPC's actors running their TokenPregnantActor scripts and I outsource calculating Bellysize or something to a Function and 2 actors call the function on the same frame?

Link to comment

Not sure, Hal. I'm gonna go out on a limb and say it'd work in the way that spell scripts or object scripts on different refs work in a single frame, ie different instances happening on the different refs (if that's what happens, who knows these things...)

Link to comment
Guest tomm434

Anyone know how this handles things if more than one script calls it at once?

 

Say I have 2 Pregnant nPC's actors running their TokenPregnantActor scripts and I outsource calculating Bellysize or something to a Function and 2 actors call the function on the same frame?

 

My game crashed when I was CIOSing 3 SexoutNGFinish spells at the same time (3 lines in a row). So I used simple

While iCount2 <6
let iCount2 +=1
loop
Link to comment
Guest tomm434

I was doing it on different actors (have 3 animations going at the same time - needed to make sure that they stop before player leaves the cell).

Link to comment

 

Anyone know how this handles things if more than one script calls it at once?

 

Say I have 2 Pregnant nPC's actors running their TokenPregnantActor scripts and I outsource calculating Bellysize or something to a Function and 2 actors call the function on the same frame?

 

My game crashed when I was CIOSing 3 SexoutNGFinish spells at the same time (3 lines in a row). So I used simple

While iCount2 <6
let iCount2 +=1
loop

 

Hmm I think if I had no choice I'd rather set a global Boolean bUDFBusy, just before calling it and a check that as a condition before calling it and have the UDF reset it at the end of it's script. But that still may not work if they were called at exactly the same frame dependant on whether the global registers as 1 in time as I'm thinking even if they run the same frame one will still run before the other, but if it's like PLC's then the global could still read 0 to the next frame.

 

And seeing this is a Fallout specific Tutorial I'm thinking it should be in a Fallout section as I keep forgetting there's stuff here in the main Tutorials, which I expect more for Non-Game specific stuff like Blender etc.

Link to comment
  • 2 weeks later...
  • 2 weeks later...
Guest tomm434

I'm trying to create a universal function which will reset quest+ particular variable from different quest and function doesn't work!

Scriptname  MyFunction

int Variable
int LocalVariable

begin Function {LocalVariable}
let Variable :=LocalVariable

let Variable := 2 

{other code}
end

(I also tried removing "Variable" and modifying "LocalVariable" directly)

 

The call from dialogue looks like this

call MyFunction Quest.MyVariable

Please tell me what's wrong with this.

{or should I do trick with "Let MyQuest.MyVariable := call MyFunction"} ?

 

Link to comment
Guest tomm434

I have many repeatable dialogue and each of them require resetting the quest. The only difference is that there is unique variable for each topic. That's why I decided to make function which will reset quest + set variable I want to a certain value (2).  So I call "call MyFunction Myquest2.Myvariable"  - quest1 is reset + Myquest2.MyVariable is set to 2.

Link to comment

Hm, yeah, that's not gonna work.

 

When you

call somefunction quest.somevar

you're really passing along the value of that var to the udf, not the actual var

 

 

you could use

let quest.somevariable := call somefunction

 

or

 

call somefunction questref "variablename" somevalue

and then use GetVariable/SetVariable etc

Link to comment

I just wanted to point out a thing that I found on UDFs.

I have this:

ESM -> contains UDFs

ESP -> calls UDFs from the ESM

I changed one of the UDFs in the ESM, adding a boolean parameter, but just for curiosity I didn't change the ESP (so it was calling the UDF but still missing a parameter, that usually doesn't compile if you open the script). If the boolean parameter was true, the UDF had to do new functions.

In game everything worked fine, my guess is it automatically interpreted the boolean as false. I'm pretty sure it didn't skip pieces of script because it was a complicated UDF. Anyway it didn't crash, that's quite relieving.

Link to comment
  • 8 months later...

Having the weirdest issue right now changing the interface to a UDF, NVSE 4.5.7.

 

A UDF defined like this:

scn fnSexoutArCompare
; Compares two arrays to see if they are equal.

; args
array_var arLHS
array_var arRHS
string_var stWild

; ...
Begin Function{arLHS arRHS}
...
End
And called like this:

if eval(0 == (call fnSexoutArCompare inActFilt, arResult[item["value"]]["actors"]))
; ...
Works fine.

 

Changing the definition to this:

Begin Function{arLHS arRHS stWild}
And the call to this:

if eval(0 == (call fnSexoutArCompare inActFilt, arResult[item["value"]]["actors"], "both"))
Results in NVSE reporting an error in the calling script.

Operator := failed to evaluate to a valid result
No other changes made at all, the UDF isn't using the 3rd param yet. I tried commenting out the call to the UDF so that no scripts were using it, saving, quitting, restarting geck, and then changing the UDF definition and adding the call back in. No help.

 

Going to try a newer NVSE now but if anyone has seen this before, I'd like to know.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use