cerealbowlparty Posted July 17, 2016 Share Posted July 17, 2016 I am trying to write a script that references three different chests. I'd like to count the number of times each was opened. Would it work if I applied the script to each one and then counted event OnOpen(ObjectReference akActionReference)? Link to comment Share on other sites More sharing options...
NexusComa Posted July 18, 2016 Share Posted July 18, 2016 Yes it would ... you will need to set up a variable to be your counter and if you are going to use a count from one chest to figure a option on a different chest you will need to use a global variable. Just to get you started ... (script added to the chest) Scriptname Bla_Bla_Bla extends ObjectReferenceInt OpenCount = 0 Event OnOpen(ObjectReference akActionReference) OpenCount += 1 If(OpenCount==(1)) ; bla bla bla ElseIf(OpenCount==(2)) ; bla bla bla EndIf EndEvent Link to comment Share on other sites More sharing options...
lofgren Posted July 18, 2016 Share Posted July 18, 2016 I thought OnOpen was for doors, not chests. Link to comment Share on other sites More sharing options...
cerealbowlparty Posted July 18, 2016 Author Share Posted July 18, 2016 Yes it would ... you will need to set up a variable to be your counter and if you are going to use a count from one chest to figure a option on a different chest you will need to use a global variable. Just to get you started ... (script added to the chest) Scriptname Bla_Bla_Bla extends ObjectReferenceInt OpenCount = 0 Event OnOpen(ObjectReference akActionReference) OpenCount += 1 If(OpenCount==(1)) ; bla bla bla ElseIf(OpenCount==(2)) ; bla bla bla EndIf EndEvent So I did some research. Correct me if I'm wrong, but I think I should use properties in the script that refers to each one of the chests (each of the three chests is a separate class). Link to comment Share on other sites More sharing options...
NexusComa Posted July 18, 2016 Share Posted July 18, 2016 it depends on what you're doing ... if something is to happen to each chest yes looks like lofgren may be correct on the OnOpen command ...One place shows it for doors but i found a forum talking about it has to have a open close animation ... so i'm not sure you will need to test that.The bit of script i gave you was more to show how to add to a variable by 1. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted July 18, 2016 Share Posted July 18, 2016 For containers: A script on the container would need OnActivate rather than OnOpen. You can have a script completely local to the container that keeps track of how many times said container opens. However, you won't be able to use that information any where else. Depending upon how you want to use the information and where you want to use the information determines how you share that information from the local script to other scripts or other records. Example 1 -- Completely local, no sharing: ScriptName SomeScript Extends ObjectReference Int NumTimesOpened = 0 Event OnActivate(ObjectReference akActionRef) NumTimesOpened += 1 If NumTimesOpened > 0 && NumTimesOpened <= 5 ;do something ElseIf NumTimesOpened > 5 && NumTimesOpened <=10 ;do something else EndIf EndEvent Example 1 -- Sharing to another script: Script On Container ScriptName SomeScript Extends ObjectReference Int Property NumTimesOpened = 0 Auto Hidden Event OnActivate(ObjectReference akActionRef) NumTimesOpened += 1 EndEventScript somewhere else ScriptName SomeOtherScript Extends Quest ;or whatever other script you need to extend SomeScript Property ContScript Auto ;inside some function or event If ContScript.NumTimesOpened > 0 && ContScript.NumTimesOpened <= 5 ;do something ElseIf ContScript.NumTimesOpened > 5 && ContScript.NumTimesOpened <= 10 ;do something else EndIf When assigning the property for the other script, you'll need to select the form or record that the script is attached to. The CK will offer every record that contains the script, so make sure you select the correct one. Example 2 -- Sharing to other records AND other scripts: Create a Global record with a value of 0. You will need one per container in order to keep the count separate. Script on container(s) be sure to assign the correct global record to the global variable property ScriptName SomeScript Extends ObjectReference GlobalVariable Property ContOpenCount Auto Event OnActivate(ObjectReference akActionRef) Float Current = ContOpenCount.GetValue() Float NewValue = Current + 1 ContOpenCount.SetValue(NewValue) EndEventNow you can use that global record on other scripts or within conditions on spells/perks/etc Those are just simple examples, none of which were tested for actual compilation. There may also be more methods to communicate between scripts and other records than what I have listed here. There may also be shorter methods of the above, especially where the math is located as some of it could be combined. Link to comment Share on other sites More sharing options...
cerealbowlparty Posted July 18, 2016 Author Share Posted July 18, 2016 (edited) Thanks, this is all very helpful. If I was only interested in if at least one chest has been opened, can I use the same global variable for each? Edited July 18, 2016 by cerealbowlparty Link to comment Share on other sites More sharing options...
IsharaMeradin Posted July 19, 2016 Share Posted July 19, 2016 I suppose. It depends on what you want to do. In your initial post you stated that you wanted to be able to "count the number of times each was opened". That would require a separate variable for each container in order to keep the count separate. Link to comment Share on other sites More sharing options...
Recommended Posts