Jump to content

CK Script: Whats wrong with this code? ?


g2mXagent

Recommended Posts

It is copied directly from the manual

https://www.creationkit.com/fallout4/index.php?title=Arrays_(Papyrus)

 

string[] myArray = new string[5]
myArray[0] = "Hello"
myArray[1] = "World"
myArray[2] = "Hello"
myArray[3] = "World"
myArray[4] = "Again"
Compile time error:
xxx.psc(17,19): no viable alternative at input 'new'
xxx.psc(18,8): no viable alternative at input '0'
Why??

 

Link to comment
Share on other sites

iirc to initialize an array, it needs to be placed inside function body, something like:

string[] myArray

function somefunction()
 myArray = new string[5]
 myArray[0] = "Hello"
 myArray[1] = "World" 
 myArray[2] = "Hello"
 myArray[3] = "World"
 myArray[4] = "Again"
endfunction 

 

call that function whenever you want

Also you can have that array as property and fill it from properties editor box

Edited by shavkacagarikia
Link to comment
Share on other sites

What shavkacagarikia said, but if you want it done when the game first loads the script (not terribly efficient) put it in a block like this.

string[] myArray

Event OnInit() ;Called when the script is first loaded into the save file (usually when the game starts)
 myArray = new string[5]
 myArray[0] = "Hello"
 myArray[1] = "World" 
 myArray[2] = "Hello"
 myArray[3] = "World"
 myArray[4] = "Again"
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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