Jump to content

Question about declaring/initializing ararys


irswat

Recommended Posts

;string[] SVE_DumpArray=new string[31]

Event OnInit()
	
	if ((SVE_DumpArray[0]!="initialized") || (!SVE_DumpArray[0]))
		string[] SVE_DumpArray=new string[31]
		SVE_DumpArray[1]="initialized"
	endif
	
endEvent

results in the following compiler errors.

 

...SVE_ParserEngine.psc(25,6): only arrays can be indexed
...SVE_ParserEngine.psc(25,22): cannot compare a none to a string (cast missing or types unrelated)
...SVE_ParserEngine.psc(25,44): variable SVE_DumpArray is undefined
...SVE_ParserEngine.psc(25,44): only arrays can be indexed

 

Understandable. So I chance the declaration to:

 

string[] SVE_DumpArray = new string[31]

and I get compiler error "...SVE_ParserEngine.psc(21,25): no viable alternative at input 'new'"

 

I don't understand. Any ideas?

 

Link to comment
Share on other sites

First error is because you use the array before declaring, second is because new must be within a function or event

 

to check to see if it's initialized you can do this

if !SVE_DumpArray

i.e.

if SVE_DumpArray == none

but i don't see the need to check that since when the scripts runs oninit the array will be guaranteed empty and after that oninit will not run again until the object is reset in which case the array is destroyed and empty again.

string[] SVE_DumpArray

Event OnInit()
SVE_DumpArray = new string[31]
endEvent

To initialize the array like a "new outside of functions" you can make it a property and add elements on ck too.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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