Jump to content

Game Freezes After Calling Activate() Several Times


wyz123

Recommended Posts

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 by wyz123
Link to comment
Share on other sites

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

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

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

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/JDAcwht0

http://pastebin.com/bgujnxa8

Yes. Nothing appears after the freeze.

Does the freeze happen when picking up items fast as well?

Yes.

Edited by wyz123
Link to comment
Share on other sites

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 by Reneer
Link to comment
Share on other sites

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 by wyz123
Link to comment
Share on other sites

  • Recently Browsing   0 members

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