Jump to content

Why won't this script work?


Dyramisty

Recommended Posts

Hi guys,

 

I'm messing around with Papyrus and am currently stuck on something.

While compiling it tells me "Did you forget a cast?"

 

The code is:

 

Scriptname Base_Force_Menu_Activate_Object extends activemagiceffect  
{Forces the object to activate, eg. opening it's menu.}

ObjectReference Property PickFurniture auto

Event OnEffectStart(Actor akTarget, Actor akCaster)

PickFurniture.Activate(Self)

EndEvent

 

Hope someone is able to help me out on this one!

Cheers.

Link to comment
Share on other sites

The numbers that came with the error message give you the line number and the position in that line at which the error occurs.

 

'Did you forget a cast?' means that the variable at that position is the wrong type for the function that you've called.

 

In your case, the error is most likely referring to the use of the Self variable. Self in a script referrs to the form to which the script is attached, in this case the active magic effect.

 

Replace Self with PickFurniture, like so.

 

PickFurniture.Activate(PickFurniture)

Link to comment
Share on other sites

Self is reserved for the object running the script or in some cases the script itself.

 

The Activate command breaks down as follows:

"Object to activate". Activate("Actor to interact with")

 

So in your existing code, if you have no care about who activates the object then use akCaster directly.

 

If you'd like to ensure that the akCaster is indeed the player then you need to add in a check for that. i.e.

 

 

Scriptname Base_Force_Menu_Activate_Object extends activemagiceffect  
{Forces the object to activate, eg. opening it's menu.}

ObjectReference Property PickFurniture auto

Event OnEffectStart(Actor akTarget, Actor akCaster)

If akCaster == Game.GetPlayer()
   PickFurniture.Activate(akCaster)
EndIf

EndEvent

 

 

Link to comment
Share on other sites

Self is reserved for the object running the script or in some cases the script itself.

 

The Activate command breaks down as follows:

"Object to activate". Activate("Actor to interact with")

 

So in your existing code, if you have no care about who activates the object then use akCaster directly.

 

If you'd like to ensure that the akCaster is indeed the player then you need to add in a check for that. i.e.

 

 

Scriptname Base_Force_Menu_Activate_Object extends activemagiceffect  
{Forces the object to activate, eg. opening it's menu.}

ObjectReference Property PickFurniture auto

Event OnEffectStart(Actor akTarget, Actor akCaster)

If akCaster == Game.GetPlayer()
   PickFurniture.Activate(akCaster)
EndIf

EndEvent

 

 

 

Noted down your way too, already got a solution running now but your info will surely be useful in the future, thanks!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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