Levionte Posted April 4, 2017 Share Posted April 4, 2017 This is probably a dumb question as this is my first attempt at using form lists in a script. The loop counter and everything in the script works fine aside from finding the correct actor from the form list (it returns it as None). Am I just writing the line wrong? I copied the format from an example on the creation kit site, and it compiles fine. It just doesn't work. FormList Property TeddyBearActorList Auto Function BearRecruit() Int BearIndex = TeddyBearActorList.GetSize() While BearIndex >= 0 BearIndex -= 1 Actor akBear = TeddyBearActorList.GetAt(BearIndex) as Actor ;This is the line that won't work akBear.SetPlayerTeammate() Debug.Notification(akBear + " is your friend.") EndWhile TeddyBear_Dialogue.SetStage(10) EndFunction Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 5, 2017 Share Posted April 5, 2017 The syntax is fine. The problem is that the objects you filled the formlist with do not yield a valid result when cast as Actor. When you filled the formlist did you use actor records or the object reference records of pre-placed actors? If it was actor records then those would cast into ActorBase rather than Actor.If it was object reference records of pre-placed actors, then it should be able to cast into Actor without any issues. As far as Papyrus is concerned, Actor is an extension of an ObjectReference while ActorBase refers to the actual actor record as found in the Creation Kit. Link to comment Share on other sites More sharing options...
Levionte Posted April 5, 2017 Author Share Posted April 5, 2017 (edited) Ah, got it. Thanks. Edited April 5, 2017 by Levionte Link to comment Share on other sites More sharing options...
cdcooley Posted April 5, 2017 Share Posted April 5, 2017 That loop condition should be a strictly greater test. While BearIndex > 0 Link to comment Share on other sites More sharing options...
Levionte Posted April 5, 2017 Author Share Posted April 5, 2017 (edited) But isn't the first entry listed at 0? I want it to run on that one too. Edited April 5, 2017 by Levionte Link to comment Share on other sites More sharing options...
FrankFamily Posted April 5, 2017 Share Posted April 5, 2017 On each loop you are actually running the one below the one that passed the test given you do -=1 right after. Link to comment Share on other sites More sharing options...
PeterMartyr Posted April 5, 2017 Share Posted April 5, 2017 On each loop you are actually running the one below the one that passed the test given you do -=1 right after. Logic hurts my brain so I hope this appreciated Bool[] bWhatThe = new Bool [5] bWhatThe[0] = true bWhatThe[1] = true bWhatThe[2] = true bWhatThe[3] = true bWhatThe[4] = true Int nIndex = bWhatThe.length ; it's 5 see above debug.Notification("length is " + nIndex) While(nIndex) nIndex -=1 Debug.Notification("Is number " + nIndex + " " + bWhatThe[nIndex] + "?") EndWhile The 1st run of the Loop is 4, it works perfectly, cdcooley, sorry bloke your wrong as well. It needs to be: While BearIndex >= 0 or While BearIndex else it won't go Zero since it looping backwards Carry on Levionte, I agree with you. Link to comment Share on other sites More sharing options...
FrankFamily Posted April 5, 2017 Share Posted April 5, 2017 I dont really get what you are saying but cdcooley and I are right (though maybe badly explained on my end) You contradict yourself when you say it needs to be "equal or higher to 0" or "anything but 0" because they dont involve the same numbers. While index (i.e. different than 0) or while index "higher than" 0 work the same way in this case and its what you should use if going backwrds, "higher or equal" will attempt to access element -1 probably giving an error. Edited: Comparison operators put weird symbols on my phone Link to comment Share on other sites More sharing options...
Levionte Posted April 5, 2017 Author Share Posted April 5, 2017 I got it, thanks. I stand corrected. Link to comment Share on other sites More sharing options...
ReDragon2013 Posted April 5, 2017 Share Posted April 5, 2017 (edited) I would like to show you the difference between using of formlist or array in a script. formlist handling Scriptname TeddyBearQuestScript extends Quest ; https://forums.nexusmods.com/index.php?/topic/5511977-running-a-script-on-a-formlist-of-actors-question/ Quest PROPERTY TeddyBear_Dialogue auto ;* Is this quest the same as this script should be attached? FormList PROPERTY TeddyBearActorList auto ; -- FUNCTION -- FUNCTION BearRecruit() ;--------------------- int i = TeddyBearActorList.GetSize() ; i = BearIndex WHILE (i > 0) ; "WHILE (i)" is shorter than "WHILE (i > 0)", but has the same logic i = i - 1 ;;; form fm = TeddyBearActorList.GetAt(i) actor aRef = TeddyBearActorList.GetAt(i) as Actor IF ( aRef ) aRef.SetPlayerTeammate(TRUE) Debug.Notification(i+" got a new friend.. " +aRef) ENDIF ENDWHILE IF (self as Quest == TeddyBear_Dialogue) self.setStage(10) ;* answer: TRUE ELSE TeddyBear_Dialogue.setStage(10) ;* answer: False ENDIF ENDFUNCTION array handling Scriptname TeddyBearQuestScript extends Quest ; https://forums.nexusmods.com/index.php?/topic/5511977-running-a-script-on-a-formlist-of-actors-question/ Quest PROPERTY TeddyBear_Dialogue auto ;* Is this quest the same as this script should be attached? Actor[] PROPERTY TeddyBearActorList auto ; array instead of formlist ; -- FUNCTION -- FUNCTION BearRecruit() ;--------------------- int i = TeddyBearActorList.Length ; i = BearIndex WHILE (i > 0) ; "WHILE (i)" is shorter than "WHILE (i > 0)", but has the same logic i = i - 1 actor aRef = TeddyBearActorList[i] ; aRef = akBear IF ( aRef ) aRef.SetPlayerTeammate(TRUE) Debug.Notification(i+" got a new friend.. " +aRef) ENDIF ENDWHILE IF (self as Quest == TeddyBear_Dialogue) self.setStage(10) ;* answer: TRUE ELSE TeddyBear_Dialogue.setStage(10) ;* answer: False ENDIF ENDFUNCTION assembled code: WHILE (i > 0) ; .local ::temp0 int ; .local ::temp1 bool ; CALLMETHOD GetSize ::TeddyBearActorList_var ::temp0 ;@line 12 ; ASSIGN i ::temp0 ;@line 12 ; label0: ; COMPAREGT ::temp1 i 0 ;@line 13 ; JUMPF ::temp1 label1 ;@line 13 ; ISUBTRACT ::temp0 i 1 ;@line 14 ; ASSIGN i ::temp0 ;@line 14assembled code: WHILE (i) ; .local ::temp0 int ; CALLMETHOD GetSize ::TeddyBearActorList_var ::temp0 ;@line 12 ; ASSIGN i ::temp0 ;@line 12 ; label0: ; JUMPF i label1 ;@line 13 ; ISUBTRACT ::temp0 i 1 ;@line 14 ; ASSIGN i ::temp0 ;@line 14In case you would use next code, you will get an error: WHILE (i >= 0) i = i - 1 ; last "i" will be -1 at this point, that is out of bound, first array entry is "a[0]", first formlist entry is "fml.GetAt(0)" ... ENDWHILEUnfortunately "PeterMartyr" you are not fully right with your statement."cdcooley" has given the right answer, imho. Edited April 5, 2017 by ReDragon2013 Link to comment Share on other sites More sharing options...
Recommended Posts