Lord Valarian Posted June 15, 2012 Share Posted June 15, 2012 I need go through the items whoever touches an item. I can't it to work. The container won't set right. Number of Items: unknown From the Beginning to the End short invPos short invCount ref pInvObj ref pCont ... set pCont to YourDesiredContainer set invPos to 0 set invCount to pCont.GetNumItems While invPos < invCount set pInvObj to (pCont.GetInventoryObject invPos) ;Do whatever you want to do set invPos to invPos + 1 Loop Taken from ES tutorials. I changed it to this: Begin OnActivate set pCont to player ;getcontainer for anything activating it set invPos to 0 set invCount to pCont.GetNumItems While invPos < invCount set pInvObj to (pCont.GetInventoryObject invPos) printc "object name: %z" pInvObj.getname ;<noname> and no value for get value something {code removed to find the bug} set invPos to invPos + 1 Loop End I can't set the container/actor so the loop will not work. I'm stuck. If try to print the player name before the loop starts as a test, <no string>. How do I get this loop to work? Link to comment Share on other sites More sharing options...
Lanceor Posted June 15, 2012 Share Posted June 15, 2012 I'm no expert with loops, strings or inventory objects - when I code it, it's a bit hit and miss and I simply try different things until it works. :P But to take a shot in the dark, what I would try is to store the strings in variables first. ... string_var ObjectName string_var WholeSentence ... Begin OnActivate set pCont to player ;getcontainer for anything activating it set invPos to 0 set invCount to pCont.GetNumItems While invPos < invCount set pInvObj to (pCont.GetInventoryObject invPos) let ObjectName := pInvObj.getname let WholeSentence := "object name: " + $ObjectName printc $WholeSentence ;<noname> and no value for get value something {code removed to find the bug} set invPos to invPos + 1 Loop End If it works, you might be able to cut out one of the string variables. Link to comment Share on other sites More sharing options...
Lord Valarian Posted June 16, 2012 Author Share Posted June 16, 2012 I found a better way from the OBSE docs after many hours of frustration. Using foreach did the trick. Thanks. Link to comment Share on other sites More sharing options...
QQuix Posted June 16, 2012 Share Posted June 16, 2012 For the record, I don't see anything wrong with your first script (it works fine for me). The problem with the second script, as Lanceor suggested, is that PrintC only accepts variables as arguments, and not something like pInvObj.getname (that line even crashed my CS) Anyway, ForEach is the way to go. Link to comment Share on other sites More sharing options...
Lord Valarian Posted June 16, 2012 Author Share Posted June 16, 2012 >For the record, I don't see anything wrong with your first script (it works fine for me). I can't get it to set the container. Will not work. Now, I need to read quest variables in other scripts(non-quest script). The editor won't allow it. See message about editor crashing on save when adding more dependent mods to my list Link to comment Share on other sites More sharing options...
QQuix Posted June 16, 2012 Share Posted June 16, 2012 To access quest variables, use <QuestEditorID>.<VarName> QuestEditorID is the one in the list on the left of the Quest Window Example: If you have a quest with the EditorID = MyQuest and the following script: Scn MyQuestScriptShort SomeVarNameRef AnotherVarName You access those vars by: MyQuest.SomeVarName and MyQuest.AnotherVarName. More info HERE Link to comment Share on other sites More sharing options...
Lord Valarian Posted June 17, 2012 Author Share Posted June 17, 2012 This needs a separate topic. This is now closed. (not watching) Link to comment Share on other sites More sharing options...
Recommended Posts