Arael54 Posted July 22, 2022 Share Posted July 22, 2022 Hello everyone, I'm not really good at scripting, as a mainly adapt existing ones to my needs, or I create new ones with a lot of trials and errors.I'm trying to store the weapon weight of my right weapon as a global every time I equip or unequip a weapon. The global is created. But when I run the game with the script I created, the global variable always return 0. Could someone tell me what's wrong with my script ? (and it's probably obvious, but as I said, I'm really not that good). Scriptname Right_Weapon_Mass_Update extends ReferenceAlias Actor Property PlayerRef Auto GlobalVariable Property _RightWeaponMass Auto Float RightWeaponMass = 0.00 Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) if akBaseObject as Weapon Utility.Wait(0.5) Debug.Notification("This actor just unequipped a weapon!") Weapon MyRightWeapon = PlayerRef.GetEquippedWeapon() as Weapon Float WeaponWeight = MyRightWeapon.GetWeight() as Float RightWeaponMass = WeaponWeight Else RightWeaponMass = 0 _RightWeaponMass.SetValue((RightWeaponMass) * 1) EndIf EndEvent Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) if akBaseObject as Weapon Utility.Wait(0.5) Debug.Notification("This actor just equipped a weapon!") Weapon MyRightWeapon = PlayerRef.GetEquippedWeapon() As Weapon Float WeaponWeight = MyRightWeapon.GetWeight() as Float RightWeaponMass = WeaponWeight Else RightWeaponMass = 0 _RightWeaponMass.SetValue((RightWeaponMass) * 1) EndIf EndEvent The debug messages work when I equip or unequip a weapon, but the global variable stay at 0.Could someone help me understand what's wrong ? Thank you. Link to comment Share on other sites More sharing options...
dylbill Posted July 22, 2022 Share Posted July 22, 2022 The script looks fine. Did you fill properties when attaching the script in the creation kit? You can also put some debug notifications to tell you the weight. Debug.Notification("RightWeaponMass = " + RightWeaponMass + " Global Value = " + _RightWeaponMass.GetValue()) Link to comment Share on other sites More sharing options...
Arael54 Posted July 22, 2022 Author Share Posted July 22, 2022 The script looks fine. Did you fill properties when attaching the script in the creation kit? You can also put some debug notifications to tell you the weight. Debug.Notification("RightWeaponMass = " + RightWeaponMass + " Global Value = " + _RightWeaponMass.GetValue())Thank you for your answer. Properties seem to be filled correctly. Link to comment Share on other sites More sharing options...
dylbill Posted July 22, 2022 Share Posted July 22, 2022 Hey I just took another look, the indents were confusing me. The script as you have it, indented correctly should look like this: Actor Property PlayerRef Auto GlobalVariable Property _RightWeaponMass Auto Float RightWeaponMass = 0.00 Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) if akBaseObject as Weapon Utility.Wait(0.5) Debug.Notification("This actor just unequipped a weapon!") Weapon MyRightWeapon = PlayerRef.GetEquippedWeapon() as Weapon Float WeaponWeight = MyRightWeapon.GetWeight() as Float RightWeaponMass = WeaponWeight Else RightWeaponMass = 0 _RightWeaponMass.SetValue((RightWeaponMass) * 1) EndIf EndEvent Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) if akBaseObject as Weapon Utility.Wait(0.5) Debug.Notification("This actor just equipped a weapon!") Weapon MyRightWeapon = PlayerRef.GetEquippedWeapon() As Weapon Float WeaponWeight = MyRightWeapon.GetWeight() as Float RightWeaponMass = WeaponWeight Else RightWeaponMass = 0 _RightWeaponMass.SetValue((RightWeaponMass) * 1) EndIf EndEventAnd you can see, you're only setting the global variable value if the equipped item is not a weapon. Change to something like this: Actor Property PlayerRef Auto GlobalVariable Property _RightWeaponMass Auto Float RightWeaponMass = 0.00 Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) if akBaseObject as Weapon Utility.waitMenuMode(0.5) ;use waitMenuMode instead. Wait will pause this script until a menu is closed. Debug.Notification("This actor just unequipped a weapon!") Weapon MyRightWeapon = PlayerRef.GetEquippedWeapon() as Weapon Float WeaponWeight = MyRightWeapon.GetWeight() as Float RightWeaponMass = WeaponWeight _RightWeaponMass.SetValue(RightWeaponMass) Debug.Notification("_RightWeaponMass = " + _RightWeaponMass.GetValue()) EndIf EndEvent Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) if akBaseObject as Weapon Utility.waitMenuMode(0.5) ;use waitMenuMode instead. Wait will pause this script until a menu is closed. Debug.Notification("This actor just unequipped a weapon!") Weapon MyRightWeapon = PlayerRef.GetEquippedWeapon() as Weapon Float WeaponWeight = MyRightWeapon.GetWeight() as Float RightWeaponMass = WeaponWeight _RightWeaponMass.SetValue(RightWeaponMass) Debug.Notification("_RightWeaponMass = " + _RightWeaponMass.GetValue()) EndIf EndEvent Also, is there a reason you're storing the weapon weight to the local float variable RightWeaponMass and to the global variable? Link to comment Share on other sites More sharing options...
TyburnKetch Posted July 22, 2022 Share Posted July 22, 2022 (edited) Im no expert either but have you tried storing the weight as an int? Dont know why that might help. Also, what is RightWeaponMass? Have you tried just using WeaponWeight instead? My guess is the script is using the else - RightWeaponMass = 0, which is why the GV is always 0. But dont know why. Apologies if none of this is useful. Edit* Posted too slow. Also, not as helpful. Lol. Edited July 22, 2022 by TyburnKetch Link to comment Share on other sites More sharing options...
Arael54 Posted July 22, 2022 Author Share Posted July 22, 2022 Hey I just took another look, the indents were confusing me. The script as you have it, indented correctly should look like this: Actor Property PlayerRef Auto GlobalVariable Property _RightWeaponMass Auto Float RightWeaponMass = 0.00 Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) if akBaseObject as Weapon Utility.Wait(0.5) Debug.Notification("This actor just unequipped a weapon!") Weapon MyRightWeapon = PlayerRef.GetEquippedWeapon() as Weapon Float WeaponWeight = MyRightWeapon.GetWeight() as Float RightWeaponMass = WeaponWeight Else RightWeaponMass = 0 _RightWeaponMass.SetValue((RightWeaponMass) * 1) EndIf EndEvent Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) if akBaseObject as Weapon Utility.Wait(0.5) Debug.Notification("This actor just equipped a weapon!") Weapon MyRightWeapon = PlayerRef.GetEquippedWeapon() As Weapon Float WeaponWeight = MyRightWeapon.GetWeight() as Float RightWeaponMass = WeaponWeight Else RightWeaponMass = 0 _RightWeaponMass.SetValue((RightWeaponMass) * 1) EndIf EndEventAnd you can see, you're only setting the global variable value if the equipped item is not a weapon. Change to something like this: Actor Property PlayerRef Auto GlobalVariable Property _RightWeaponMass Auto Float RightWeaponMass = 0.00 Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) if akBaseObject as Weapon Utility.waitMenuMode(0.5) ;use waitMenuMode instead. Wait will pause this script until a menu is closed. Debug.Notification("This actor just unequipped a weapon!") Weapon MyRightWeapon = PlayerRef.GetEquippedWeapon() as Weapon Float WeaponWeight = MyRightWeapon.GetWeight() as Float RightWeaponMass = WeaponWeight _RightWeaponMass.SetValue(RightWeaponMass) Debug.Notification("_RightWeaponMass = " + _RightWeaponMass.GetValue()) EndIf EndEvent Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) if akBaseObject as Weapon Utility.waitMenuMode(0.5) ;use waitMenuMode instead. Wait will pause this script until a menu is closed. Debug.Notification("This actor just unequipped a weapon!") Weapon MyRightWeapon = PlayerRef.GetEquippedWeapon() as Weapon Float WeaponWeight = MyRightWeapon.GetWeight() as Float RightWeaponMass = WeaponWeight _RightWeaponMass.SetValue(RightWeaponMass) Debug.Notification("_RightWeaponMass = " + _RightWeaponMass.GetValue()) EndIf EndEvent Also, is there a reason you're storing the weapon weight to the local float variable RightWeaponMass and to the global variable? Thanks a lot, now it's working ! The only reason I'm storing both is because I took inspiration from another script that store the weight of armors, so the script was divided between boots, cuirass, helm and arms and they were stored separately. I kept the same structure to see if I could make it work first before trying to delete useless steps. Im no expert either but have you tried storing the weight as an int? Dont know why that might help. Also, what is RightWeaponMass? Have you tried just using WeaponWeight instead? My guess is the script is using the else - RightWeaponMass = 0, which is why the GV is always 0. But dont know why. Apologies if none of this is useful. Edit* Posted too slow. Also, not as helpful. Lol."RightWeaponMass" is defined in the script, but as I said it's indeed an useless step in this case. Dylbill made it work, but your intervention was useful, I think you were on the right track, thanks to you too ! Link to comment Share on other sites More sharing options...
dylbill Posted July 22, 2022 Share Posted July 22, 2022 Gotcha, glad i'ts working! Link to comment Share on other sites More sharing options...
Recommended Posts