Script Help; Calling Properties or Vars from other script

Post » Sat Feb 11, 2017 2:16 am

Any idea how to access variables, properties, functions from another script?



so i just extended the script, which seems to work although i have ran into an even bigger issue. I'm not 100% sure its related.



Script A is attached to a persistent xMarker and houses a number of int Properties



Script B extends Script A and is attached to a Book, sets those int Properties to 1 in an OnRead Event.



So I can see through the debug.notifications that the Properties have indeed changed from <> or 0 (i filled a few to 0, left a few default), to 1. i can re-read the book and it tells me the same thing through debug notes.



Script A and all its properties are Conditional, through this i'm using GetVMScriptVariable condition so i can give weapons and armor recipes for the forge through books. However, it doesn't appear to be recognizing the changes whnever i read the book. it doesn't show up in the crafting menu.



If I manually set the Properties value to 1 prior to launching the game, the armor recipe will show up in crafting menu. so at some point it can read it. I figured that perhaps it was not able to load automatically, so i read the book, saved, exited game, came back to the forge, still nothing. Any ideas? Either the script properties are being reset (i haven't checked that externally, like with another note to read, im not sure how exactly i haven't thought that far), or perhaps because the script isn't running, the crafting menu cannot access the script.

User avatar
Naomi Ward
 
Posts: 3450
Joined: Fri Jul 14, 2006 8:37 pm

Post » Fri Feb 10, 2017 2:23 pm

so i think i've tried just about every combination of things i can think of to get this to work.



i need to create some type of system to keep track of over 500+ (probably more) different variables. I guess I may have to just attach these scripts to a quest that constantly runs. Although i've never liked doing that. Any other ideas? it appears that the conditional functions will not pull variables from a non-currently-running script. Without putting scripts on vanilla objects, idk how to get around this and keep it clean and modular.

User avatar
LuCY sCoTT
 
Posts: 3410
Joined: Sun Feb 04, 2007 8:29 am

Post » Fri Feb 10, 2017 2:29 pm

That part makes no sense at all. If Script B is extending Script A then Script B has automatic access to every variable and function in A but you only use script B. Extending a script makes a new and improved (potentially altered) version of the original but has absolutely nothing to do with accessing variables on some other object in the game.



Those properties you're setting in your book have absolutely nothing to do with the properties on the Xmarker. Those are two different objects even if they do have the same or compatible scripts.



There's no reason for your script B to extend script A. Instead you need to create a property in script B that points to the xmarker object which has script A.



I'll most more in a little while but there's nothing wrong with a quest solution. It will be less resource intensive for the system than a persistent xmarker object.



I'll post more in a little while but I need to come up with a good explanation of the scripts.

User avatar
Pants
 
Posts: 3440
Joined: Tue Jun 27, 2006 4:34 am

Post » Fri Feb 10, 2017 10:44 pm

ok thanks for the help,



I think the problem is that the GetVMScriptVariable requires an actual persistent object with a script attached. So that's why i made the xMarker in the first place, attached the script to it with all the Properties.



I tried very hard to just access the Properties of Script A (xMarker) through Script B (book). only by making Script B a child of Script A was I able to access the Properties. I guess I could have imported it. Nevertheless it appeared to work. The CK.com solution appears to require I fill a ObjectReference variable of my book to then cast it as a script.



http://www.creationkit.com/index.php?title=Variables_and_Properties#Getting_Properties_From_Any_Other_Script



I'm sure i made this alot harder than i needed to and probably confused myself.

User avatar
Nims
 
Posts: 3352
Joined: Thu Jun 07, 2007 3:29 pm

Post » Fri Feb 10, 2017 9:25 pm

The ScriptB code in the example on that CK page is some the most convoluted an pointless code I've ever seen. And even then it only allows to you access the a second script attached to the same object. I'll go and change that page next so it doesn't cause anyone else the same headaches.



Accessing values of properties remotely is actually extremely easy. But You're right that for your conditions on the recipes you'll need those properties in a conditional script attached to a "persistent" object.




A conditional script on a quest is a fairly efficient way to handle a relatively large list of values you want to use with conditions.



I'll use a quest with editor id "RecipeMaster" for this example. The quest doesn't need to be running to serve as a holder for these shared properties. The important feature is that Quests are inherently "persistent" so you can always reference them. (But if you do start the quest later the existing values of variables could get reset to defaults which might be good or bad depending on your design.) You use the GetVMQuestVariable condition function to filter the recipes based on the property values in the script and you'll be able to change those properties from other scripts (shown below). The script on the quest will be very simple with just a collection of properties so it doesn't really matter if the quest is running or not.



ScriptName RecipeMasterScript extends Quest Conditional

int Property Option1 = 0 Auto Hidden Conditional
int Property Option2 = 0 Auto Hidden Conditional
int Property Option3 = 3 Auto Hidden Conditional
int Property Option4 = 0 Auto Hidden Conditional
int Property Option5 = 7 Auto Hidden Conditional

You can set whatever defaults you want and I highly recommend simply setting them in the script directly rather than trying to fill each one in the CK. (And of course you should give them better names or you'll go crazy trying to remember what each one controls.)



Then your configuration book (or books) can alter them with a script that has a property pointing to the quest.



ScriptName RecipeOptionSettingScript extends ObjectReference

RecipeMasterScript Property RecipeMaster Auto
; type is the script name and variable name is the editor id of the quest so it will auto-fill


Event OnRead()

; if you need the current value of an option you can get it with:
Debug.Notification("Recipe Option 1 is " + RecipeMaster.Option1)

; to change the value just assign to it:
RecipeMaster.Option1 = 42


EndEvent

That's it. As long as you create the quest script first then fill the book's script property it should all just work.

User avatar
Dale Johnson
 
Posts: 3352
Joined: Fri Aug 10, 2007 5:24 am

Post » Fri Feb 10, 2017 11:48 pm

:frog:



thank you. i was going crazy.



edit:



ALLOW ME TO EXPRESS MY ETERNAL GRATITUDE



:goodjob: :intergalactic: :mohawk: :tops: :thanks: :disco:




works without having start game enabled too. beautiful.



edit: and one final thing for the back of your mind, maybe you already know this but,



during my testing i found out you don't have to fill custom variable properties like bool or int. leaving them default seems to work,


this was born out of my fear that manually filling them in the script would cause them not to be overridden by my external script.

User avatar
Danel
 
Posts: 3417
Joined: Tue Feb 27, 2007 8:35 pm


Return to V - Skyrim