BKnight49 Posted October 28, 2017 Share Posted October 28, 2017 (edited) So, I'm trying to make a VERY simple script which toggles lights by getting the ObjectReference from an array and then enabling/disabling said light before waiting for 1 second and then repeating until all items in the array have been processed. I've added 7 objects to the array(s) via the Properties window inside of the CK > Select reference in render window. However, trying to pass my array to the function throws the error "Argument 'lightReference' / 'lightReferenceOFF' is not specified and has no default value". Also, yes I'm aware that there are easier ways to do this but I'd like to experiment with the code and implement it in my way since I'd like the lights to have a delay before turning on/off and also for me to not have to blatantly copy some code since that wont help me get better. You could probably say I'm a near-beginner since I'm used to other coding languages and understand the basics too. Anyway here's my code: Scriptname activateLightsScript extends ObjectReference ObjectReference[] Property lightReference Auto Const ObjectReference[] Property lightReferenceOFF Auto Const int currentState Event OnActivate(ObjectReference akActionRef) if currentState == 0 EnableAll() else DisableAll() endIf EndEvent Function EnableAll(ObjectReference[] lightReference) // Offending lines int currentElement = 0 while (currentElement < lightReference.Length) lightReference[currentElement].Enable() currentElement += 1 Utility.Wait(1) endWhile EndFunction Function DisableAll(ObjectReference[] lightReferenceOFF) // Offending lines int currentElement = 0 while (currentElement < lightReferenceOFF.Length) lightReferenceOFF[currentElement].Disable() currentElement += 1 Utility.Wait(1) endWhile EndFunction Any help would be greatly appreciated! Thanks :smile: EDIT: I noticed that both functions were enabling lights. That was just a minor typo. Edited October 28, 2017 by BKnight49 Link to comment Share on other sites More sharing options...
BKnight49 Posted October 28, 2017 Author Share Posted October 28, 2017 Bump (Does this even work on here? haha). Still having this issue guys. Link to comment Share on other sites More sharing options...
ThoraldGM Posted October 28, 2017 Share Posted October 28, 2017 The syntax is right from the page on arrays. Two guesses: 1. Your function arguments have the same name as your CK auto defined arrays, so compiler is getting confused (?) 2. Your code should work as-is if your functions had no arguments at all inside the (). Because CK filled properties are already visible to your functions without needing to be passed to them. Edit: Just noticed you also didn't pass the arrays to the functions via OnActivate: Enable(myArrayName)Disable(myArrayNameOff) You don't need to if you choose #2. Link to comment Share on other sites More sharing options...
JonathanOstrus Posted October 28, 2017 Share Posted October 28, 2017 (edited) The error message is pretty simple. You're calling the EnableAll() and DisableAll() with no parameters so you're not passing the references. In fact doing so in that way tells papyrus to either pass None or use any defaults declared in the function declaration (which you have none). The function declarations have a scope variable that it is expecting to be passed to it during the call but you're not passing it. So during the scope of the function the non passed variable is None. Also as noted by previous poster you should not have function variables that have the same name as any script scope or property names. You can either remove the variables from the function declarations and access the global properties or add the properties to the calling line so it passes it. (the latter is suggested) On another note, is there a reason you have 2 different arrays of refs? Are you not enabling or disabling the same set? Are all of these refs also in the same area? If they're all in an interior cell or the same local worldspace you could use an enable marker then you just turn that marker on or off and it does so to all of the linked enable refs. This would not allow your timed enable/disable and would cause all of them to pop on or off at once. Edited October 28, 2017 by BigAndFlabby Link to comment Share on other sites More sharing options...
ThoraldGM Posted October 28, 2017 Share Posted October 28, 2017 Ninja'd. BigAndFlabby is right. Link to comment Share on other sites More sharing options...
JonathanOstrus Posted October 28, 2017 Share Posted October 28, 2017 Ok, so now that I'm home and have more time to look at this and respond. There's another issue I see, which would make the whole thing not work as it is anyway. You check for currentState but never change it. So every run will always either enable or disable. I don't remember if uninitialized ints default to 0 or return as None. If they default 0 then every activation will always try to enable since you never changed state. Though personally I think using a bool would be better option since you're just using on/off states. I changed up your script with the assumption that all lights will either be toggled on or off and that when the script first initializes they will be off. This will need only one array of the refs and it will be a property which the activation event passes to the enable/disable functions when it calls them. This is intentional. The enable/disable functions are pretty generic and self contained so they can be reused in other scripts, or called from other scripts if so designed and desired. I left the 1s timer waits, though I'm not sure why you want that unless it's just for a cosmetic elegance or something. By design there is no error checking to validate that the array actually has content from CK. If it doesn't you'll get a papyrus error in the log and the script will abort. Scriptname activateLightsScript extends ObjectReference ObjectReference[] Property lightReferences Auto Const bool currentStateActive = false Event OnActivate(ObjectReference akActionRef) if !currentStateActive EnableAll(lightReferences) currentStateActive = true else DisableAll(lightReferences) currentStateActive = false endIf EndEvent Function EnableAll(ObjectReference[] ReferenceToggles) int currentElement = 0 while (currentElement < ReferenceToggles.Length) ReferenceToggles[currentElement].Enable() currentElement += 1 Utility.Wait(1) endWhile EndFunction Function DisableAll(ObjectReference[] ReferenceToggles) int currentElement = 0 while (currentElement < ReferenceToggles.Length) ReferenceToggles[currentElement].Disable() currentElement += 1 Utility.Wait(1) endWhile EndFunction Link to comment Share on other sites More sharing options...
BKnight49 Posted October 29, 2017 Author Share Posted October 29, 2017 I appreciate all the replies but Reddit sorted me out in about 5 minutes. As someone said, I did forget to pass the arguments when calling the functions but I actually didn't need them in the first place since making the array a Property is global from the start unlike other programming languages that I'm used to: Change Function EnableAll(ObjectReference[] lightReference) to just Function EnableAll() and the same with the other, Function DisableAll(). /u/The-RekoAlso, thanks for pointing out the fact that I hadn't changed the state. The way I work with scripts is to do it in chunks rather than all at once so I got to this problem and tested before actually finishing the rest of the script. I've now got it working completely fine and as intended though! Here's the full script for anyone who needs it in the future: Scriptname activateLightsScript extends ObjectReference ObjectReference[] Property lightReference Auto Const ObjectReference[] Property lightReferenceOFF Auto Const Sound Property soundReference Auto Const Sound Property soundReferenceOFF Auto Const ObjectReference Property activateMusic Auto Const int currentState Event OnActivate(ObjectReference akActionRef) activateMusic.Enable() if currentState == 0 EnableAll() else DisableAll() endIf EndEvent Function EnableAll() int currentElement = 0 while (currentElement < lightReference.Length) lightReference[currentElement].Enable() currentElement += 1 Utility.Wait(0.4) soundReference.Play(self) endWhile currentState = 1 EndFunction Function DisableAll() int currentElement = 0 while (currentElement < lightReference.Length) lightReference[currentElement].Disable() currentElement += 1 Utility.Wait(0.4) soundReferenceOFF.Play(self) endWhile currentState = 0 EndFunction Link to comment Share on other sites More sharing options...
ThoraldGM Posted October 29, 2017 Share Posted October 29, 2017 Glad you got it working. I'm a night shifter in the US, so not as fast as Reddit ;-) Link to comment Share on other sites More sharing options...
Recommended Posts