Language: 
To browser these website, it's necessary to store cookies on your computer.
The cookies contain no personal information, they are required for program control.
  the storage of cookies while browsing this website, on Login and Register.

Author Topic:  why our containers have no inventory pointers in lua ?  (Read 114 times)

0 Members and 1 Guest are viewing this topic.

Dolfo

« on: 22, September 2023, 14:26:55 »
Code: [Select]
if obj.type==game.TYPE_CONTAINER then
 pl:Write("container : " .. obj.name, game.COLOR_YELLOW)
 -- why our containers have no inventory pointers in lua ???
 if obj.inventory==nil then
  pl:Write("inv is null", game.COLOR_YELLOW)
 end
end
I get on all my containers null? I can't browse recursive the containers in lua with this null pointers.  :(
Looking in daimonin_object.c we have

Code: [Select]
/* All entries MUST be in same order as field_id enum above */
struct attribute_decl GameObject_attributes[] =
{
...
{"inventory", FIELDTYPE_OBJECT, offsetof(object_t, inv), FIELDFLAG_READONLY, 0},
...
also what is the meaning of this comment line?
/* All entries MUST be in same order as field_id enum above */
There is no field_id enum above?  ::)

Edit:
Cool, same lua code is working today on a newer server folder.  :o

Wow, someone really trolls me, close to the moment, when i thought, now church.lua script is finished, all containers have again no inv->pointers.  :'(

Ok, the troll was me.

Containers have only an inv pointer when they have at least one item in. Without items in the inv pointer is for sure null. *bump against the wall* Yes, sometimes learning things could be a hard life session.  ::)
« Last Edit: 24, September 2023, 20:34:33 by Dolfo »
Don't believe the shit, you hear in mainstream. Believe your own body. Your body is speaking always the true to you. But you need to understand your body. Hear to your body, not to your ego. And when body is calling to you: "Hey something is wrong!" find the reason(s) for that. Man in White don't go for that, they don't want to heal you. They want earn money and sell you medicine, you should take rest of your life. You are not the patient, you are their customer. Never forget this!

_people_

« Reply #1 on: 03, October 2023, 02:55:34 »
Yep, on both the server C side and the Lua side, obj->inv or object.inventory are null/nil with nothing inside. This is because inventories are stored in a linked list, so inventories are iterated via obj->inv->next.

Lua has a global function for iterating inventories: for obj in obj_inventory(parent) do ... end

This will do nothing if the object has no inventory.
-- _people_ :)

Tags:
 

Related Topics

  Subject / Started by Replies Last post
20 Replies
12334 Views
Last post 14, June 2007, 11:52:23
by smacky
15 Replies
3438 Views
Last post 16, March 2008, 20:19:43
by vinhi
15 Replies
2762 Views
Last post 21, April 2008, 17:52:10
by smacky
1 Replies
840 Views
Last post 30, July 2010, 17:09:38
by Anich
8 Replies
3820 Views
Last post 28, December 2013, 14:53:25
by smacky