wyz123 Posted August 24, 2016 Share Posted August 24, 2016 (edited) I added a perk to the player that can let the sole survivor pick up food item and eat directly. Here is my code. ScriptName GrabAndEat Extends Quest ; Properties Perk Property GrabAndEatPerk Auto Const Message Property GrabAndEatMSG_Enabled Auto Const Message Property GrabAndEatMSG_Disabled Auto Const ; Keyword Keyword Property ObjectTypeFood Auto const ; variables Form Item = None Actor PlayerRef Event OnQuestInit() On() EndEvent Function On() If (!Game.GetPlayer().HasPerk(GrabAndEatPerk)) Game.GetPlayer().AddPerk(GrabAndEatPerk,False) GrabAndEatMSG_Enabled.Show(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0) EndIf EndFunction Function Grab(ObjectReference akTargetRef) GotoState("Busy") PlayerRef=Game.GetPlayer() Debug.trace("Grab() oprerating...") Item=akTargetRef.GetBaseObject() Debug.trace("Item is "+Item) Debug.Trace("prepare to pick up",0) ;game freezes after calling Activate() 11 or 12 times akTargetRef.Activate(PlayerRef,True); Debug.Trace("picked up food",0) Game.GetPlayer().EquipItem(Item,False,True) Debug.Trace("Equiped",0) Utility.wait(2.5) GotoState("") EndFunction State Busy Function Grab(ObjectReference akTargetRef) Debug.Notification("You are chewing") Debug.trace("Grab() BUSY state.",0) EndFunction EndState and the perk fragment code that calls GrabController.Grab() ;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment Scriptname PRKGrabAndEat Extends Perk Hidden Const GrabAndEat Property GrabController Auto Const Mandatory ;BEGIN FRAGMENT Fragment_Entry_00 Function Fragment_Entry_00(ObjectReference akTargetRef, Actor akActor) ;BEGIN CODE GrabController.Grab(akTargetRef) ;END CODE EndFunction ;END FRAGMENT ;END FRAGMENT CODE - Do not edit anything between this and the begin comment Everything works fine except that the game always freezes when you pick up 12th or 13th item. After a few trials and errors I found that it has something to do with akTargetRef.Activate(PlayerRef,True) cause freeze always occurs after the game calls that function 11 or 12 times. I can't figure out why Active() causes the problem and why it happens on 12th or 13th call. Is Active() different from pressing active button ? Does anybody know how to solve this problem? I'm not a native speaker and sorry for my poor English. I hope you understand what I say. :smile: Edited August 24, 2016 by wyz123 Link to comment Share on other sites More sharing options...
Dielos Posted August 24, 2016 Share Posted August 24, 2016 Could it be that you have an unending loop here? Sorry if I go in the wrong direction, as I have little experience with states, but you call the Grab function which immediately changes to state "Busy", and the first thing the "Busy" state does is recall the function. As said, no idea how states work, so I might be misleading... Link to comment Share on other sites More sharing options...
wyz123 Posted August 24, 2016 Author Share Posted August 24, 2016 Could it be that you have an unending loop here? Sorry if I go in the wrong direction, as I have little experience with states, but you call the Grab function which immediately changes to state "Busy", and the first thing the "Busy" state does is recall the function. As said, no idea how states work, so I might be misleading...Thanks for replying. GotoState("Busy") is more like setting object's current state to "Busy". Next time the function is called the script will check its state and go to corresponding state. I use state to prevent player from spamming . I am pretty sure it is akTargetRef.Activate(PlayerRef,True) that causes the problem cause no freeze after I remove that statement. But player won't pick up the food if it is removed, making this mod useless. Link to comment Share on other sites More sharing options...
Dielos Posted August 24, 2016 Share Posted August 24, 2016 Ok. Thanks for clarifying that to me! Seriously no idea why this might happen. I'd expect a script error if there was anything strange, not a freeze... I guess nothing appears in the log after the freeze, right? Just to check, you wait 2.5 seconds in that function. Does the freeze happen when picking up items fast as well? I guess not or you should see those traces in the log after the freeze... Link to comment Share on other sites More sharing options...
TummaSuklaa Posted August 24, 2016 Share Posted August 24, 2016 As said, no idea how states work, so I might be misleading...STATES prevents the very thing the OP seems to be experiencing. Link to comment Share on other sites More sharing options...
wyz123 Posted August 25, 2016 Author Share Posted August 25, 2016 (edited) I guess nothing appears in the log after the freeze, right?Here are my log traces. With and without Utility.wait(2.5).I removed Game.GetPlayer().EquipItem(Item,False,True) to test Active() only.http://pastebin.com/JDAcwht0http://pastebin.com/bgujnxa8Yes. Nothing appears after the freeze.Does the freeze happen when picking up items fast as well?Yes. Edited August 25, 2016 by wyz123 Link to comment Share on other sites More sharing options...
Reneer Posted August 25, 2016 Share Posted August 25, 2016 (edited) My only guess is you blocking the default activation during your Activate() call is having something to do with it. Have you tried calling Activate() with that bit set to false? I wrote a mod very similar to yours (never released it) and I never had this sort of problem. Edited August 25, 2016 by Reneer Link to comment Share on other sites More sharing options...
wyz123 Posted August 25, 2016 Author Share Posted August 25, 2016 (edited) Ah! I don't even notice that! I tried what you said. Setting to false did improves the stability of the mod a lot. Unfortunately it doesn't prevent the game from freezing (after 21 calls, far better than before). So weird. Maybe it has something to do with the engine or with my PC. Thank you anyway. I'll try to rewrite this script with other functions. Edited August 25, 2016 by wyz123 Link to comment Share on other sites More sharing options...
Recommended Posts