About Store Forum Documentation Contact



Post Reply 
slot[playerData.activeWeapon].valid() always returns false
Author Message
Ogniok Offline
Member

Post: #1
slot[playerData.activeWeapon].valid() always returns false
Hi!

I have a problem with my game, because
Code:
slot[playerData.activeWeapon].valid()
always returns false.

Definition:
Code:
Reference<ItemEC> slot[SLOT_NUM];        //These are references to items which are placed at certain slots

And my Inventory::update function:
Code:
if(slot[playerData.activeWeapon].valid())
      if(OrientP *point = owner.cskel.findPoint("HandR"))
         slot[playerData.activeWeapon]().matrix(Matrix().setPosDir(point->pos, point->perp, point->dir));

I think that false is a correct "answer", but why it's not valid? When i pick up item, it's added to item container but not to the reference.
(This post was last modified: 03-22-2010 09:37 PM by Ogniok.)
03-22-2010 09:36 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: slot[playerData.activeWeapon].valid() always returns false
you must assign object to reference so it can become valid

slot[x]=object;
03-22-2010 09:58 PM
Find all posts by this user Quote this message in a reply
Ogniok Offline
Member

Post: #3
RE: slot[playerData.activeWeapon].valid() always returns false
I have this code:

Code:
void Player::autoPickUp()
{
   if(!Kb.bp(KB_F)) return;

   Memc<Game::Obj*> obj;
   Vec test_pos = pos() - Vec(0, ctrl.height() / 2, 0);
   Game::World.objGet(obj, Ball(2, test_pos), OBJ_ITEM);

   REPA(obj)
   {
       if(ItemEC *item = CAST(ItemEC, obj[i]))
       {
         if(item->type2 == ITEM_WEAPON && item->mesh && Dist(test_pos, item->mesh->box * item->matrixScaled()) <= ctrl.radius() + 0.5f)
         {
             AddMessage(S + "Podniesiono " + item->name);
             Inv.slot[0] = *item;
             this->itemPickUp(*item);
         }
       }
   }
}

But it didn't works fine.
03-22-2010 10:00 PM
Find all posts by this user Quote this message in a reply
Ogniok Offline
Member

Post: #4
RE: slot[playerData.activeWeapon].valid() always returns false
It works fine if I remove:

Code:
itemPickUp(*item)

from autopickup function.

But, when it's removed and I'm not holding weapon, it's drawing laying on a terrain.
03-23-2010 03:35 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #5
RE: slot[playerData.activeWeapon].valid() always returns false
this->itemPickUp(*item);

this changes memory address of 'item' object
you need to set 'slot' in virtual Chr::itemAdded
03-23-2010 03:40 PM
Find all posts by this user Quote this message in a reply
Ogniok Offline
Member

Post: #6
RE: slot[playerData.activeWeapon].valid() always returns false
I have this code:

Code:
void Player::itemAdded(Game::Item &item)
{
    if(ItemEC *actItem = CAST(ItemEC, item))
    {
            //Inv.slot[actItem->type + 1] = CAST(ItemEC, item);
            Inv.slot[actItem->type + 1] = actItem;
    }

    Inv.itemAdded(item);
}

but when I try to compile my game i have an error:

Code:
1>d:\fps\player.cpp(112) : error C2682: cannot use 'dynamic_cast' to convert from 'EE::Game::Item' to 'ItemEC *'
03-23-2010 03:56 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #7
RE: slot[playerData.activeWeapon].valid() always returns false
if(ItemEC *actItem = CAST(ItemEC, &item))

you're missing __super::itemAdded
03-23-2010 03:59 PM
Find all posts by this user Quote this message in a reply
Ogniok Offline
Member

Post: #8
RE: slot[playerData.activeWeapon].valid() always returns false
It works fine now.
03-24-2010 09:22 PM
Find all posts by this user Quote this message in a reply
Post Reply