TangerineDog Posted September 28, 2017 Share Posted September 28, 2017 I'm running this script as a magic effect. ScriptName HungerCounterScript extends activemagiceffectFloat Property pHoursToWait AutoInt Property HungerCount AutoEvent OnUpdateGameTime(); debug.trace(self + "OnUpdateGameTime")HungerCount += 1Debug.Notification("Hunger increased")RegisterForSingleUpdateGameTime(pHourstoWait)EndEventEvent OnEffectStart(Actor akTarget, Actor akCaster); start timerRegisterForSingleUpdateGameTime(pHourstoWait)Debug.Notification("Hunger starting")EndEvent Now I want to add checks to it that make things happen when HungerCount reaches certain values. How can I make the script check the current value of HungerCount? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 28, 2017 Share Posted September 28, 2017 If it is to be done within the same script. The following examples would be used inside a custom function or event. If HungerCount == 10 ;example of an exact match ;do whatever EndIf If HungerCount >= 10 ;example of exact match or greater ;do whatever EndIf If HungerCount <= 10 ; example of exact match or lower ;do whatever EndIf If HungerCount > 10 ;example of greater only ;do whatever EndIf If HungerCount < 10 ; example of lower only ;do whatever EndIf Link to comment Share on other sites More sharing options...
TangerineDog Posted September 28, 2017 Author Share Posted September 28, 2017 Thanks, that's what I got, too. ScriptName HungerCounterScript extends activemagiceffectFloat Property pHoursToWait AutoInt Property HungerCount AutoInt Property HungerCount1 AutoEvent OnUpdateGameTime(); debug.trace(self + "OnUpdateGameTime")HungerCount += 1Debug.Notification("Hunger increased")RegisterForSingleUpdateGameTime(pHourstoWait)if (HungerCount == HungerCount1)Debug.Notification("Hunger at One")endifEndEventEvent OnEffectStart(Actor akTarget, Actor akCaster); start timerRegisterForSingleUpdateGameTime(pHourstoWait)Debug.Notification("Hunger starting")EndEvent With that script, I can set both time and required HungerCount value in the CK. Now I'll try and see if another script can read and change the HungerCount value... Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 28, 2017 Share Posted September 28, 2017 Another script cannot see local variables from any other script. If you want the HungerCount to be seen by scripts on other records, you'll need to convert it or pass it into a GlobalVariable. A global is a type of form in the Creation Kit that uses the GlobalVariable property type and is modified with functions from the GlobalVariable script. Example: Script A Int HungerCount = 0 GlobalVariable Property HungerCountGV Auto ;some function or event ;modify HungerCount as needed HungerCountGV.SetValue(HungerCount as Float) ;end function or eventScript B GlobalVariable Property HungerCountGV Auto ;some function or event If HungerCountGV.GetValue() == SomeFloatValue ;do stuff EndIf ;end function or event There is another method of sharing values from one script to another but I don't recommend it if you are just starting out with Papyrus. Link to comment Share on other sites More sharing options...
TangerineDog Posted September 28, 2017 Author Share Posted September 28, 2017 (edited) So Script A would set HungerCountGV to the current value of HungerCount, but when I change the value of HungerCountGV in another script, won't Script A always just override those changes as soon as it runs again? Can't I just make HungerCount a global variable in my first script without basically using another variable to set its value? Edit: Turns out I can. ScriptName HungerCounterScript extends activemagiceffectFloat Property pHoursToWait AutoGlobalVariable Property HungerCount AutoInt Property HungerCount1 AutoEvent OnUpdateGameTime(); debug.trace(self + "OnUpdateGameTime")HungerCount.GetValue()HungerCount.Mod(1.0)Debug.Notification("Hunger increased")RegisterForSingleUpdateGameTime(pHourstoWait)EndEventEvent OnEffectStart(Actor akTarget, Actor akCaster); start timerRegisterForSingleUpdateGameTime(pHourstoWait)Debug.Notification("Hunger starting")EndEvent The next problem is to not only have another script read and mod it, but also tohave that script modify the global value by the amount I give the corresponding magical effect. Like healig potions use the same effect and you set the exact amount of health they give by adding the same effect to them and entering different magnitudes of that effect for each potion. Which might well be impossible. In that case, it would be 20 scripts reading the global value and modding it by 20 different values. And every food item would need one of those effects depending on how saturating it should be... aaw man, I hope there's an easy way to do this... Edited September 28, 2017 by TangerineDog Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 28, 2017 Share Posted September 28, 2017 Yes, as you found out, you could just turn 'HungerCount' into a global variable. The example I gave was for passing the existing value into a separate global. How you do it really depends upon the current circumstance and what you are trying to accomplish. Those are things that I do not know. Assume 20 food itemsAssume compatibility with other mods is not a concernEdit the 20 food items and add a new effect of the script typeEach effect gets the same script only difference being the value to assign to the Int or Float property holding the amount you want to modify the global variable by. In other words, you do not have to create a new script for every object if only property set values would be different. Link to comment Share on other sites More sharing options...
GSGlobe Posted September 28, 2017 Share Posted September 28, 2017 Im not sure IF Im allowed to jump in here but youre very kind explaing so detailed IsharaMeradin, Love these forum. Filled with knowledge, easier to learn here than the wiki. Thanks! Link to comment Share on other sites More sharing options...
TangerineDog Posted September 28, 2017 Author Share Posted September 28, 2017 (edited) Im not sure IF Im allowed to jump in here but youre very kind explaing so detailed IsharaMeradin, Love these forum. Filled with knowledge, easier to learn here than the wiki. Thanks!I absolutely second that - I miss a like-button or something, like other forums use. Yes, as you found out, you could just turn 'HungerCount' into a global variable. The example I gave was for passing the existing value into a separate global. How you do it really depends upon the current circumstance and what you are trying to accomplish. Those are things that I do not know. Assume 20 food itemsAssume compatibility with other mods is not a concernEdit the 20 food items and add a new effect of the script typeEach effect gets the same script only difference being the value to assign to the Int or Float property holding the amount you want to modify the global variable by. In other words, you do not have to create a new script for every object if only property set values would be different. I'll get on that asap - I should have had the idea to set the reduction amount in the properties myself, considering that I'd done the same thing an hour before with another script...Thank you! You don't hapen to know how a script might be able to check the given magnitude of a spell?Edit: there is a way. It needs SKSE though. I'd rather script the mod for Oldrim and port to SE without having to hope that the SKSE Alpha will do what I want it to... Edited September 28, 2017 by TangerineDog Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 28, 2017 Share Posted September 28, 2017 You don't hapen to know how a script might be able to check the given magnitude of a spell?Edit: there is a way. It needs SKSE though. I'd rather script the mod for Oldrim and port to SE without having to hope that the SKSE Alpha will do what I want it to... Outside of SKSE, no idea. Link to comment Share on other sites More sharing options...
TangerineDog Posted September 29, 2017 Author Share Posted September 29, 2017 You don't hapen to know how a script might be able to check the given magnitude of a spell?Edit: there is a way. It needs SKSE though. I'd rather script the mod for Oldrim and port to SE without having to hope that the SKSE Alpha will do what I want it to... Outside of SKSE, no idea. I'll play it safe and do the 20 effects then.Thank you! Also, can you spot the error in this script? I'm trying to find out what's wrong with my if-else-statements, but from what I gather from the wiki, they're not wrong... :( ScriptName HungerChangeScript extends activemagiceffect GlobalVariable Property HungerCount AutoGlobalVariable Property HungerCount1 AutoGlobalVariable Property HungerCount2 AutoGlobalVariable Property HungerCount3 AutoSpell Property SpellHunger01 AutoSpell Property SpellHunger02 AutoSpell Property SpellHunger03 Autoint Property HungerCountMod Auto Event OnEffectStart(Actor akTarget, Actor akCaster) If akTarget == Game.GetPlayer()HungerCount.Mod(HungerCountMod)if HungerCount.GetValue() < HungerCount1.GetValue()If (Game.GetPlayer().HasMagicEffect(SpellHunger03))Game.GetPlayer().RemoveSpell(SpellHunger03)endifIf (Game.GetPlayer().HasMagicEffect(SpellHunger02))Game.GetPlayer().RemoveSpell(SpellHunger02)endifIf (Game.GetPlayer().HasMagicEffect(SpellHunger01))Game.GetPlayer().RemoveSpell(SpellHunger01)Debug.Notification("No more Hunger")endifelseif HungerCount.GetValue() < HungerCount2.GetValue()if HungerCount.GetValue() >= HungerCount1.GetValue()If (Game.GetPlayer().HasMagicEffect(SpellHunger03))Game.GetPlayer().RemoveSpell(SpellHunger03)endifIf (Game.GetPlayer().HasMagicEffect(SpellHunger02))Game.GetPlayer().RemoveSpell(SpellHunger02)endifIf (Game.GetPlayer().HasMagicEffect(SpellHunger01))Debug.Notification("Placeholder")ElseGame.GetPlayer().AddSpell(SpellHunger01)endifendifendifendif EndEvent Link to comment Share on other sites More sharing options...
Recommended Posts