Jump to content

[LE] Get int property value?


TangerineDog

Recommended Posts

I'm running this script as a magic effect.

 

ScriptName HungerCounterScript extends activemagiceffect

Float Property pHoursToWait Auto
Int Property HungerCount Auto

Event OnUpdateGameTime()

; debug.trace(self + "OnUpdateGameTime")
HungerCount += 1
Debug.Notification("Hunger increased")
RegisterForSingleUpdateGameTime(pHourstoWait)


EndEvent

Event OnEffectStart(Actor akTarget, Actor akCaster)

; start timer
RegisterForSingleUpdateGameTime(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

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

Thanks, that's what I got, too.

 

ScriptName HungerCounterScript extends activemagiceffect

Float Property pHoursToWait Auto
Int Property HungerCount Auto
Int Property HungerCount1 Auto

Event OnUpdateGameTime()

; debug.trace(self + "OnUpdateGameTime")
HungerCount += 1
Debug.Notification("Hunger increased")
RegisterForSingleUpdateGameTime(pHourstoWait)
if (HungerCount == HungerCount1)
Debug.Notification("Hunger at One")
endif

EndEvent

Event OnEffectStart(Actor akTarget, Actor akCaster)

; start timer
RegisterForSingleUpdateGameTime(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

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 event

Script 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

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 activemagiceffect

Float Property pHoursToWait Auto
GlobalVariable Property HungerCount Auto
Int Property HungerCount1 Auto

Event OnUpdateGameTime()

; debug.trace(self + "OnUpdateGameTime")
HungerCount.GetValue()
HungerCount.Mod(1.0)
Debug.Notification("Hunger increased")
RegisterForSingleUpdateGameTime(pHourstoWait)


EndEvent

Event OnEffectStart(Actor akTarget, Actor akCaster)

; start timer
RegisterForSingleUpdateGameTime(pHourstoWait)
Debug.Notification("Hunger starting")

EndEvent

 

 

The next problem is to not only have another script read and mod it, but also to

have 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 by TangerineDog
Link to comment
Share on other sites

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 items

Assume compatibility with other mods is not a concern

Edit the 20 food items and add a new effect of the script type

Each 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

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 items

Assume compatibility with other mods is not a concern

Edit the 20 food items and add a new effect of the script type

Each 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 by TangerineDog
Link to comment
Share on other sites

 

 

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

 

 

 

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 Auto

GlobalVariable Property HungerCount1 Auto

GlobalVariable Property HungerCount2 Auto

GlobalVariable Property HungerCount3 Auto

Spell Property SpellHunger01 Auto

Spell Property SpellHunger02 Auto

Spell Property SpellHunger03 Auto

int 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)

endif

If (Game.GetPlayer().HasMagicEffect(SpellHunger02))

Game.GetPlayer().RemoveSpell(SpellHunger02)

endif

If (Game.GetPlayer().HasMagicEffect(SpellHunger01))

Game.GetPlayer().RemoveSpell(SpellHunger01)

Debug.Notification("No more Hunger")

endif

elseif HungerCount.GetValue() < HungerCount2.GetValue()

if HungerCount.GetValue() >= HungerCount1.GetValue()

If (Game.GetPlayer().HasMagicEffect(SpellHunger03))

Game.GetPlayer().RemoveSpell(SpellHunger03)

endif

If (Game.GetPlayer().HasMagicEffect(SpellHunger02))

Game.GetPlayer().RemoveSpell(SpellHunger02)

endif

If (Game.GetPlayer().HasMagicEffect(SpellHunger01))

Debug.Notification("Placeholder")

Else

Game.GetPlayer().AddSpell(SpellHunger01)

endif

endif

endif

endif

 

EndEvent

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...