Page 1 of 1

printf

Posted: Mon Oct 19, 2009 6:02 pm
by S3v3n11
Simple question. I am trying to print out the count of an item in my bags.

Code: Select all

    itemCount = inventory:getItemCount(204833);
   
   printf ("We have %d tools\n", itemCount );
I am getting the error:
scripts\rom\inv.lua:37: bad argument #1 to 'printf' (got nil)
Any ideas?

Re: printf

Posted: Mon Oct 19, 2009 6:18 pm
by S3v3n11
I think I know what is going on. itemCount is not getting set properly.

Code: Select all

inventory = CInventory();


	while(true) do

    if( keyPressedLocal(key.VK_SPACE) ) then
      break;
    end
    
    itemCount = inventory:getItemCount(204833);
    
   
   printf ("We have %d tools\n", itemCount );


		yrest(100);
	end


end
Here is my code snippet. Can someone tell me what I am doing wrong when I am trying to get the items counts for that item?

TIA!

Re: printf

Posted: Mon Oct 19, 2009 6:29 pm
by droppen
try

Code: Select all

RoMScript("GetBagItemCount("..itemId..")");
if that don't work, theres something wrong with the function that inventory has.

you can allso try

Code: Select all

itemTotalCount(itemNameOrId)
this function uses the bot's saved values of the item. for that you need to run inventory:update() first

Re: printf

Posted: Mon Oct 19, 2009 6:55 pm
by S3v3n11
That does not seem to work either. Anyone have an example of

Code: Select all

inventory:getItemCount(204833)
that works?

Or some other way I can get inventory item counts?

Thanks!

Re: printf

Posted: Mon Oct 19, 2009 7:29 pm
by droppen
S3v3n11 wrote:That does not seem to work either. Anyone have an example of

Code: Select all

inventory:getItemCount(204833)
that works?

Or some other way I can get inventory item counts?

Thanks!
as i said,

Code: Select all

inventory:update();
local count = inventory:getItemTotalCount(204833);

Re: printf

Posted: Tue Oct 20, 2009 12:50 am
by d003232
S3v3n11 wrote:That does not seem to work either. Anyone have an example of

Code: Select all

inventory:getItemCount(204833)
that works?

Or some other way I can get inventory item counts?

Thanks!
At which time or coding place are you doing that item count?
As droppen said, 'Inventory:getItemCount(itemId)' is the same as 'RoMScript("GetBagItemCount("..itemId..")");' and reads the value directly from the client. And it would return 0 if the item id isn't found.

e.g. test it with

Code: Select all

	<onLoad>
		-- Additional Lua code to execute after loading the profile
		-- and before the bot starts. e.g. You could overwrite profile settings here
		-- like: changeProfileOption("HP_REST", 60);
		printf("TEST: %s\n", inventory:getItemCount(454545) );

	</onLoad>
in the profiles onLoad event. You should get a 'TEST: 0' printout.

Re: printf

Posted: Wed Oct 21, 2009 10:27 pm
by droppen
actually, inventory:getItemTotalCount(204833); uses the bot's database of the items you have, it does not read the item count directly from the game, thats why you need to update inventory to have accurate data.