Custom function in scripts?

Post » Tue Jun 29, 2010 6:43 am

My script is getting bigger and heavier so i was wondering if it was possible to create a custom function with parameters etc. in a script to re-use some code in the GECK scripts. IMHO its not possible as i cannot find any reference but i wish I could!
User avatar
Sarah Unwin
 
Posts: 3413
Joined: Tue Aug 01, 2006 10:31 pm

Post » Tue Jun 29, 2010 11:34 am

Nope. You could have a separate Quest with a script attached. Run it on-demand like a function... startquest Questname. then the last line of the quest's script, do stopquest Questname.

Set variables in it before running with set Questname.varname to X.
User avatar
Phillip Brunyee
 
Posts: 3510
Joined: Tue Jul 31, 2007 7:43 pm

Post » Tue Jun 29, 2010 8:23 pm

Make a persistent reference, put a script on it containing whatever variables you need and the code you want to run in an OnActivate block, then you can call it with
set FunctionRef.Param1 to Somethingset FunctionRef.Param2 to SomethingElseFunctionRef.activate player 1

User avatar
Wayland Neace
 
Posts: 3430
Joined: Sat Aug 11, 2007 9:01 am

Post » Tue Jun 29, 2010 5:38 am

Make a persistent reference, put a script on it containing whatever variables you need and the code you want to run in an OnActivate block, then you can call it with
set FunctionRef.Param1 to Somethingset FunctionRef.Param2 to SomethingElseFunctionRef.activate player 1


Are there any types of objects that are more suitable for this than others?
User avatar
Eilidh Brian
 
Posts: 3504
Joined: Mon Jun 19, 2006 10:45 am

Post » Tue Jun 29, 2010 2:39 pm

I just use activators, but I don't think one thing's particularly better than any others.
User avatar
Vickey Martinez
 
Posts: 3455
Joined: Thu Apr 19, 2007 5:58 am

Post » Tue Jun 29, 2010 7:53 pm

Another method (the one i prefer) is to use stage functions.

1. Create a quest, check "Allow repeated stages" (important if you wanna call it more than once!)
2. In the Quest Stages tab, add a new index, then a new and empty log entry.
3. Put your script in the "Result script" box.

To execute the script, setStage myQuest myIndex

Its also possible to pass arguments, though its up to you how to get them. You can either use globals, or use questvars. And of course you can also have many stagescripts per quest.
User avatar
chloe hampson
 
Posts: 3493
Joined: Sun Jun 25, 2006 12:15 pm

Post » Tue Jun 29, 2010 6:41 pm

You can also do functions via Label/GoTo with NVSE - this has the benefit of running it all in one frame and allowing you to get the results of the function within that frame.
User avatar
dell
 
Posts: 3452
Joined: Sat Mar 24, 2007 2:58 am

Post » Tue Jun 29, 2010 4:50 pm

Both, activators and stage functions run in the same frame, too.
You can do
set myQuest.input to XsetStage myQuest 1set result to myQuest.output

User avatar
daniel royle
 
Posts: 3439
Joined: Thu May 17, 2007 8:44 am

Post » Tue Jun 29, 2010 11:41 am

You can also do functions via Label/GoTo with NVSE - this has the benefit of running it all in one frame and allowing you to get the results of the function within that frame.
Not without a lot of effort- you have to initialise a label before goto will return to it. So your script would look like
label 10if(callfunction1)endiflabel 20if(function2)endiflabel 30set callfunction1 to 1goto 10endif

When activation scripts run in the same frame, can have variables defined on them (unlike quests), and can be nested up to 8 deep (in CSR Fallout I've got activators with loops that call activators with loops calling activators which call activators which call activators) they're pretty much the best solution, at least to my mind.
User avatar
Jessica Raven
 
Posts: 3409
Joined: Thu Dec 21, 2006 4:33 am

Post » Tue Jun 29, 2010 9:00 am

Something I think I missed with using the activators - you can have a bunch of these in a dummy cell and the activation block will run even if you are not in that cell?
User avatar
jasminĪµ
 
Posts: 3511
Joined: Mon Jan 29, 2007 4:12 am

Post » Tue Jun 29, 2010 6:08 am

Yup. Then you can potentially use functions like GetFirstRefInCell and IsInList to do some tricks with dynamically choosing between functions.
User avatar
Ice Fire
 
Posts: 3394
Joined: Fri Nov 16, 2007 3:27 am


Return to Fallout: New Vegas