Jump to content

Check my script


ripple

Recommended Posts

I am trying to set up a RegisterForSingleUpdate chain in place of a RegisterForUpdate event. If someone can check my script to make sure I am doing it right, I'd appreciated it.

 

 

 

Scriptname MyScript extends ObjectReference Conditional


Scene Property MyScene  Auto 
ObjectReference Property MyNPCMarker  Auto
int Property MyNPCisTalking  Auto  Conditional 


Event OnLoad()
	RegisterForSingleUpdate(5)
EndEvent

Event OnUnload()
	UnregisterForUpdate()
endEvent

Event OnUpdate()
	Bool bKeepUpdating = True
	if MyNPCisTalking == 0
		if GetDistance(MyNPCMarker) <= 300
			if Game.GetPlayer().GetDistance(Self) <= 1000 
				MyScene.Start() 
				MyNPCisTalking = 1
			endif
		Endif
	endif
	If bKeepUpdating
		RegisterForSingleUpdate(1.0)
	endif
EndEvent

 

 

Edited by ripple
Link to comment
Share on other sites

Looks good to me.

Are you sure? :smile:

 

The thing is....I may have messed up on the original Town Crier script. I was testing something in game and found that the crier had stopped making announcements. I suspect that this may be because I used RegisterForSingleUpdate instead of RegisterForUpdate (since the latter has been known for causing so much grief to save games), so the script only fires once....I am not entirely sure, but I can't see any other reason why the crier would stop working in my own save games...so now I am thinking that I may need to set up a RegisterForSingleUpdate chain....

Edited by ripple
Link to comment
Share on other sites

I see it is an objectreference script. What is the script attached to? A trigger box?

 

One thing I see that will probably not work as you intended is the KeepUpdating boolean. It will be reset to true on each update. You should declare it as an internal variable just below your properties like this:

 

Bool KeepUpdating = true

 

Then, your OnUpdate event can read the stored value each time it is fired. However, right now, you don;t seem to shut that boolean off anywhere, so I;m not 100% sure what your intent it. I don't think you really need it.

 

If I had to guess, the issue is with your MyNPCIsTalking variable. First, I would also make this an internal unless you really need to access it externally as a property. Second, after the first time the script fires, it will be set to true, and I don;t see that you shut that off anywhere.

 

Love your mod, BTW.

 

Edit: Yeah, the more I look at this, the more I think you just need to add MyNPCisTalking = 0 to your OnLoad() event.

 

Another Edit: Also, within this conditional:

 

if Game.GetPlayer().GetDistance(Self) <= 1000
MyScene.Start()
MyNPCisTalking = 1
endif

 

You should add:

 

UnRegisterForUpdate()

 

At least, I think that is your intent. You only want to trigger him once per cell load, right?

Link to comment
Share on other sites

Yeah, the more I look at this, the more I think you just need to add MyNPCisTalking == 0 to your OnLoad() event.

 

Ding! Ding! That fixed it. Thanks LP!

 

Another Edit: Also, within this conditional:

if Game.GetPlayer().GetDistance(Self) <= 1000

MyScene.Start()

MyNPCisTalking = 1

endif

You should add:

UnRegisterForUpdate()

 

 

I am not sure, to be honest. The crier goes in and out of the tavern throughout the day, so while I intended the script to initiate on cell load, I also want to make sure that if the player does not transition cells during all that time (say, the player spends a lot of time hanging around the market or just walking around the city), the crier's announcement scene will still play when the conditions are met. But doesn't

Event OnUnload()
	UnregisterForUpdate()
endEvent

already work to unload the event once the player leave the cell? This is why I want KeepUpdate to reset to 'true' on each update so it will (I thought) loop the whole thing as long as all the conditions are met. The 'MyNPCisTalking' conditional is so the scene doesn't reset itself before it completes. Oh, the script is attached to the NPC.

Edited by ripple
Link to comment
Share on other sites

It is the MyNPCisTalking thing. You are checking for it to be value 0. You set it to value 1 when he first talks but it never gets reset to 0 for him to talk to him again.

 

According to the last couple posts you are now resetting it in the OnLoad event which will allow it to repeat on each visit to the area but not while the player is still in the same area.

 

Add this (or similar) in your Update event AFTER your scene event

If MyNPCisTalking == 1
  MyNPCisTalking = 0
EndIf

It will allow your scene to play out and the update to register again. Then on the next update it will reset the MyNPCisTalking variable to 0 so that on the third update the NPC could do their scene if conditions are right.

 

And you don't need the bool. It is always true. Just drop it and leave the single update register in place. In all instances of that block you want it to re-register anyway.

Link to comment
Share on other sites

Thanks Ishara. I just realized I didn't need to use the script to loop the scene because it's been flagged as 'repeat while true' with game hour conditions. But I'll add that bit just for good measures.

 

The script now re-initializes properly and the crier is now working again in the old save games where he was 'broken' after the script ran once. Here is the actual script if anyone wants to take a look.

 

 

 

Scriptname zINPCSCrierAnnounceScript extends ObjectReference Conditional

Scene Property AASCrierAnnounceScene01  Auto 
ObjectReference Property AASolitudeCrierMarker01  Auto
int Property AASCrierAnnounce  Auto  Conditional 


Event OnLoad()
	RegisterForSingleUpdate(5)
	AASCrierAnnounce = 0
EndEvent

Event OnUnload()
	UnregisterForUpdate()
endEvent

Event OnUpdate()
	if AASCrierAnnounce == 0
		if GetDistance(AASolitudeCrierMarker01) <= 300
			if Game.GetPlayer().GetDistance(Self) <= 1000 
				AASCrierAnnounceScene01.Start() 
				AASCrierAnnounce = 1
			endif
		Endif
	endif
	If AASCrierAnnounce == 1
		AASCrierAnnounce = 0
	EndIf
	RegisterForSingleUpdate(5.0)
EndEvent

 

 

Link to comment
Share on other sites

Ripple, AASCrierAnnounce is redundant. You set it to 1 then immediately in the next If statement you set it to 0, so effectively it is always 0...

 

So you could make the script a bit more compact:

 

 

 

Scriptname zINPCSCrierAnnounceScript extends ObjectReference

Scene Property AASCrierAnnounceScene01  Auto 
ObjectReference Property AASolitudeCrierMarker01  Auto


Event OnLoad()
	RegisterForSingleUpdate(5)
EndEvent

Event OnUnload()
	UnregisterForUpdate()
endEvent

Event OnUpdate()
	if GetDistance(AASolitudeCrierMarker01) <= 300 && Game.GetPlayer().GetDistance(Self) <= 1000 
		AASCrierAnnounceScene01.Start() 
	endif
	RegisterForSingleUpdate(5.0)
EndEvent

 

Edited by steve40
Link to comment
Share on other sites

  • Recently Browsing   0 members

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