Zatronium Posted September 2, 2014 Share Posted September 2, 2014 (edited) How does one refer to the script of an ActiveMagicEffect on another Actor? I've tried several different ways, but the compiler keeps complaining that I'm trying to do arithmetic on type "None" or it just rejects the code as being malformed. The idea is that the effect referenced in the UpdateEffectValues function will grab info from the script on another ActiveMagicEffect on the same target and apply changes. I'm aware that I can maintain an array of values on the Player, but this seems inefficient because the array will need to hold a lot of NPCs. I want to avoid the reference caching that will become necessary with such a solution. Applying papyrus scraps to each affected NPC seems a lot more reasonable because then each effect is managed by the game rather than my own code. I'm aware that I can store the values inside the effect itself, but since I don't know how to reference that specific instance of the effect, it doesn't really matter at the moment. Anyway, here's my most recent attempt. ActiveMagicEffect Property ManagerRef Auto ;The effect script storing the values is just called Manager for now. Function UpdateEffectValues(Actor Ref, String Name) Int Iterator = 0 Int SpellCount = Ref.GetSpellCount() While SpellCount > Iterator Spell TempSpellCache = Ref.GetNthSpell(Iterator) If TempSpellCache.GetName() == Name TempSpellCache.SetNthEffectMagnitude(0, Ref.(ManagerRef as Manager).Magnitude * MagnitudeScale.GetValue()) ;Does not work Return EndIf EndWhile EndFunctionThis is the first mod that I've written, but I know several other languages. If I'm doing something oxymoronic... That's why. Lol. Thanks. Edited September 2, 2014 by Zatronium Link to comment Share on other sites More sharing options...
lofgren Posted September 2, 2014 Share Posted September 2, 2014 I believe it should look like this: TempSpellCache.SetNthEffectMagnitude(0, (Ref as Manager).Magnitude * MagnitudeScale.Value) Assuming Magnitude is a property of Ref declared in the Manager script attached to Ref. Link to comment Share on other sites More sharing options...
Zatronium Posted September 2, 2014 Author Share Posted September 2, 2014 (edited) Ah. That makes a lot more sense, but the compiler complains "Cannot cast an actor to a Manager, types are incompatable." I suppose that happens because the script isn't attached to the actor itself but instead to a magic effect that would be applied during gameplay. So, I tried to refer to the spell which contains the Magic Effect (this takes the Actor reference out of the equation) but it still didn't work: Function UpdateEffectValues(Actor Ref, String Name) Int Iterator = 0 Int SpellCount = Ref.GetSpellCount() Spell[] SpellCache While SpellCount > Iterator Spell TempSpellCache = Ref.GetNthSpell(Iterator) If TempCache.GetName() == Name SpellCache[0] = TempCache EndIf If TempCache.GetName() == "Manager" SpellCache[1] = TempCache EndIf EndWhile SpellCache[0].SetNthEffectMagnitude(0, (SpellCache[1].GetNthEffectMagicEffect(0) as Manager).Magnitude * MagnitudeScale.GetValue()) EndFunction The compiler error is " cannot cast a magiceffect to a manager, types are incompatible." This is probably because "MagicEffect" is different from "ActiveMagicEffect." Go figure. MagicEffect extends "Form" while ActiveMagicEffect does not. Is there any way to reconcile this difference? Or am I attacking this from the wrong angle? Edited September 2, 2014 by Zatronium Link to comment Share on other sites More sharing options...
lofgren Posted September 2, 2014 Share Posted September 2, 2014 Technically activemagiceffect extends actor. You could try casting the actor as the script. Link to comment Share on other sites More sharing options...
Zatronium Posted September 2, 2014 Author Share Posted September 2, 2014 (edited) Yeah, I've tried that a couple of different ways. Not sure what I'm doing wrong because it isn't working. Edited September 2, 2014 by Zatronium Link to comment Share on other sites More sharing options...
Zatronium Posted September 4, 2014 Author Share Posted September 4, 2014 (edited) Why does the compiler keep complaining that the magic effect is an unknown type? I tried compiling a test script inside a magic effect named "TestEffect" containing only one variable. Again, I was unable to access this script. SpellCache[0].SetNthEffectMagnitude(0, (TestSpell.GetNthEffectMagicEffect(0) as TestEffect).CanIAccessThis) C:\Program Files (x86)\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\Manager.psc(145,82): cannot convert to unknown type testeffectC:\Program Files (x86)\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\Manager.psc(145,82): cannot cast a magiceffect to a testeffect, types are incompatibleC:\Program Files (x86)\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\Manager.psc(145,94): testeffect is not a known user-defined type I tried declaring the TestEffect as both an ActiveMagicEffect or a MagicEffect, neither seemed to make any difference as they both returned "unknown type" at compile time. Edited September 4, 2014 by Zatronium Link to comment Share on other sites More sharing options...
Zatronium Posted September 4, 2014 Author Share Posted September 4, 2014 (edited) Aha, changing the script itself to a MagicEffect instead of an ActiveMagicEffect allowed the reference to be passed correctly. I guess you can't reference ActiveMagicEffect scripts via their parent: they're an unknown type because they don't explicitly extend Actor, instead they implicitly extend Actor at runtime as was mentioned by Iofgren. This means you can't reference a dynamically attached ActiveMagicEffect; it must be attached to the Actor at compile time. Whew. Hope that helps anyone who has a similar problem. I'll update this if it doesn't work when I test it in-game. Edited September 4, 2014 by Zatronium Link to comment Share on other sites More sharing options...
lofgren Posted September 4, 2014 Share Posted September 4, 2014 Useful info! If you have a minute might want to add whatever you learned to the wiki. Link to comment Share on other sites More sharing options...
Recommended Posts