Jump to content

Can't attach 2 "identical" scripts to an object?


Recommended Posts

Good late evening / early morning everybody!

 

I have made a script that rotates an object when a quest stage is reached.

It has "DegreesToRotate" and "QuestStage" as parameters, aehm I mean properties.

I might use this for a lot of different things, so it is kept as simple as possible.

 

Now, I want to attach two of those scripts to an object.

One that rotates the object to 0° when the quest stage is 0 and one to rotate the object to 90° when the quest stage is 10.

 

But I can't.

I can attach the first script without any problems.

But when I click "Add script" to add the second script, it doesn't show up in the "script selection window".

 

 

So it appears that you can only have one "instance" of a script attached to an object.

Sad ...

Link to comment
Share on other sites

Like dylbill said, you can use a struct array for this, with two members in the struct:

Struct RotationDescriptor
    Int QuestStageReached
    Float AngleZ
EndStruct

Then use an array property of type RotationDescriptor:

RotationDescriptor[] Property RotationDescriptors Auto Const

You can fill this in CK.

Use the remote event from your other post to receive quest stage change, leverage FindStruct to locate the particular descriptor for the received quest stage in the RotationDescriptors Array and apply AngleZ from the descriptor to Self, if found.

Link to comment
Share on other sites

Nice idea to use a struct array. I've never used one so I edited the other code I posted to include so I could see what it looks like in the CK. Pretty cool. Would this code work properly?

Quest Property MyQuest Auto 
RotationDescriptor[] Property RotationDescriptors Auto
Int Count = 0

Event OnInit() 
    RegisterForRemoteEvent(MyQuest, "OnStageSet") 
EndEvent 

Event Quest.OnStageSet(Quest akSender, int auiStageID, int auiItemID)
    Int Index = RotationDescriptors.FindStruct("QuestStageReached", auiStageID) 
    If Index > 0 
        Self.SetAngle(Self.GetAngleX(), Self.GetAngleY(), RotationDescriptors[Index].AngleZ)
        Count += 1 
        If Count >= RotationDescriptors.Length ;if all stages have passed, unregister for the event.
            UnRegisterForRemoteEvent(MyQuest, "OnStageSet") 
        Endif
    Endif
EndEvent
    
Struct RotationDescriptor
    Int QuestStageReached
    Float AngleZ
EndStruct
Link to comment
Share on other sites

It might work. :smile:

 

You could replace the check with the counter for a 3rd entry in the rotationdescriptor, Bool LastStage or something. So the entries in the array don't need to be in order.

Yeah that would work too. I was thinking the count only increases if it finds an applicable stage, so they also wouldn't need to be in order then.

 

The index 0 of an array is a valid index, the condition should be If Index > -1

Good catch, I don't know what I was thinking. Probably if Index >= 0

 

Granted, when it comes to scripting I am a novice but I'll ask the question nonetheless. Could you not just use the DefaultRotateHelper script and call the doRotate function from a fragment within the quest?

Yes you could do that. I think this is more for if you're trying to catch vanilla quest stages and don't want to edit the quest directly for compatibility reasons.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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