thesniperdevil Posted March 24, 2015 Share Posted March 24, 2015 Hi guys I apologise if this has been covered elsewhere, but I cannot seem to find it :sad: I was wondering if within Papyrus, it is possible to use the number that dictates a while loop to reference variables and properties? See below for an example - I am sure the syntax are all wrong. int property Test0 = 10int property Test1 =4 0int property Test2 = 15 int property true0 autoint property true1 autoint property true2 auto Function myFunction()int iwhile i<3property true = propertyTesti++endwhile If what I am trying to achieve is possible, can anyone provide me a simple example (with correct syntax)? cheers! Link to comment Share on other sites More sharing options...
cdcooley Posted March 24, 2015 Share Posted March 24, 2015 You are trying to use arrays, you just need to declare them that way. And your example makes little sense, so here's a slightly different one. Actor Property PlayerRef Auto bool[] Property isNearby Auto ObjectReference[] Property nearbyTarget Auto Function CheckDistances(int range = 500) int i = nearbyTarget.length while i > 0 i -= 1 isNearby[i] = PlayerRef.GetDistance(nearbyTarget[i]) < range endwhile EndFunction ; This is optional and only needed if you don't fill the properties in the CK. Event OnInit() PlayerRef = Game.GetPlayer() isNearby = new bool[5] nearbyTarget = new ObjectReference[5] nearbyTarget = Game.GetForm(0x013698) as ObjectReference ; Whiterun carriage driver nearbyTarget = Game.GetForm(0x03F220) as ObjectReference ; Markarth carriage driver nearbyTarget = Game.GetForm(0x09B7B1) as ObjectReference ; Solitude carriage driver nearbyTarget = Game.GetForm(0x09B7B4) as ObjectReference ; Riften carriage driver nearbyTarget = Game.GetForm(0x09B7C8) as ObjectReference ; Windhelm carriage driver EndEvent It would be better to fill the properties in the CK, but in either case you need to make sure both arrays have the same length. Link to comment Share on other sites More sharing options...
thesniperdevil Posted March 25, 2015 Author Share Posted March 25, 2015 Thanks for this.It has helped me out lots- I am actually confusing myself because I am using MCM for the first time. I want to store MCM globals into a global array that is referenced by multiple scripts - can this be done? in my minds eye the mcm script would use the following for an array of integers. (sorry my browser wont let me embed scripts) int[] property holdCounter = new int[9] ;how would I declare this globally, the length of array will always be 9 and will contain integers only. addHeaderOption("Hold Countdowns")AddSliderOptionST("FalkreathCounterState", "Falkreath COuntdown", holdCounter[0].GetValue())AddSliderOptionST("EastmarchCounterState", "EAstmarch Countdown", holdCOunter[1].GetValue());and so on with the slider states being referencing the array in the same way as above. Many Thanks. Does MCM support this? Link to comment Share on other sites More sharing options...
cdcooley Posted March 25, 2015 Share Posted March 25, 2015 Thanks for this.It has helped me out lots- I am actually confusing myself because I am using MCM for the first time. I want to store MCM globals into a global array that is referenced by multiple scripts - can this be done? in my minds eye the mcm script would use the following for an array of integers. (sorry my browser wont let me embed scripts) int[] property holdCounter = new int[9] ;how would I declare this globally, the length of array will always be 9 and will contain integers only. addHeaderOption("Hold Countdowns")AddSliderOptionST("FalkreathCounterState", "Falkreath COuntdown", holdCounter[0].GetValue())AddSliderOptionST("EastmarchCounterState", "EAstmarch Countdown", holdCOunter[1].GetValue());and so on with the slider states being referencing the array in the same way as above. Many Thanks. Does MCM support this?(You use the [ code ] tag (without those spaces to embed code if you aren't using the WYSIWYG editor.) MCM itself doesn't care how the variable values are stored, arrays are as good as anything else. It's quite possible (and efficient) to share an array, but it may not be the best option. Arrays aren't protected from multi-threading conflicts, so be careful that you don't have multiple scripts trying to change values at the same time. The second problem is that giving the different scripts access to the shared array has to be done in script because there's no way to connect them in the CK. With those warning noted, there are a few ways to get things working but here's the approach I would probably use. First, put a declaration like this in the MCM script and use the CK to fill that array with the correct number of values. (Filling it in the CK ensures that it will exist before any other script tries to access it.) int[] Property holdCounter Auto Minimally you just need this in the other scripts to access the counters. MyMCMQuestScript Property MyMCMQuest Auto Function DoSomething() if MyMCMQuest.holdCounter[1] == 0 Debug.Notification("holdCounter 1 is zero") endif EndFunction You have to change the quest script and quest names to match what you are really using and you'll need to fill that property in the CK, but after that you can access the array whenever you like. But that minimal version is very inefficient because it accesses the MCM quest every time you access the counter array, so you really want to do something like this to grab a local reference to the array once. int[] holdCounter MyMCMQuestScript Property MyMCMQuest Auto Event OnInit() holdCounter = MyMCMQuest.holdCounter EndEvent Function DoSomething() if holdCounter[1] == 0 Debug.Notification("holdCounter 1 is zero") endif EndFunction I use a variable for the holdCounter array here as a reminder to myself that it's a local reference to the shared data. There's no need for any other script to ever access the array through this script (since it's available through the MCM quest's property). Link to comment Share on other sites More sharing options...
Recommended Posts