LegendofThunder Posted December 17, 2013 Share Posted December 17, 2013 Hi guys, I'm currently making a function and one of the parameters is going to be a global variable. I have several created for example: pLOT01NirnrootpLOT01NightshadepLOT01WheatpLOT01FireSalts Yes they are all ingredients but what I'm trying to do is create a function that saves me a lot more lines. The part of the function that is bugging me is this:Function ingCount(Ingredient iCur, String iiCur, Int stage, Int max, show pLot) float CurrentCount = Game.GetPlayer().GetItemCount(iCur) pLot.Value = CurrentCountNow at the moment I've tried pretty much everything I can think of to get it to pass through correctly. I'm not trying to pass the globals value, but it's name. So I'm trying to pass "pLOT01Nirnroot" instead of "4" if I had 4 Nirnroot. I've tried passing it through as a string and that didn't work either. This function is to count a number of ingredients, and BTW I don't want to change the way I'm doing it. Anyone have any ideas?Would really appreciate some help with this one! Link to comment Share on other sites More sharing options...
Xander9009 Posted December 18, 2013 Share Posted December 18, 2013 I'm not sure I understand what's going on here. But I'll point out there's an SKSE function called GetName() which has worked for me before. I don't know if it will successfully get the name of a variable, though. Honestly, I doubt it, but it's worth a shot. Let me know if that fails. And if that's the case, then what's the entire function so I can see what everything is doing. Maybe I can help change it subtly so it stays as close to this as possible. Link to comment Share on other sites More sharing options...
LegendofThunder Posted December 18, 2013 Author Share Posted December 18, 2013 (edited) On 12/18/2013 at 12:42 AM, Xander9009 said: I'm not sure I understand what's going on here. But I'll point out there's an SKSE function called GetName() which has worked for me before. I don't know if it will successfully get the name of a variable, though. Honestly, I doubt it, but it's worth a shot. Let me know if that fails. And if that's the case, then what's the entire function so I can see what everything is doing. Maybe I can help change it subtly so it stays as close to this as possible. When I saved the call of this function after including GetName() the compiler said that GetName() isn't a function or doesn't exist? I am assuming I don't have SKSE loaded into the Creation Kit? This is what calls the function (when a player picks up an item):if pLOT01Quest.GetStageDone(10) == 1 if pLOT01Quest.GetStageDone(230) == 0 if akBaseItem == pDeathbell pLOT01QS.ingCount(pDeathbell, 230, 2, "pLOT01DeathbellCount") endif endif endifThis is the function:Function ingCount(Ingredient iCur, Int stage, Int max, GlobalVariable pLot) float CurrentCount = Game.GetPlayer().GetItemCount(iCur) pLot.Value = CurrentCount UpdateCurrentInstanceGlobal(pLot) if CurrentCount >= max pLOT01Quest.SetObjectiveCompleted(stage,1) pLOT01Quest.SetObjectiveDisplayed((stage + 5),true,true) elseif CurrentCount < max pLOT01Quest.SetObjectiveCompleted(stage,0) pLOT01Quest.SetObjectiveDisplayed((stage + 5),0) pLOT01Quest.SetObjectiveDisplayed(stage,true,true) endif endFunctionAs you can see, I need increase or decrease the global variable depending on the count, and this depends on the ingredient. So I'd prefer to have a single function with parameters, instead of loads of functions. Edited December 18, 2013 by LegendofThunder Link to comment Share on other sites More sharing options...
Xander9009 Posted December 18, 2013 Share Posted December 18, 2013 I've been wrong before, so this might not be 100% accurate, but I don't believe it's possible to do it the way you are. As far as I know, you can't pass a variable into another variable like that. It'll automatically pass the variable's value. But, there might be a workaround that will leave it nearly as short. Use an array, instead. Specifically, two arrays. They would be the same size, but one would be filled with ingredients, the other would be empty and would be use for numbers. Reveal hidden contents Function ingCount(Ingredient iCur, Int stage, Int max) int CurrentCount = Game.GetPlayer().GetItemCount(iCur) int i = IngredientArray.Find(iCur) IngredientQuantity[i] = CurrentCount if CurrentCount >= max pLOT01Quest.SetObjectiveCompleted(stage,1) pLOT01Quest.SetObjectiveDisplayed((stage + 5),true,true) elseif CurrentCount < max pLOT01Quest.SetObjectiveCompleted(stage,0) pLOT01Quest.SetObjectiveDisplayed((stage + 5),0) pLOT01Quest.SetObjectiveDisplayed(stage,true,true) endif endFunction Ingredient[] Property IngredientArray Auto Int[] Property IngredientQuantity Auto Event OnInit() IngredientArray = New Ingredient[150] ;This needs to match however many ingredients you're working with IngredientQuantity = New Int[150] ;Same as above EndEvent The downside to this is that it's no longer a global variable so whatever you had referencing it will no longer work. But you can switch whatever is referencing it to reference this variable directly. It'll still need both variables. Anyway, to do that, use this in any other script. For this, I'll assume the above is attached to a quest, but it'll work no matter what it's attached to. Reveal hidden contents ScriptName SomeOtherScript Extends Quest ScriptOne'sName Property QuestScriptOneIsAttachedTo Auto Ingredient Property SomeIngredient Auto Event OnInit() int i = (QuestScriptOneIsAttachedTo as ScriptOne'sName).IngredientArray.Find(SomeIngredient) float Var2 = (QuestScriptOneIsAttachedTo as ScriptOne'sName).IngredientQuantity[i] EndEvent At the end of the second script, the Var2 float will equal whatever you set the it to in the first script assuming you changed the names correctly and set the property. So, all you need to make it work in another script like the second one is the first property and the two lines in OnInit(). Link to comment Share on other sites More sharing options...
Recommended Posts