Arrays, and FormLists, and actors

Post » Tue Jun 19, 2012 9:37 am

I'm attempting to make a list of NPCs and, welp, it ain't working.

Using arrays like
actor[] BotArray = new actor[10]
Fails to compile in a script that extends Quest Conditional, throwing up the errors
(4,20): no viable alternative at input 'new'(4,29): required (...)+ loop did not match anything at input '['(4,9): Unknown user flag actor
So using arrays is out. Swapping Actor for ObjectReference throws up the same errors.

I tried an alternative, tracking the actor refs in a formlist like in The Good Old Days, but that doesn't work either:
a0aDwBotList.addForm((BotRef as Form))debug.Messagebox("List contains "+a0aDwBotList)
Returns an empty list, size functions claim it has no length, it just doesn't seem to work- with or without casting as a form. On the plus side at least it compiles.

So can anyone tell me where I'm going wrong? Papyrus is proving something of a challenge for my Fortran-addled physicist mind.
User avatar
Jessie Rae Brouillette
 
Posts: 3469
Joined: Mon Dec 11, 2006 9:50 am

Post » Tue Jun 19, 2012 9:45 am

I believe the syntax would be
Actor[] BotArray
edit: nevermind you had the right syntax
If your formlist says it's empty, it is empty or you've not hooked it up to the right (or any) formlist in the editor
User avatar
OTTO
 
Posts: 3367
Joined: Thu May 17, 2007 6:22 pm

Post » Tue Jun 19, 2012 1:07 am

I believe the syntax would be
Actor[] BotArray
I'm aware that's the syntax to declare an uninitialised array, but the code I was using is on the wiki page for how to declare and initialise an array. Literally it's
ObjectReference[] myObjectArray = new ObjectReference[10]
With the names changed. Although bizarrely it works if I remove the initialisation, so thanks I guess? WTF.

So, do I now have to initialise the array before using it (by assigning it a New Actor XYZ in the OnInitialise() event) or can I just pick random uninitilised elements after the current end point like BotArray[3] and set them, and that automatically adds to the length?
User avatar
Thema
 
Posts: 3461
Joined: Thu Sep 21, 2006 2:36 am

Post » Tue Jun 19, 2012 2:08 am

I'm attempting to make a list of NPCs and, welp, it ain't working.

Using arrays like
actor[] BotArray = new actor[10]
Fails to compile in a script that extends Quest Conditional, throwing up the errors
(4,20): no viable alternative at input 'new'(4,29): required (...)+ loop did not match anything at input '['(4,9): Unknown user flag actor
So using arrays is out. Swapping Actor for ObjectReference throws up the same errors.

I think your problem is that you're trying to use a variable which seems to be referred from outside the script.

My understanding is that only a Property could be referred from outside the script itself.

Try to add an Array Property from the script Properties menu...that might work! :-/
Jashkar
User avatar
Hayley Bristow
 
Posts: 3467
Joined: Tue Oct 31, 2006 12:24 am

Post » Tue Jun 19, 2012 10:30 am

I'm aware that's the syntax to declare an uninitialised array, but the code I was using is on the wiki page for how to declare and initialise an array. Literally it's
ObjectReference[] myObjectArray = new ObjectReference[10]
With the names changed. Although bizarrely it works if I remove the initialisation, so thanks I guess? WTF.

So, do I now have to initialise the array before using it (by assigning it a New Actor XYZ in the OnInitialise() event) or can I just pick random uninitilised elements after the current end point like BotArray[3] and set them, and that automatically adds to the length?

Most arrays are fixed length (ignoring ArrayLists and such), and the fact you need to declare its size makes me think that it doesn't automatically add to its length. But I could be wrong.
User avatar
ILy- Forver
 
Posts: 3459
Joined: Sun Feb 04, 2007 3:18 am

Post » Mon Jun 18, 2012 11:30 pm

I think your problem is that you're trying to use a variable which seems to be referred from outside the script.

My understanding is that only a Property could be referred from outside the script itself.

Try to add an Array Property from the script Properties menu...that might work! :-/
Jashkar
Thing is, it's not referred to from outside the script. It's all internal. I mean, you can't get more internal than the declaration, surely. Also I get the same errors when declaring it as a property- it won't accept being initialised in the declaration.
User avatar
Conor Byrne
 
Posts: 3411
Joined: Wed Jul 11, 2007 3:37 pm

Post » Tue Jun 19, 2012 10:02 am

Thing is, it's not referred to from outside the script. It's all internal. I mean, you can't get more internal than the declaration, surely. Also I get the same errors when declaring it as a property- it won't accept being initialised in the declaration.

Are you calling it inside a function?

From the wiki:

The new call must be done inside a function. You cannot use it on an object variable outside of a function. If you want a variable to start with an empty array, then you can make the array inside the OnInit event.
User avatar
Queen of Spades
 
Posts: 3383
Joined: Fri Dec 08, 2006 12:06 pm

Post » Mon Jun 18, 2012 8:26 pm

...Aaaaaah. It all falls into stupid, stupid place. So whilst you can declare arrays that any function in a script can access outside of functions, you can't initialise them. However, you can declare and initialise temporary arrays within functions.
Actor[] ThisArray = Actor[10]		 ;BAD WRONG CODE

Actor[] ThatArray						   ;GOOD CODEEvent OnInit()   ThatArray = New Actor[10]EndEvent
Function DeclareArray				  ;GOOD CODE   Actor[] OtherArray = Actor[10]EndFunction
It's good to know there's still chunks of the language that make no sense.

I've edited the wiki to put this information in a slightly more useful format.
User avatar
Nikki Morse
 
Posts: 3494
Joined: Fri Aug 25, 2006 12:08 pm

Post » Tue Jun 19, 2012 3:45 am

*Off Topic*

Please forgive me for asking here, Mr. Toaster (PM wouldn't go through). But do you have any plans to create locational damage for Skyrim like you did for Oblivion?

Also, thank you for all your mods! :-D
User avatar
Dragonz Dancer
 
Posts: 3441
Joined: Sat Jun 24, 2006 11:01 am

Post » Mon Jun 18, 2012 7:42 pm

Please forgive me for asking here, Mr. Toaster (PM wouldn't go through). But do you have any plans to create locational damage for Skyrim like you did for Oblivion?
Inbox must be full again.
Also, maybe. I shouldn't even be making this one, my course workload is kind of high.
User avatar
Emily Martell
 
Posts: 3469
Joined: Sun Dec 03, 2006 7:41 am

Post » Tue Jun 19, 2012 1:59 am

I wish I were here when you first asked this question, as I've run into it (and the answer) before and could have saved you a hassle :)

Basically, you can only initialise variables to literal values outside of a function (including events). I had an example like yours in a draft of my "http://www.cipscis.com/skyrim/tutorials/externalaccess.aspx" tutorial, and SmkViper (a dev) told me this as part of his feedback:
In your second “Calling Functions on External Objects” example you have “ObjectReference LinkedRef = GetLinkedRef()”. This won’t compile because it is outside a function or event. If you want to initialize an object variable with something other then a literal then you may want to use the OnInit() event. Though in your case, that might be too early for GetLinkedRef (your object may not have its linked ref available at the time the script is initialized).
Cipscis
User avatar
Rich O'Brien
 
Posts: 3381
Joined: Thu Jun 14, 2007 3:53 am


Return to V - Skyrim