Jump to content

RegisterForKey from a inventory item?


Recommended Posts

So, RegisterForKey is part of the Form script, ObjectReference extends Form, so in theory RegisterForKey should be available to object references, right?

 

But i'm trying to call it from an item in my inventory (extending object reference) and i'm getting this on the log "Unable to call RegisterForKey - no native object bound to the script object, or object is of incorrect type"

 

Testing this on a book, added to my inventory through an alias for testing purposes, but it's not working. Does RegisterForKey simply cannot work for an inventory item? I'd prefer to not need to call it on a quest or something, would be quite limiting.

 

Scriptname lalal extends ObjectReference

 

Event OnRead()

RegisterForKey(2)

EndEvent

 

Link to comment
Share on other sites

If he didn't have SKSE it wouldn't have compiled. :P

 

Frank, it's my understanding that, it cannot be called on an objectreference script. I know it does work attached to a quest.

 

What's your end goal, why would calling it via quest be limiting?

 

EDIT: maybe you have to tell the CK where to import the function from?

Edited by Fantafaust
Link to comment
Share on other sites

Should work with persistent items even if in the inventory.

If the reference is held in an alias, it will be persistent.

If it's held in a variable or property it will be persistent too.

Maybe something like this could work?

ObjectReference Property Myself auto hidden

Event OnInit()

Myself = self

EndEvent



Event OnRead()

RegisterForKey(2)

EndEvent

I found this article quite helpful : http://www.creationkit.com/index.php?title=Persistence_%28Papyrus%29

 

And this : https://github.com/xanderdunn/skaar/wiki/Understanding-Forms%2C-Object-References%2C-Reference-Aliases%2C-and-Persistence

Edited by Ghaunadaur
Link to comment
Share on other sites

Its meant to be an item you buy so the script should be self contained if posible. I'm going to try the persistence thing. On second thought i think i could use a quest to handle it even if its multiple items and in any case im going to need the items to be persistent in order for them to work the way i wanted...

 

Thanks all :)

Link to comment
Share on other sites

I've done some findings about inventory items, specially books in inventory and doing nasty stuff on them...

 

- Making a property point to self seems to make the object reference work almost fine , stuff works but there are some oddities...

 

- If multiple identical (as in same base object) persistent items are in inventory they only stack for as long as their variables and properties are identical, the moment they are different they no longer stack, which is useful. But the order of them in inventory appears random and not always the same so you can't do "equip/read the first, then open inventory and equip the second" because that second may or may not be same you equipped before. They each keep their own variables and can be tested by dropping and seeing the values of each. If different names were given to each ref with Jaxonz's renamer maybe this would be fixed.

 

- Activating a book (or actually the book activating itself) that is within a container works fine (forces reading) if it's persistent but kind of makes a temporal reference since it shows the "take" button as if it wasn't in your inventory, if you close the book without taking it everything is fine, you have your book in your inventory and works every time. But if you take it then it makes duplicate of it and both the original and the duplicate reset their variables, which is unfortunate. If only "can't take" flag worked... damn Bethesda.

 

- They also appear to need to be dropped to the ground once to get initialized or whatever, when added via alias inventory at least, otherwise it can't activate itself. From then on they work.

 

Putting everything together, too many bugs do do it from the inventory, i'd get them out temporary, but this means the take button will always be there, so i'd have to make something like if you take it don't do anything if you closed it then give it back, otherwise you'd loose it, or make duplicates.

Edited by FrankFamily
Link to comment
Share on other sites

A book is probably worst type of object you could have chosen as an item to hold a script that actually needs to register for events.

 

What are you trying to do? Maybe there's a simple way to work around your problem. In the many versions of my Storage Helpers mod I've tried all sorts of things with items in inventory.

Link to comment
Share on other sites

Yeah, i'm probably being too misterious about it. I'm not happy with the existing "write a journal ingame" mods, so i'd like to one myself that is:

- Unlimited in number, if you want to write 847 journals, write different stuff in each and dump them in the entrance of your home, you can, and each will keep it's own text. (of course 847 is crazy and nobody would make as many, but still, no limits. This not so much about journals, but to allow writing alchemy recipes, a bestiary, journal of what you do, anything, all at once. So each book has to store it's text, in strings and send it to the text replacement aliases at runtime.

- Unlimited in extension (if posible, if not to a reasonably high level)

- Supporting bold text, italic, iluminated letters, one click current date, etc etc

- Easy and quick to use, it needs to look like it was already there.

 

Haven't spent much on it yet, just laying down the basic functionality and ideas. Input method via RegisterForKey is sort of working since i got the book to be persistent, but i'm looking at skylib as a much cleaner alternative.

I've also got working the way to actually display the text on any amount of different books through text replacement and all the formatting stuff by used skse's string util, substring , find , addition, etc.

 

Currently the main issue is refreshing the text, which seems like it requires closing the book and opening, what lead to the issues above, the book animation playing twice (onread() it updates texts, closes menu and activates itself to refresh it), duplicates, etc.

 

And overall having the script in the book results in quite a few oddities (haven't tested the whole thing since i added persistence, checking just core funcionality now until that's is right, so maybe persistence improved that...)

 

I'm thinking maybe i should do the whole script quest based as in: a book gets read, it sends an event to the quest, the quest handles input, string calculations, additions, etc and sends the string back to the book for storage, then of the two updates the text replacement aliases. Wouldn't take away form the features i want it to have and probably having it in a quest will work better.

 

So, what i'm focusing right now: How to get the book refresh it's text without having a dedicated alias (that would mean 1 alias per book so no longer unlimited since i can't make unlimited aliases)?

The only way i've found is: OnRead() => update stuff => close => force reading of itself (issues above)

 

Something i'm considering is making the book not an actual book, and by that i mean that each empty alchemy recipe or journal you buy to write your stuff in it is actually a misc item, which may hold scripts better? and receives onequip events, when it's equipped it sends it's text string to the text replacement alias which updates and forces the reading of a single "master book" used by all items as a way to display text basically, thus avoiding the double book animation thing. But how to make this master book untakeble if "cant take" flag wont work? This could be done in conjuction with the more-quest-script-based idea ofc.

Edited by FrankFamily
Link to comment
Share on other sites

  • Recently Browsing   0 members

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