z4x Posted February 25, 2013 Share Posted February 25, 2013 Scriptname TEST extends ObjectReference Actor Property PC Auto Armor Property Armor1 Auto Potion Property Potion1 Auto Sound Property Sound1 Auto GlobalVariable Property Count1 Auto Event OnEquipped(Actor akActor) Utility.Wait(1.0) If (akActor == Game.GetPlayer()) Function1(akActor) Debug.notification("TEST1") EndIf EndEvent Event OnUnequipped(Actor akActor) If (akActor == Game.GetPlayer()) Debug.notification("TEST2") EndIf EndEvent Function Function1(Actor akActor) ActorBase Wearer = akActor.GetBaseObject() as ActorBase Int CountVal = Count1.GetValue() as Int ;reads global Count1 from game? Debug.notification("TEST3|) if (akActor.isEquipped(Armor1)) ;checks if armor equipped then plays sound int instanceID = Sound1.Play(akActor) while (akActor.isEquipped(Armor1)) && (CountVal > 3) ;checks if global count > 3 akActor.AddItem(Potion1, 1) CountVal = CountVal - 1 ;decreases count by one Count1.setValue(CountVal) ;sets changed count as global IN GAME count Debug.notification("TEST4") endwhile Sound.StopInstance(instanceID) Debug.notification("TEST5") endif EndFunction Count1 global value is set by another script and in CK as global so its hold by game. Its supposed to play sound (all the time) while equipping armor as well as spawning items/potions (till count >3) Its compiling fine, but in game it goes till TEST3 debug message (showing correctly the number from other script), then its stuck. Thanks in adavance! Link to comment Share on other sites More sharing options...
unuroboros Posted February 25, 2013 Share Posted February 25, 2013 Script is attached to the armor object, I'm assuming. You've double-checked the value of the Armor1 Property? Tried a clean save? (Changes to Properties can behave strangely in a savegame where that script already exists, already with that Property.) The only thing that really stands out to me is that your while loop depends on both the armor being equipped and CountVal already being greater than 3. Maybe try: Debug.Notification("TEST3. CountVal is: " + CountVal) Link to comment Share on other sites More sharing options...
z4x Posted February 25, 2013 Author Share Posted February 25, 2013 Script is attached to the armor object, I'm assuming. Yeah. The only thing that really stands out to me is that your while loopdepends on both the armor being equipped and CountVal already beinggreater than 3. I wanted sound to play when armor is equipped even if CountVal doesnt match. And play sound + 2nd effect while both are TRUE. Maybe try: Debug.Notification("TEST3. CountVal is: " +CountVal) Tried this, and it shows correct CountVal from other script/game. Any other ideas what could be wrong? Link to comment Share on other sites More sharing options...
VectorPlexus Posted February 25, 2013 Share Posted February 25, 2013 Function1(Actor akActor)? would that work? or if not, set akActor first as a property, because I'm not sure if the akActor can only be accessed by the Event. If so, the function is not passing anything at all. Link to comment Share on other sites More sharing options...
unuroboros Posted February 25, 2013 Share Posted February 25, 2013 I've passed around Actors (and every other kind of type) between functions without problems. The only time you do have to be careful is with an ObjectReference changing containers, since the reference ceases to exist when it goes into a(nother) container - meaning OnContainerChanged can only really make use of its 'self' when dropping items. z, I'm kinda stumped, but I think you're on the right track with the Debug "breakpoints", and I'd suggest adding two more: a TEST4 just inside the IsEquipped block, and a TEST5 just inside the While block. One of those has got to be the culprit, but which? Link to comment Share on other sites More sharing options...
Recommended Posts