Jump to content

Parent/Child Script - accessing child function help


LeianneH

Recommended Posts

;This is the PARENT Script
Script myParent extends ObjectReference
 
String PlayerChair
; whole bunch more variables declared
 
 
Event OnTriggerEnter(ObjectReference akActionRef)
     if akActionRef == PlayerREF
	Utility.Wait(2.5)
        ;calling external script above, using function - no problem!
        
        ;NOW need to call Child script function
        myChild.myFunction(PlayerChair)  ;does not work
     endif
EndEvent
 
;This is the CHILD Script
Script myChild extends myParent
 
String Function myFunction(String akString)
      ;do something and return to parent script
EndFunction

I'm having trouble with my scripts and was hoping someone might be able to help me with this bit ...

 

I have a Parent script and I've made a Child script that extends the Parent

 

I can use the external script Utility and access it's Wait Function just fine .... but when I try to access myFunction from the myParent script I have, I get the error; Cannot call the member function myFunction alone or on a type, must call it on a variable

 

Anyone have any idea why it will not allow me to access the function in the child script?

Have tried; myFunction() ; using import myChild ... and myChild.myFunction() .... not working. sigh.

 

EDIT: The ONLY reason I am trying to make a CHILD script holding functions to be accessed by my PARENT script is .... I am at line 912 in my script (which works perfectly with the functions inside of it) - BUT my script will NOT ALLOW ME TO ADD A SINGLE CHARACTER MORE!!!! Is there some OTHER way to overcome this restriction?

Edited by LeianneG
Link to comment
Share on other sites

You've got the parent/child thing backwards conceptually. Child scripts inherit functions from their parents but not the other way around.

 

What object is the child script attached to? If it's the same ObjectReference as the parent script, your child script could extend ObjectReference and then your parent could call (Self as myChild).myFunction( .. ) but that's not using inheritance. Essentially, the two scripts become siblings.

 

What you could also do, is to attach the child script to the base object and the parent script to the placed instance. Then the inheritance would work. Just the names would be misleading.

Edited by OldMansBeard
Link to comment
Share on other sites

Yeah, saw that my inheritance is backwards .. sigh, inherits UP not down - also the reason I can call Utility.Wait() - or just Wait() is because the function is compartmentalized and is declared as a global. The function in the 'Child' that I need to access from the 'Parent' requires variables from the 'Parent' ... so can't make the function global.

Arrghhh ... my head is starting to hurt!

 

Is there ANY way that I can 'bypass' this apparent character/line restriction on the script? It's just SO darn handy having all my functions in the ONE script!

 

Edit: They are both attached to the same ObjectReference (DefaultTrigger) so making them siblings would probably be the most efficient, if not the most elegant option. Because it's a default trigger, can't add the 'child' to the base object unless I copy it and make a 'myDefaultTrigger' ... which isn't really an issue. But I never thought of the sibling - appreciate you suggesting it

Edited by LeianneG
Link to comment
Share on other sites

There's no script length limit if you use an external text editor instead of the Creation Kit editor. So if your only problem is script length I recommend just editing that script externally and compiling outside of the CK. You can still use the CK to attach the script to objects and fill properties, you just won't be able to edit it after it gets too large. The CK Wiki has info about setting up an external editor.

Link to comment
Share on other sites

Thank you so much! Both you, OldMansBeard and you, Cdcooley - I will keep the larger file because it works flawlessly, and I'm only introducing errors by trying to farm out my functions :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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