Jump to content

array size as variable?


Recommended Posts

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

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
ENDFUNCTION

diziet wrote: "the purpose of this function is to return a list of the display names of the items in the formlist"

 

some links

 

;-------------------------------------------------
 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

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...