Would appreciate help with a script

Post » Sun Nov 18, 2012 1:57 am

I'm tinkering around, and more as an exercise in learning than anything else I have a script which is supposed to populate a container with Alchemy ingredients when it's opened. In Oblivion this was a tedious gigantic script of doom, but I was eager to try it in Papyrus. To wit, I have the following:

Scriptname AllIngredients extends ObjectReferenceFormList Property everyingredient Auto{all default ingredients}Event OnActivate(ObjectReference akActionRef)self.removeallitems()Ingredient ingredInt iwhile i< everyingredient.getSize()   ingred = everyingredient.getAt(i) as Ingredient   self.additem(ingred, 10)   i+=1  endwhileendEvent

'everyingredient' is an correctly associated to a formlist with all of the default ingredients, and the script compiles successfully. My problem is that it doesn't actually do anything. I suspect, but am not sure, the problem is that 'self.additem' is not the correct way to insert an item into a container, but to be honest I'm at something of a loss.

Any help would be appreciated.
User avatar
TOYA toys
 
Posts: 3455
Joined: Sat Jan 13, 2007 4:22 am

Post » Sun Nov 18, 2012 12:36 am

Player.RemoveAllItems()

Player.Additem(ingred,10)

I think those are what you want rather than self.
User avatar
Emma-Jane Merrin
 
Posts: 3477
Joined: Fri Aug 08, 2008 1:52 am

Post » Sun Nov 18, 2012 6:06 am

It very specifically isn't adding them to the player inventory though, that's simple enough but not what I'm trying to do.

This script is attached to a barrel, and in theory should execute as soon as the barrel is opened, populating it with items and then showing the inventory. That's the behaviour I expected given how this sort of thing worked in Oblivion and even Morrowind. As mentioned I'm uncertain if it fails because I'm incorrectly referencing the container (self, which might not mean what I think it means) or because there's a more fundamental error somewhere.
User avatar
Bethany Short
 
Posts: 3450
Joined: Fri Jul 14, 2006 11:47 am

Post » Sun Nov 18, 2012 4:40 am

Oh I see.

then you want to use: AddToContainer(self)

RemoveAllItems(self)

I think because of the way Papyrus uses properties, self. doesn't actually have a reference in the game world.

I think those might do. Not able to test em out for you but i know the self keyword is passed as parameter to a function.
User avatar
Elisabete Gaspar
 
Posts: 3558
Joined: Thu Aug 31, 2006 1:15 pm

Post » Sun Nov 18, 2012 1:59 am

(self, which might not mean what I think it means)
Self refers to the object that the script is attached to, so in this case it is the barrel as an ObjectReference.

Looking at your code, the general idea is good, but this would be a problem:
Int i
So it's not defined at all when it gets to the while condition.

A simple change to:
Int i = 0 
should be enough...
User avatar
Queen
 
Posts: 3480
Joined: Fri Dec 29, 2006 1:00 pm

Post » Sun Nov 18, 2012 4:03 am

Btw, a slightly more efficient solution would be:
Int i = everyingredient.GetSize() - 1While i > -1  ingred = everyingredient.GetAt(i) as Ingredient    self.AddItem(ingred, 10)    i -= 1EndWhile
or, as JustinOther would point out (and a good learning opportunity):
Int i = everyingredient.GetSize() - 1While i > -1ingred = everyingredient.GetAt(i) as IngredientAddItem(ingred, 10)i -= 1EndWhile
The "self" is not actually needed as it is implied.
User avatar
Kelsey Anna Farley
 
Posts: 3433
Joined: Fri Jun 30, 2006 10:33 pm

Post » Sun Nov 18, 2012 7:49 am

Hey, thanks for the help and the suggestion. Unfortunately I can't get the wretched thing to work. I attempted to add some traces to spam my console with messages and see where it's going wrong, but absolutely none of them appear (including one immediately after 'Event OnActivate...' Is there some logic special to containers that prevents OnActivate from working properly in Skyrim?
User avatar
KIng James
 
Posts: 3499
Joined: Wed Sep 26, 2007 2:54 pm

Post » Sun Nov 18, 2012 12:06 am

Hey, thanks for the help and the suggestion. Unfortunately I can't get the wretched thing to work. I attempted to add some traces to spam my console with messages and see where it's going wrong, but absolutely none of them appear (including one immediately after 'Event OnActivate...' Is there some logic special to containers that prevents OnActivate from working properly in Skyrim?

Nothing special, OnActivate works fine on containers - that's how the chests work. How did you attach the code to the barrel?
User avatar
Talitha Kukk
 
Posts: 3477
Joined: Sun Oct 08, 2006 1:14 am

Post » Sun Nov 18, 2012 8:31 am

Here's what I have.
[img]http://i.imgur.com/Clryk.jpg[/img]

The script at present (haven't added your more efficient refinements at the moment, since I'm more concerned with function than elegance at this point):

Scriptname AllIngredients extends ObjectReferenceFormList Property everyingredient Auto{all default ingredients}Event OnActivate(ObjectReference akActionRef)Debug.Trace("Woohoo, script started")Debug.Trace("Container reference is : " + self)self.removeallitems()Ingredient ingredInt i = 0while i< everyingredient.getSize()   ingred = everyingredient.getAt(i) as Ingredient   self.additem(ingred, 10)   Debug.Trace("Added 10 " + ingred)   i+=1  endwhileDebug.Trace("Done")endEvent

The barrel appears in the world exactly where it's placed. Interacting with it brings up the empty inventory window. No debug messages are sent, no items appear, no other addons AT ALL are enabled while testing this. I'm genuinely stumped.

Edit - since I misunderstood the output of Trace - checked the Papyrus log in Skyrim\logs\script - there's nothing there either, just standard notification of memory usage.
User avatar
ILy- Forver
 
Posts: 3459
Joined: Sun Feb 04, 2007 3:18 am

Post » Sun Nov 18, 2012 5:52 am

The barrel appears in the world exactly where it's placed. Interacting with it brings up the empty inventory window. No debug messages are sent, no items appear, no other addons AT ALL are enabled while testing this. I'm genuinely stumped.

Edit - since I misunderstood the output of Trace - checked the Papyrus log in Skyrim\logs\script - there's nothing there either, just standard notification of memory usage.

What kind of barrel did you start with?

I just did a test, I duplicated the BarrelEmpty01, renamed it to BarrelTest and attached the following script:
Scriptname BarrelTestScript extends ObjectReferenceEvent OnActivate(ObjectReference akActionRef)debug.messagebox("OnActivate");debug.notification("OnActivate")endEvent
Everything worked just fine. (and there's two different example for outputing debug infomration. Messagebox stops and waits for input, useful for something like the OnActivate, and Notification just spams the top left message area, useful when you don't want it to stop, like in loop.)
User avatar
Noely Ulloa
 
Posts: 3596
Joined: Tue Jul 04, 2006 1:33 am

Post » Sat Nov 17, 2012 6:47 pm

Okay, changing to messageboxes resolved the 'Nothing is happening at all' panic, so I'm back to the original problem that my script simply doesn't work, hah.

Scriptname AllIngredients extends ObjectReferenceFormList Property everyingredient AutoEvent OnActivate(ObjectReference akActionRef)	Debug.MessageBox("Script started")		//this appears	self.removeallitems()	Ingredient ingred	Int i = 0	while i< everyingredient.getSize()	   ingred = everyingredient.getAt(i) as Ingredient	   self.additem(ingred, 10)	   Debug.Notification("Added 10 " + ingred)		//none of these messages appearDebug.Notification("i is currently : " + i)			//none of these messages appear	   i+=1	endwhileDebug.MessageBox("Done")		//this also appearsendEvent


The problem appears to be with my while loop, I'm uncertain where though.
User avatar
Wayne W
 
Posts: 3482
Joined: Sun Jun 17, 2007 5:49 am

Post » Sun Nov 18, 2012 3:20 am

The problem appears to be with my while loop, I'm uncertain where though.

Okay, add this debug before the start of the while loop:
Debug.Messagebox("count="+ everyingredient.GetSize())
This will make sure the formlist is being sent correctly.
User avatar
casey macmillan
 
Posts: 3474
Joined: Fri Feb 09, 2007 7:37 pm

Post » Sun Nov 18, 2012 5:11 am

That's the problem. It evaluates to 0, which is infuriating. The list itself (which has 93 members) and the linked property are in the screenshot I posted above, so I really have no idea what I've managed to do wrong here.
User avatar
Eibe Novy
 
Posts: 3510
Joined: Fri Apr 27, 2007 1:32 am

Post » Sat Nov 17, 2012 4:17 pm

That's the problem. It evaluates to 0, which is infuriating. The list itself (which has 93 members) and the linked property are in the screenshot I posted above, so I really have no idea what I've managed to do wrong here.
You might have done something as simple as forgetting to save in the CK. (Really annoys me when I do that!)

So I updated my test code, and now it looks like this:
Scriptname BarrelTestScript extends ObjectReferenceFormlist Property CookingIngredientsList autoEvent OnActivate(ObjectReference akActionRef)Debug.Messagebox("count="+ CookingIngredientsList.GetSize())Ingredient ingredInt i = CookingIngredientsList.GetSize() - 1While i > -1  ingred = CookingIngredientsList.GetAt(i) as Ingredient    self.AddItem(ingred, 10)    i -= 1EndWhileendEvent
As you can see, I am using CookingIngredientsList, which is already included in the CK. If you try this code, compile, then go back in to the CK and hit Autofill in the Property dialog and it will set the property. This code worked fine and now I have a barrel in my house full of cooking ingredients :wink:
User avatar
Jeff Tingler
 
Posts: 3609
Joined: Sat Oct 13, 2007 7:55 pm

Post » Sat Nov 17, 2012 11:20 pm

And now it works perfectly, my thanks.

I don't believe the problem was failing to save, since the various efforts you've talked me through have resulted in about 15 different saves in the last 30 minutes, but it seems to fail if I create a formlist called foo, a property called bar, and then associate foo to bar from the script property window. Your suggestion of giving the property an identical name to the form list and allowing the property window to autofill results in a barrel that does precisely what I wanted. I don't pretend to understand why this works but the previous approach did not, but I'm grateful in any event.

Many thanks for your assistance, and have a nice evening!
User avatar
Tessa Mullins
 
Posts: 3354
Joined: Mon Oct 22, 2007 5:17 am


Return to V - Skyrim