TessSin Posted July 7, 2021 Share Posted July 7, 2021 I got a pretty simple script in which i want to iterate through my inventory and do something with enchanted weapons: Array_var invItems Array_var invTemp ref rItem int zzzTestVal1 float zzzTestVal2 Begin GameMode let invTemp := ar_Construct Array let invItems := Player.GetItems 33 ForEach invTemp<- invItems let rItem := invTemp["value"] if GetObjectCharge rItem != zzzTestVal1 Set zzzTestVal1 to GetObjectCharge rItem EndIf if rItem.GetCurrentCharge > 0 Set zzzTestVal2 to rItem.GetCurrentCharge EndIf Loop Message TestVal1 %.0f. TestVal2 %0.f", zzzTestVal1, zzzTestVal2, 2 let invTemp := ar_Null let invItems := ar_Null End It is currently supposed to just give debug message. If i comment the GetCurrentCharge commands out there is no problem. But if the GetCurrentCharge commands are in the script the script simply will crash at those. I think it is some kind of problem with the reference? At least that's what i assume happens, because the GetObjectCharge requires a objectID:ref, while the GetCurrentCharge requires the reference for the call. Is there any way how i can fix this? Do i have to use something like CreateTempRef or GetInvRefsForItem? If yes, how do i use them in this case? At the end i want to update the charge of enchanted weapons via ModCurrentCharge or SetCurrentCharge, but both of those have the same kind of problem with the reference i think. Thanks in advance! Link to comment Share on other sites More sharing options...
qwertyasdfgh Posted July 7, 2021 Share Posted July 7, 2021 (edited) I'm fairly sure GetItems returns base items, not inventory references. You need to use something like this: ForEach iter <- Player.GetItems 33 Let item := iter->value ForEach iter2 <- Player.GetInvRefsForItem item Let ir := iter2->value Let charge := ir.GetCurrentCharge loop loop Edited July 7, 2021 by qwertyasdfgh Link to comment Share on other sites More sharing options...
TessSin Posted July 8, 2021 Author Share Posted July 8, 2021 I'm fairly sure GetItems returns base items, not inventory references. You need to use something like this: ForEach iter <- Player.GetItems 33 Let item := iter->value ForEach iter2 <- Player.GetInvRefsForItem item Let ir := iter2->value Let charge := ir.GetCurrentCharge loop loop Yeah, i realized this yesterday. I tried two things afterwards: 1. The GetInvRefsForItem path. I got usable references for which i could change the charge with ModCurrentCharge. The problem with that is, that the change to the charge didnt reflect in the item in my inventory. I assume because of it creating temporary references it isn't actually working with the real existing item. 2. Hacky way, by saving references in variables. The references i got from the equipped item in the weapon slot. The reference was valid, as long as the weapon was equipped. But after unequipping the reference wasnt working anymore. With the first solution i probably could do something like "get temporary reference and change the charge. Afterwards remove the old item and add the temporary reference to the inventory." But i feel like that would lead to savegame bloat and is an extremely ugly way of doing it. Link to comment Share on other sites More sharing options...
qwertyasdfgh Posted July 8, 2021 Share Posted July 8, 2021 1. No, it is actually working with existing items. I've used ModCurrentCharge with inventory references before and it worked fine. Can you post your new script? 2. You really shouldn't store IRs in variables. They're generally only valid for a single frame, everything else is risky. Link to comment Share on other sites More sharing options...
SinseiTD Posted July 8, 2021 Share Posted July 8, 2021 Array_var invItems Array_var invTemp Array_var invRefs ref rItem ref refItem ref plsRef Short weaponAusgabe Short enchantedAusgabe int zzzTestVal1 float zzzTestVal2 float zzzTestVal3 Begin GameMode let invTemp := ar_Construct Array let invItems := Player.GetItems 33 Set weaponAusgabe to 0 Set enchantedAusgabe to 0 Set zzzTestVal1 to 0 Set zzzTestVal2 to 0 ForEach invTemp<- invItems let rItem := invTemp["value"] let refItem := *invTemp Set weaponAusgabe to weaponAusgabe + 1 let invRefs := player.GetInvRefsForItem rItem let plsRef := invRefs[0] if GetObjectCharge rItem != zzzTestVal1 Set zzzTestVal1 to GetObjectCharge rItem EndIf if plsRef.GetCurrentCharge > 0 Set zzzTestVal2 to plsRef.GetCurrentCharge plsRef.ModCurrentCharge 20 Set zzzTestVal3 to plsRef.GetCurrentCharge EndIf Loop Message "%.0f waffen! %0.f enchanted! TestVal1 %.0f. TestVal2 %0.f. TestVal3 %0.f", weaponAusgabe, enchantedAusgabe, zzzTestVal1, zzzTestVal2, zzzTestVal3, 2 let invTemp := ar_Null let invItems := ar_Null End That's what i used for 1. As i said, i could see the value changing for the plsRef-variable/reference, but it didnt reflect ingame (i tested with a weapon with 856/1600 charge, which stayed at 856). Link to comment Share on other sites More sharing options...
Recommended Posts