getnumitems error

Post » Thu Apr 29, 2010 4:06 am

getnumitems isnt returning the number of items in my container.

I am using PrintToConsole to print every variable that comes up
it prints that the condition is true,
it prints the containers name
there is a stack of 58 arrows in it.

set numberitems to CNTRef.getnumitemsPrintToConsole "%n is my container", CNTRef

prints the container name to the console

it says it has zero items when

set numberitems to CNTRef.getnumitemsPrintToConsole "% items in my container", numberitems


should give me a value of 1 shouldn't it?
User avatar
Roberta Obrien
 
Posts: 3499
Joined: Tue Oct 23, 2007 1:43 pm

Post » Wed Apr 28, 2010 4:52 pm

Did you try it with: "%.0f items in my container", numberitems
User avatar
Veronica Martinez
 
Posts: 3498
Joined: Tue Jun 20, 2006 9:43 am

Post » Thu Apr 29, 2010 5:39 am

Did you try it with: "%.0f items in my container", numberitems


thanks, that worked, doing a step by step, unfortunately, a step isn't working
User avatar
Tamara Dost
 
Posts: 3445
Joined: Mon Mar 12, 2007 12:20 pm

Post » Thu Apr 29, 2010 2:21 am

script now stops working at
while (numberitems >= 0)			PrintToConsole "%.0f items in my container 2", numberitems 			set itemref to CNTRef.getinventoryobject numberitems			PrintToConsole "%.0f items in my container 2", numberitems 			PrintToConsole "%.0f items in my container 3", itemref 			PrintToConsole "%n name items", itemref 			set itemtype to itemref.getobjecttype


does the first print once, gives me 3 items, which is correct
second print gives me 3 items, which is correct
3rd print gives me 0 items

PrintToConsole "%n name items", itemref gives a

is itemref just not coded correctly here? the script terminates and doesnt continue
User avatar
biiibi
 
Posts: 3384
Joined: Sun Apr 08, 2007 4:39 am

Post » Thu Apr 29, 2010 1:18 am

I might be wrong, but isn't it always starting from "0"?
GetInventoryObject with an index greater than what is inside the container will not give you anything of use.

And the "%.0f", awaiting a float value, will not work with "itemref", clearly a form id reference value.
User avatar
cassy
 
Posts: 3368
Joined: Mon Mar 05, 2007 12:57 am

Post » Wed Apr 28, 2010 7:37 pm

I might be wrong, but isn't it always starting from "0"?
GetInventoryObject with an index greater than what is inside the container will not give you anything of use.

And the "%.0f", awaiting a float value, will not work with "itemref", clearly a form id reference value.



sorry, its %1 Of, copy paste did something weird with the font

and that allowed it to move to the next bug, thanks. will post the next one soonish
User avatar
carla
 
Posts: 3345
Joined: Wed Aug 23, 2006 8:36 am

Post » Thu Apr 29, 2010 3:34 am

what is the correct way of doing this one

set itemtype to itemref.getobjecttypePrintToConsole "%n name items", itemtype 


cant figure out the correct % for the printtoconsole
User avatar
Valerie Marie
 
Posts: 3451
Joined: Wed Aug 15, 2007 10:29 am

Post » Thu Apr 29, 2010 1:44 am

what is the correct way of doing this one
You must learn what the different %# means. The OBSE documentation has a section explaining the use of each format specifier, so I suggest you read that. For example, your last code snippet assigns a long variable, and you try to use %n to write its value, even though the docs says "%n - replaced with the name of a reference or object passed in a ref variable". Since a long is not a reference or object with a name, it will fail.

To print out the value of numbers as you try to do you need to use %g or %.0f.
User avatar
Richard Thompson
 
Posts: 3302
Joined: Mon Jun 04, 2007 3:49 am

Post » Wed Apr 28, 2010 3:39 pm

I did read it, but couldn't make enough sense from the examples, which is why I ask questions here, because you guys are far more knowledgeable and can make better sense of it.
User avatar
phil walsh
 
Posts: 3317
Joined: Wed May 16, 2007 8:46 pm

Post » Wed Apr 28, 2010 11:52 pm

I did read it, but couldn't make enough sense from the examples, which is why I ask questions here, because you guys are far more knowledgeable and can make better sense of it.

Ok, then here's a short intro. In general you can do almost everything you need using the vanilla %.#f (where the # is replaced by the number of decimals you want written, i.e. #.0f if you want no decimals), %n, %i and possibly %z.

%.#f is for writing the value of numbers (i.e. any short, long or float variable).
  float myVar  ...  set myVar to 5.72  PrintC "%.1f", myVar  --- Output: 5.7


%i is for writing the formid of references, and %n for the name of references.
  ref CNTRef  ...  PrintC "%n has formId %i", CNTRef, CNTRef  ---  Output:  has formId 


%z is for writing a string_var
  string_var myName  ...  let myName := CNTRef.GetName  PrintC "Name is %z", myName  ---  Output: Name is 

User avatar
Eddie Howe
 
Posts: 3448
Joined: Sat Jun 30, 2007 6:06 am

Post » Wed Apr 28, 2010 6:39 pm

bloody thing still isn't working

short counted 			long numberitems		short itemcount			long itemtype	ref itemref	;a while loop;little lower downset numberitems to (numberitems - 1)set itemref to CNTRef.getinventoryobject numberitems	                                                              PrintToConsole "%n", itemref set itemtype to itemref.getobjecttype	                                                              PrintToConsole "%.0f type of item", itemtype ;tried with the %g as wellset itemcount to CNTRef.getitemcount itemref	                                                              PrintToConsole "%.0f %n", itemcount, itemref ;loop



objects in container 2
1 stack of entoma 2
1 stack arrows 56

results of print
Steelblue entoma
0 type of item..................should retype that to type 0, itemtype should be 25, not 0
2 Steelblue entoma

Steel arrow
0 type of item................. need same correction, should also be item type 34, not 0
56 Steel arrows

I still cant see where I am going wrong
User avatar
Thema
 
Posts: 3461
Joined: Thu Sep 21, 2006 2:36 am

Post » Thu Apr 29, 2010 2:32 am

I still cant see where I am going wrong

A simple error I think. Things in containers/inventory aren't references, but base objects. GetObjectType can be called on either references or objects, and you're using the reference syntax with a ref variable holding a base obejct. Change the line to "set itemtype to getobjecttype itemref" and it should work.
User avatar
Lauren Dale
 
Posts: 3491
Joined: Tue Jul 04, 2006 8:57 am

Post » Wed Apr 28, 2010 3:47 pm

A simple error I think. Things in containers/inventory aren't references, but base objects. GetObjectType can be called on either references or objects, and you're using the reference syntax with a ref variable holding a base obejct. Change the line to "set itemtype to getobjecttype itemref" and it should work.


new misinterpretation also known as I am still messing up

                                PrintToConsole "%n is a Type %.0f item", itemref, itemtype set effecttype to GetNthEffectItemCode itemref 1				PrintToConsole "%n has %.0f effect", itemref, effecttype


result
Gold Dust is a Type 25 item.................... alchemy
Gold dust has 1413567044 effect.................??? was trying for the 4 letter code that alchemy ingredients have in each tier.

here I was trying for the novice effect, obviously, doing something wrong. I need to learn more, but appreciate the help, the other GetNth... commands were for active magic items and such, not sure which actually applies


tested effectype with %c, %n, %g, and %.0f
User avatar
Sunnii Bebiieh
 
Posts: 3454
Joined: Wed Apr 11, 2007 7:57 pm


Return to IV - Oblivion