Page 1 of 1

Reading Components Info

Posted: 2014-08-30, 06:03
by SoulRider
I have created a new component called CompScore. I have implemented the variables m_Score, m_Kills & m_Deaths. I have added the score component to CompHumanPlayer.

I have removed the code for AddFrags from HumanPlayer, and created AddKill(), AddScore() etc in the Score lua script.

I am now trying to update the player HUD to read the kills variable, instead of frags. I have done all the cosmetic changes, but my problem is calling the variable.

gui.Player only references variables available directly in the HumanPlayer Component, and when I try and call through gui.Entity with the following:

local kills = gui.Entity:GetComponent("Score"):get("Kills")

I get told I am trying to index a nil value. Here are my files.

I haven't yet been able to test the AddKills() code etc, as I can't get the GUI working with the component. If you could shed some light on it, I would be grateful.

Re: Reading Components Info

Posted: 2014-08-30, 15:39
by Carsten
Overall, this is looking good!

Have you added a Score component instance to a newly instantiated player?
See method CaServerWorldT::InsertHumanPlayerEntityForNextFrame() in file Ca3DE/Server/ServerWorld.cpp for details, adding the Score component at about line 132 should work.

As an alternative, it would probably be possible (and maybe easier) to use the Inventory component for additional custom counters. It would save you from customizing the C++ code (which is probably not what you want, though ;-) ), and I've not verified that this works.

Re: Reading Components Info

Posted: 2014-08-30, 19:45
by SoulRider
Thanks for the advice. I added the score component into the serverworld file and all works great :D

Well, at least the GUI does, I don't have anyone to shoot at to see if the kills register!!

I am now adding the team number component. I think I have figured out how to integrate my gamerules code into the scripts already there. It just took me a little while to think about it in the right way :D

Re: Reading Components Info

Posted: 2014-08-31, 14:40
by Carsten
Ok, that sounds great, it's good to hear that! :up: