dizietemblesssma Posted August 26, 2020 Share Posted August 26, 2020 I have the following function: String Function dz_form_array_item_names(Formlist list) int j j = list.GetSize() string[] names ;string name names = new string[j] int i i = 0 While i < j - 1 names[i] = list.GetAt(i) as string ;names[i] = name i = i + 1 EndWhile Return names as string EndFunction unless I comment out the line:names = new string[j] I get the compile error:dz_auto_outfit_mcm_menu.psc(647,20): mismatched input 'j' expecting INTEGER the purpose of this function is to return a list of the display names of the items in the formlist, I know that the formlist is not empty from other debugging statements, I'm assuming the reason this does not give me anything other than an empty array is becasue the array 'names' is not initialised, but how to do that? diziet Link to comment Share on other sites More sharing options...
ReDragon2013 Posted August 26, 2020 Share Posted August 26, 2020 Your approach is wrong! ;-------------------------------------------------- String FUNCTION dz_form_item_values(Formlist list) ;-------------------------------------------------- string s ; local string variable is empty by default int m = list.GetSize() int i = 0 WHILE (i < m) ; from GetAt(0) up to GetAt(max-1) s = s + (list.GetAt(i) as String) ; save into string s = s + "," ; add separator i = i + 1 ENDWHILE RETURN s ; return the local string to caller function or event ENDFUNCTIONdiziet wrote: "the purpose of this function is to return a list of the display names of the items in the formlist" some linksoverview https://www.creationkit.com/index.php?title=Category:PapyrusGetName() https://www.creationkit.com/index.php?title=GetName_-_FormGetActorBase() https://www.creationkit.com/index.php?title=GetActorBase_-_ActorGetLeveledActorBase() https://www.creationkit.com/index.php?title=GetLeveledActorBase_-_Actor ;------------------------------------------------- String FUNCTION dz_form_item_names(Formlist list) ;------------------------------------------------- string s ; local string variable is empty by default int m = list.GetSize() int i = 0 WHILE (i < m) ; from GetAt(0) up to GetAt(max-1) form fm = list.GetAt(i) IF (fm as Actor) actorBase AB = (fm as Actor).GetLeveledActorBase() s = s + (AB.GetName() as String) ; add o string ELSE IF (fm as ObjectReference) fm = (fm as ObjectReference).GetBaseObject() ENDIF s = s + (fm.GetName() as String) ; add to string ENDIF s = s + "," ; add separator i = i + 1 ENDWHILE RETURN s ; return the local string to caller function or event ENDFUNCTION Link to comment Share on other sites More sharing options...
dizietemblesssma Posted August 27, 2020 Author Share Posted August 27, 2020 Oh cŵl thanks.For info, do you know why the line:names = new string[j]would give the compile error that j is not an integer?since:j = list.GetSize() I'll try your code, it seems simpler, I did not know you could concatenate strings like that:) diziet Link to comment Share on other sites More sharing options...
IsharaMeradin Posted August 27, 2020 Share Posted August 27, 2020 Because in this instance a literal integer is required. A variable will not work. It is explained on the page about Arrays at the CK Wiki You cannot use a variable or expression to specify the length of an array - it must be declared with an Integer Literal. Link to comment Share on other sites More sharing options...
dizietemblesssma Posted August 27, 2020 Author Share Posted August 27, 2020 Because in this instance a literal integer is required. A variable will not work. It is explained on the page about Arrays at the CK Wiki You cannot use a variable or expression to specify the length of an array - it must be declared with an Integer Literal. Ah, that seems restricting, but then I'm not a programmer:) diziet Link to comment Share on other sites More sharing options...
Evangela Posted August 28, 2020 Share Posted August 28, 2020 It's another one of those "if Papyrus was built using C++ then why does it carry so many restrictions" things.. Link to comment Share on other sites More sharing options...
Recommended Posts