lord_vader Posted January 4, 2016 Posted January 4, 2016 I want to write a code that will trigger specific animations and repeat it when an actor activates an a item. The code works perfectly without the while loop. However with the while loop the code compiles successfully but the actor in the game doesn't perform the animations just stands still . Could you please help me ? Scriptname seat extends ObjectReference Armor Property armour Autoint x= 0 Event OnActivate(ObjectReference akActionRef) Actor akt = akActionRef as Actorwhile x<1 Debug.SendAnimationEvent(akt, "anim1") Utility.wait(2) akt.EquipItem(armour, true) Utility.wait(15) Debug.SendAnimationEvent(akt, "anim2") Utility.wait(15) akt.RemoveItem(armour) Debug.SendAnimationEvent(akt, "anim3"") Utility.wait(1) Debug.SendAnimationEvent(akt, "anim4"") Utility.wait(5) Debug.SendAnimationEvent(akt, "anim5"") endwhile endevent
Guest Posted January 4, 2016 Posted January 4, 2016 HI. Doing an infinite loop is a really bad idea. No matter what. And probably you get stuck, because the very first time the event is managed, (and probably not by an actor), then the papyrus execution loops forever and will never receives a second event (it actually receives it but cannot handle it because there is a REALLY BAD infinite loop.) Now, what are you trying to do? Is the animation "anim1" something you creates? Is is from a mod? It is a vanilla anim? If it is your (but works also in the other cases) you can simply make it cyclic in the FNIS definition, so you DON'T have to cycle with a loop like this that will just break the game engine.
lord_vader Posted January 4, 2016 Author Posted January 4, 2016 Dear CPU, Thank you for your reply anim1 is an animation from a mod. Is it ok to make my script loop ten times as shown below ? Scriptname seat extends ObjectReference Armor Property armour Autoint x= 0Event OnActivate(ObjectReference akActionRef)Actor akt = akActionRef as Actorwhile x<10Debug.SendAnimationEvent(akt, "anim1")Utility.wait(2)akt.EquipItem(armour, true)Utility.wait(15)Debug.SendAnimationEvent(akt, "anim2")Utility.wait(15)akt.RemoveItem(armour)Debug.SendAnimationEvent(akt, "anim3"")Utility.wait(1)Debug.SendAnimationEvent(akt, "anim4"")Utility.wait(5)Debug.SendAnimationEvent(akt, "anim5"") x +=1endwhileendevent But the problem here is that the code won't compile it says that X isn't an object reference, how can I fix that?
Guest Posted January 5, 2016 Posted January 5, 2016 You put the "int x=0" outside the event, so it is not reachable. Scriptname myAnimationSeat extends ObjectReference Armor Property armour Auto Event OnActivate(ObjectReference akActionRef) Actor akt = akActionRef as Actor int x=10 while x i -= 1 Debug.SendAnimationEvent(akt, "anim1") Utility.wait(2.0) akt.EquipItem(armour, true) Utility.wait(15.0) Debug.SendAnimationEvent(akt, "anim2") Utility.wait(15.0) akt.RemoveItem(armour) Debug.SendAnimationEvent(akt, "anim3") Utility.wait(1.0) Debug.SendAnimationEvent(akt, "anim4") Utility.wait(5.0) Debug.SendAnimationEvent(akt, "anim5") endWhile endEvent If you have compile errors, just copy/paste the errors here. The line numbers give you a huge amount of info.
lord_vader Posted January 5, 2016 Author Posted January 5, 2016 You put the "int x=0" outside the event, so it is not reachable. Scriptname myAnimationSeat extends ObjectReference Armor Property armour Auto Event OnActivate(ObjectReference akActionRef) Actor akt = akActionRef as Actor int x=10 while x i -= 1 Debug.SendAnimationEvent(akt, "anim1") Utility.wait(2.0) akt.EquipItem(armour, true) Utility.wait(15.0) Debug.SendAnimationEvent(akt, "anim2") Utility.wait(15.0) akt.RemoveItem(armour) Debug.SendAnimationEvent(akt, "anim3") Utility.wait(1.0) Debug.SendAnimationEvent(akt, "anim4") Utility.wait(5.0) Debug.SendAnimationEvent(akt, "anim5") endWhile endEvent If you have compile errors, just copy/paste the errors here. The line numbers give you a huge amount of info. I received the following errors with your modifications .psc(11,12): property x on script objectreference is read-only, you cannot give it a value ..psc(11,12): type mismatch while assigning to a none (cast missing or types unrelated)
Guest Posted January 5, 2016 Posted January 5, 2016 yes. Your script extends"ObjectReference". And "ObjectReference" has an intrinsic property called "x", to define the location of the reference (X, y, z) Change your X to I.
Guffel Posted January 5, 2016 Posted January 5, 2016 Hi there, i want to say that a while loop is really not a good solution at all. A while loop repeates itself very fast, about 30 to 50 per second is my guess. Its good for sorting an array or searching inventories, but gives papyrus very much stress when running for a longer time. You should better use an OnUpdate event here. So you want to play the 5 animation in a row, once? Or shall this repeat on its own again and again? I recommend you do something like this: Scriptname myAnimationSeat extends ObjectReference Armor Property armour Auto Actor Property akt Auto ;make the actor an propery so the OnUpdate event can use it Event OnActivate(ObjectReference akActionRef) akt = akActionRef as Actor RegisterForSingleUpdate(0.1) ; register for a single update in 0.1 sec, basically instant endEvent Event OnUpdate() ; this event now only fires once and doesn't repeat while still running Debug.SendAnimationEvent(akt, "anim1") ; the animations play as usual Utility.wait(2.0) akt.EquipItem(armour, true) Utility.wait(15.0) Debug.SendAnimationEvent(akt, "anim2") Utility.wait(15.0) akt.RemoveItem(armour) Debug.SendAnimationEvent(akt, "anim3") Utility.wait(1.0) Debug.SendAnimationEvent(akt, "anim4") Utility.wait(5.0) Debug.SendAnimationEvent(akt, "anim5") RegisterForSingleUpdate(0.1) ; starting over by triggering the OnUpdate event again endEvent This script would now run forever! Is that really what you want? I don't really recommened this. You really should do it a time limit or some other condition for it to stop, like if the player has a line of sight to it or if the activation objects 3d model is loaded. If you'd tell me more about what you're planning I could give you more specific advise^^ Hope that helps anyway
Recommended Posts
Archived
This topic is now archived and is closed to further replies.