Jump to content

Prolems with a couple of NVSE functions...


HerrBaron

Recommended Posts

Hi guys,

 

It would appear that GetObjectType and Player.GetNumItems aren't working, always return 0.

 

I'm calling GetObjectType with a reference returned from GetHotKeyItem after checking that it's non-zero, like so:

...

set rItem to GetHotKeyItem ListIndex;
if ( rItem )
   set ObjectType to rItem.GetObjectType;
       if ( ObjectType == 40 ) ; weapon...
            ListAddReference WSTNExceptionsList, rItem;
       endif
endif

...

 

I'm cycling through the hotkey items for weapons prior to iterating the player's inventory to removing weapons from him into storage; I don't want to remove hotkey items.

 

In preparation for iterating, I'm calling GetNumItems to determine loop boundaries, like so:

 

set ListIndex to Player.GetNumItems - 1;

 

GetNumItems is always returning 0.

Can anyone shed some light on what's going on here?

 

Thanks!

 

P.S. MAN, what's with this EDITOR?? where do you shut off the HTML??

Link to comment
Share on other sites

I'm interested in the answer too, as this is a very strong contender for my own script's problem.

 

EDIT: Actually, GetNumItems seems to be working perfectly for me. I stuck a Debug ShowMessage in my loop and it's detecting the correct amount of items. Not my problem then :)

Link to comment
Share on other sites

I'm interested in the answer too, as this is a very strong contender for my own script's problem.

 

EDIT: Actually, GetNumItems seems to be working perfectly for me. I stuck a Debug ShowMessage in my loop and it's detecting the correct amount of items. Not my problem then :)

 

lucky you! heheh! :)

Link to comment
Share on other sites

  • 2 weeks later...

Well the loop with GetHotKeyItem should probably be called like so...

ref rItem
integer ObjectType
integer i
set i to 1
Label HotKeyLoop
if (i < 9)
set rItem to GetHotKeyItem i
if (rItem)
       	set ObjectType to rItem.GetObjectType
       	if (ObjectType == 40)
               	ListAddReference WSTNExceptionList, rItem
       	endif
endif
set i to i+1
goto HotKeyLoop
endif

 

The reason is that GetHotKeyItem expects an integer between 1 and 8 inclusive, the hotkeys for the keys 1 through 8. Using a return value from GetNumItems may or may not randomly work given a coincidence of inventory count and the hotkey numbers. So basically the above is iterating the 8 hotkey positions and setting rItem to the return value of the 8 key positions one at a time. Then you can compare the object type against the value of 40 for a weapon.

Link to comment
Share on other sites

Why GetNumItems would return 0 I don't know... maybe something above the code line is bombing?

 

 

Hey Astymma,

 

 

Yeah, all the above has been extensively rewritten several times now, finally ending up with the recommendations given by RickerHK, here: BethSoft forums. Turns out that calling rItem.GetObjectType was the problem; it needs to be called like so: set ItemType to GetObjectType rItem;

 

It turns out that there are definite bugs in the formlist methods for removing items, so the recommendation was that I should replace them instead. Unfortunately, this approach doesn't work, either; the code MAY run the first time through, but crashes if you run it again. So I'm stuck, unable to get a nice, custom weapon storage container to work without crashing. Ah, well...

 

 

Oh, and BTW, I had no idea I could use an alphanumeric name for a label; thought they had to be numeric only, so thank you for that; I find numeric labels to be very basic-like, and they offend my C++/C# sensibilities! :)

 

Best,

 

HB

Link to comment
Share on other sites

Why GetNumItems would return 0 I don't know... maybe something above the code line is bombing?

 

 

Hey Astymma,

 

 

Yeah, all the above has been extensively rewritten several times now, finally ending up with the recommendations given by RickerHK, here: BethSoft forums. Turns out that calling rItem.GetObjectType was the problem; it needs to be called like so: set ItemType to GetObjectType rItem;

 

It turns out that there are definite bugs in the formlist methods for removing items, so the recommendation was that I should replace them instead. Unfortunately, this approach doesn't work, either; the code MAY run the first time through, but crashes if you run it again. So I'm stuck, unable to get a nice, custom weapon storage container to work without crashing. Ah, well...

 

 

Oh, and BTW, I had no idea I could use an alphanumeric name for a label; thought they had to be numeric only, so thank you for that; I find numeric labels to be very basic-like, and they offend my C++/C# sensibilities! :)

 

Best,

 

HB

 

Ahh probably because it needs to be passed as a reference instead of being used as a reference caller since it's a base type.

Link to comment
Share on other sites

Why GetNumItems would return 0 I don't know... maybe something above the code line is bombing?

 

 

Hey Astymma,

 

 

Yeah, all the above has been extensively rewritten several times now, finally ending up with the recommendations given by RickerHK, here: BethSoft forums. Turns out that calling rItem.GetObjectType was the problem; it needs to be called like so: set ItemType to GetObjectType rItem;

 

It turns out that there are definite bugs in the formlist methods for removing items, so the recommendation was that I should replace them instead. Unfortunately, this approach doesn't work, either; the code MAY run the first time through, but crashes if you run it again. So I'm stuck, unable to get a nice, custom weapon storage container to work without crashing. Ah, well...

 

 

Oh, and BTW, I had no idea I could use an alphanumeric name for a label; thought they had to be numeric only, so thank you for that; I find numeric labels to be very basic-like, and they offend my C++/C# sensibilities! :)

 

Best,

 

HB

 

Ahh probably because it needs to be passed as a reference instead of being used as a reference caller since it's a base type.

 

 

Right. Also, the issue with formlists in NVSE seems to center around baseforms only. I've used formlists elsewhere in the mod with permanent references (followers), and you can add and remove those references all day long. When you try to do the same thing with baseforms, that's when you get the crashes.

Link to comment
Share on other sites

Hmm, from what I read about ListAddReference, that can't even be used with baseforms and the above way we called it is incorrect. It should be (ListAddReference list:formList, integer:index) with index optional (not present add to end of list as default). Since the calling convention used is R it won't work with a baseform reference since you won't be able to call (rItem.ListAddRef WSTNExceptionList). Edited by Astymma
Link to comment
Share on other sites

  • Recently Browsing   0 members

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