Magicockerel Posted December 10, 2018 Share Posted December 10, 2018 I'm having trouble remotely running a function in a script that is attached to an alias from a script that is attached to another alias (in the same quest). The scripts can be simplified to the following: Actor Property PlayerRef Auto Const Mandatory ReferenceAlias Property OtherAlias Auto Const Mandatory Event OnAliasInit() Self.RegisterForDetectionLOSGain(akViewer = PlayerRef, akTarget = Self.GetReference()) EndEvent Event OnGainLOS(ObjectReference akViewer, ObjectReference akTarget) If (akViewer == PlayerRef && akTarget == Self.GetReference()) OtherAlias.GetReference().TheFunctionIWantToRun() EndIf EndEvent Function TheFunctionThatIWantToRun() ; Do things EndFunction The error that it is giving me is "TheFunctionIWantToRun is not a function or does not exist" when I try to compile the top script, the bottom script of course compiles without any issues. For reference, I do get the same error when I get rid of GetReference() and change the line to "OtherAlias.TheFunctionIWantToRun()". This would suggest that the script isn't actually attached to the object in a way that Papyrus can detect, given that it is only attached while it has that alias. Hopefully I'm overlooking something simple and there's a quick fix. I can work around this issue, but I'd rather not. If I'm forgetting any information that could be helpful, please do let me know. Thanks in advance for any assistance you're able to provide. Link to comment Share on other sites More sharing options...
Reneer Posted December 10, 2018 Share Posted December 10, 2018 You want something like this: (OtherAlias.GetReference() As OtherScriptName).TheFunctionIWantToRun() Link to comment Share on other sites More sharing options...
Magicockerel Posted December 10, 2018 Author Share Posted December 10, 2018 You want something like this: (OtherAlias.GetReference() As OtherScriptName).TheFunctionIWantToRun() Thanks for taking the time to respond. I forgot to include this in the OP, but I did also try this and received the following compilation error: "cannot cast a ObjectReference to a OtherScriptName, types are incompatible". If it's of any assistance, both scripts extend ReferenceAliases, given that's what they're attached to. Link to comment Share on other sites More sharing options...
Reneer Posted December 10, 2018 Share Posted December 10, 2018 Oh, then you probably want: (OtherAlias As OtherScriptName).TheFunctionIWantToRun() Link to comment Share on other sites More sharing options...
SKKmods Posted December 10, 2018 Share Posted December 10, 2018 (edited) I have not found a way to call a script attached to a quest alias. The format suggested by reneer looks like it should work, but it just doesn't. The most elegant workaround I have used is for the calling script to send a custom event that the alias script listens for: ;Main Script CustomEvent CrunchPlayerJunkChanged ; Notify Alias_PlayerREFScript that holotape has changed GlobalVariable SKK_ScrapperCrunchPlayerJunk SendCustomEvent("CrunchPlayerJunkChanged", kArgs) ;Alias_PlayerREFScript RegisterForCustomEvent(pSKK_ScrapperMainScript, "CrunchPlayerJunkChanged") Event SKK_ScrapperMainScript.CrunchPlayerJunkChanged(SKK_ScrapperMainScript akSender, Var[] akArgs) CrunchPlayerJunkFilter() EndEvent A cut price K-mart version would be to run a polling timer in the alias script checking for a calling script variable property or global variable. Have even used an inventoryeventfilter on an actor so the calling script can silently place an object triggering the event. That's rather brittle. Edited December 10, 2018 by SKK50 Link to comment Share on other sites More sharing options...
Reneer Posted December 10, 2018 Share Posted December 10, 2018 (edited) The SendCustomEvent is what I've used in my mods in the past, since it works well and goes to each alias that is registered for it all at once. It's weird though that calling the function on the Alias like that doesn't work, but I guess I never thought to do it that particular way. Edited December 10, 2018 by Reneer Link to comment Share on other sites More sharing options...
Magicockerel Posted December 10, 2018 Author Share Posted December 10, 2018 Oh, then you probably want: (OtherAlias As OtherScriptName).TheFunctionIWantToRun() I don't know why I didn't try this, but you're right this works, thanks. I'll pass it off as being tired, haha. I have not found a way to call a script attached to a quest alias. The format suggested by reneer looks like it should work, but it just doesn't. The most elegant workaround I have used is for the calling script to send a custom event that the alias script listens for: ;Main Script CustomEvent CrunchPlayerJunkChanged ; Notify Alias_PlayerREFScript that holotape has changed GlobalVariable SKK_ScrapperCrunchPlayerJunk SendCustomEvent("CrunchPlayerJunkChanged", kArgs) ;Alias_PlayerREFScript RegisterForCustomEvent(pSKK_ScrapperMainScript, "CrunchPlayerJunkChanged") Event SKK_ScrapperMainScript.CrunchPlayerJunkChanged(SKK_ScrapperMainScript akSender, Var[] akArgs) CrunchPlayerJunkFilter() EndEvent A cut price K-mart version would be to run a polling timer in the alias script checking for a calling script variable property or global variable. Have even used an inventoryeventfilter on an actor so the calling script can silently place an object triggering the event. That's rather brittle. Reneer's second suggestion works for me, so you may want to try that. I appreciate your input all the same, the custom event approach is a pretty good workaround. If you're having troubles you can PM me and I'll send you my mod files so that you can see what we've done differently. The SendCustomEvent is what I've used in my mods in the past, since it works well and goes to each alias that is registered for it all at once. It's weird though that calling the function on the Alias like that doesn't work, but I guess I never thought to do it that particular way. I've found the custom event approach to be preferable if you're either remotely communicating with a large number of scripts or you want to do so indirectly for whatever reason (I suppose it saves you some properties, etc.). Bethesda even choose to sometimes send out custom events when there are actual events that do the same thing (e.g. OnWorkshopObjectPlaced() and other workshop based events), which is odd. Link to comment Share on other sites More sharing options...
SKKmods Posted December 10, 2018 Share Posted December 10, 2018 It would be wonderful, but just tried it again and still doesn't compile with "is not a function". Oh yes it is ! (Alias_PlayerRef as SKK_ScrapperPlayerRefAliasScript).CrunchPlayerJunkFilter() The custom event is working fine in production, sticking with that. Link to comment Share on other sites More sharing options...
Recommended Posts