Jump to content

How to use AddItem() in a standalone script?


kurikinton

Recommended Posts

I'm having trouble using Additem() in a stand alone papyrus script (meaning one that is not a fragment).

 

I have a mod, with a potion object "thePotion" defined under Magic > Potions in the creation kit.

 

This works in a script fragment, say a dialog response end script, without any problem:

 

(Game.GetPlayer() as actor).Additem(thePotion, 1, 0)

 

In this case, using the dialog option in-game triggers that script and the potion is added to inventory.

 

Obviously, I use "AddProperty" under the script properties to add "thePotion" as a property of the script.

 

However, with a stand alone script (one that only shows up under the Papyrus Script Manager, I do it manually:

 

Potion Property thePotion Auto

 

and

 

(Game.GetPlayer() as actor).Additem(thePotion, 1, 0)

 

or

 

Game.GetPlayer().Additem(thePotion, 1, 0)

 

But this line is not executed in either case. There are no other apparent problems with the rest of the script.

 

This is all within the same mod. Can anyone guess what I'm doing wrong?

 

Thanks!

Link to comment
Share on other sites

Do we win a prize if we guess right? :P

 

I guess that you haven't attached the script to anything in the game, so it never gets initiated.

 

If I'm correct, put the script on a quest that starts enabled (the quest doesn't need to do anything, just be initiated to start the script up)

 

For my prize, I'd like a Phazed Plasma Rifle in a 40 Watt range; I've always wanted one of those. :D

Link to comment
Share on other sites

Ya, there's not really any such thing as a 'stand alone script' in Skryim. It sounds repulsive at first, especially if you're a programmer, but once you understand the system it's way better this way for the purpose of making mods for this engine.

 

Your script has to be on something, and it has to have a real representation in the world (a reference) to have any meaning for the most part. Quests, once started, count as this, and are great ways to run stuff once you understand them to a point. Dozens, possibly even the majority of actual quests in the game are hidden quests existing purely to manage things transparently.

 

Edit: just glanced again at the quests... the vast VAST majority of quests are such transparent management quests lol. To the point it almost seems like they could make it a separate form type and make the actual 'quest' a more simple thing lol. *almost*

Edited by SinderionsBones
Link to comment
Share on other sites

  On 1/16/2013 at 1:40 PM, Eckss said:

I guess that you haven't attached the script to anything in the game, so it never gets initiated.

 

Sorry, bad explanation. The script is attached to a magic effect, which is in turn attached to a spell.

 

I cut my manual definition and re-attached the line as a property in the script corner of the magic effect dialog box, but no improvement.

 

Incidentally, I use the exact same function, but with a different item code, a few lines earlier to give the player some gold, and that works fine.

 

EDIT:

OK, I take that back. I had the wrong mod set to active in the creation kit when I re-attached the property to the script via the interface instead of doing it manually, and it was simply getting overwritten by the original mod.

 

But anyway, long story short for anyone with a similar issue:

It seems that if you do not attach the referenced properties in your script through the creation kit's interface, and write it in manually instead, your script will compile fine but will not always function correctly.

 

But anyway, your reply lead me in the right direction, so thanks.

Edited by kurikinton
Link to comment
Share on other sites

  • Recently Browsing   0 members

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