Jump to content

New to scripting...what's wrong with my script?


Rayek

Recommended Posts

Purpose of script: Disable some bones and a couple of arrows while at the same time enabling a gravestone and dirt pile.

 

I've followed a tutorial exactly as far as I can tell and am unable to get it to work.

 

When trying to compile the script I get a couple of Papyrus compiling errors:

 

"No viable alternative at input 'X"'

 

and

 

"Required (...)+ loop did not match anything at input 'X"'

 

I have read the reason is the compiler didn't expect X and so cannot compile the element...likely a result of a malformed line or missing part.

 

My first attempt at making my own script looks like this:

 

Scriptname RE_BurialScript extends ObjectReference  


ObjectReference Property LeftArm Auto
ObjectReference Property RightArm Auto
ObjectReference Property LeftLeg Auto
ObjectReference Property RightLeg Auto
ObjectReference Property LeftHand Auto
ObjectReference Property RightHand Auto
ObjectReference Property LeftFoot Auto
ObjectReference Property RightFoot Auto
ObjectReference Property Skull Auto
ObjectReference Property RibCage Auto
ObjectReference Property KneeArrow Auto
ObjectReference Property ChestArrow Auto
ObjectReference Property GraveStone Auto
ObjectReference Property GraveDirt Auto


EventOnActivate(ObjectReference akActionRef)
  If akActionRef == Game.GetPlayer()
    LeftArm.Disable()
    RightArm.Disable()
    LeftLeg.Disable()
    RightLeg.Disable()
    LeftHand.Disable()
    RightHand.Disable()
    LeftFoot.Disable()
    RightFoot.Disable()
    Skull.Disable()
    RibCage.Disable()
    KneeArrow.Disable()
    ChestArrow.Disable()
    GraveStone.Enable()
    GraveDirt.Enable()
  Endif
Endevent
Any help on what I'm doing wrong is of course appreciated...
Edited by Rayek
Link to comment
Share on other sites

Now this is not directly related to your issue (which I think KunoMochi solved, since I cannot see anything else that could be wrong in your script), but another idea for tweaking the script, considering the large number of discrete ObjectReferences that each have their own Property, could be to try out an array or a FormList. An array is basically just a list of objects of a specific type, for example integer, float, Actor, ObjectReference and whatnot. With all the ObjectReferences stored in a list of sorts (array), you could easily loop through the list and disable or enable everything in it. For example like this:

ScriptName RE_BurialScript Extends ObjectReference

ObjectReference[] Property ToEnable Auto ; brackets make it an array, put the things to enable here
ObjectReference[] Property ToDisable Auto ; an array of all the things to disable

Event OnActivate(ObjectReference akActionRef)

    If (akActionRef == Game.GetPlayer())

        Int i = ToEnable.Length  ; each array has this property which contains its length

        While (i > 0)    ; indexes go from 0 to length-1
            i -= 1       ; decrease i by one, as in, move to the next index, towards 0
            If (ToEnable[i] && ToEnable[i].IsDisabled())
                ToEnable[i].Enable()
            EndIf
        EndWhile

        i = ToDisable.Length

        While (i > 0)
            i -= 1
            If (ToDisable[i] && ToDisable[i].IsEnabled())
                ToDisable[i].Disable()
            EndIf
        EndWhile

    Endif

Endevent

Filling an array property works just like filling any other property, except that it will look like a list, and you can add a whole bunch of objects (of the type of the array, in this case, ObjectReferences) in that list (although there might be a size limit of 128).

 

The wiki page on arrays is here: http://www.creationkit.com/index.php?title=Arrays_(Papyrus)

 

Another solution could be to:

  • have one ObjectReference property in the script, pointing at one ObjectReference in the gameworld (for example the tombstone) and set that in-game ObjectReference (tombstone) as "intially disabled" to have it disabled at first
  • set the "enable parent" for each ObjectReference in-game to be enabled with the tombstone to point to that tombstone, and make sure the "state opposite to parent" (or such, cannot remember exatly) is NOT checked (this will make the ObjectReferences copy the enable/disable status of the enable parent, in this case, the tombstone)
  • for the items to be disabled with the tombstone, also set the tombstone as the enable parent, but make sure the "state opposite to parent" (or such) IS CHECKED (this will make the items to copy the state of the enable parent, but invert it, so that when the tombstone is enabled, they are disabled, and when the tombstone is disabled, they are enabled)

With the enable parent system, you could make your script with just one ObjectReference:

ScriptName RE_BurialScript Extends ObjectReference

ObjectReference Property EnableParentOfAll Auto ; this one points to the enable parent of all the refs

Event OnActivate(ObjectReference akActionRef)

    If (akActionRef == Game.GetPlayer() && EnableParentOfAll.IsEnabled())
        EnableParentOfAll.Disable()
    EndIf

EndEvent

There might even be an existing in-game script for a single ObjectReference, I think (I have not checked) that you could use. It sounds like something the game developers could have used themselves in many places (by reusing the same script thanks to Properties).

 

Also, those are both just ideas, something to think about, in case you one day end up having to enable and disable a massive amount of ObjectReferences. There is nothing wrong with your current script as it is (except for that one pointed out by KunoMochi). :thumbsup:

 

Edit: Ooops. The text editor makes one incredible mess out of lists... :tongue: Now it should look like a list again.

Edited by Contrathetix
Link to comment
Share on other sites

I figured it would be something simple and perhaps obvious to one who hasn't been staring at it for some time.

 

Thank you @KunoMochi

 

Also I really appreciate the possible alternatives @Contrathetix.

 

It sparked another thought of possibly condensing the multiple object references down to 2 Xmarkers...one that represents enable and disable.

 

If I enable parent the appropriate item to the appropriate marker...check the initially disable on the Xmarker for the items that are to be enabled it seems like it would work as well? Condensing the script down to just a couple object references and actions.

 

But again, I am new to this...but having fun learning as I go.

 

Again, thank you both...will be experimenting with those ideas.

Link to comment
Share on other sites

No problem. Alternatives are usually great food for thought. :)

 

What you are describing could also be done with a single enable parent. For example, if you did this:

  • for the dirt pile, set the tombstone as the enable parent and make sure "state opposite to parent" is un-checked
  • for each bone, set the tombstone as the enable parent and make sure "state opposite to parent" is checked
  • set the tombstone to "initially disabled"
  • in the script, enable the tombstone when appropriate

So that, instead of two xmarkers, you would have one single tombstone. When that tombstone would be disabled, all the bones would have the opposite state (enabled) and the dirt pile the identical state (disabled). When the tombstone would be enabled, all the bones would have the opposite state (disabled) and the dirt pile the identical state (enabled). You can use the "state opposite to parent" tickbox in the enable parent tab of each reference to determine whether the enable state of that reference should be the same as the parent or the oppsite to it.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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