Reading Components Info

Get technical support about the C++ source code and about Lua scripts for maps, entities, GUIs, the console, materials, etc. Also covered are the Cafu libraries and APIs, as well as compiling, linking, and the build system.
Post Reply
SoulRider
Posts:95
Joined:2014-04-06, 00:16
Reading Components Info

Post by SoulRider » 2014-08-30, 06:03

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.
Attachments
CompScore.hpp
(1.91KiB)Downloaded 387 times
CompScore.cpp
(2.67KiB)Downloaded 419 times
CompHumanPlayer.hpp
(9.86KiB)Downloaded 399 times
CompHumanPlayer.cpp
(66.95KiB)Downloaded 398 times
Score.lua
(795Bytes)Downloaded 410 times
HumanPlayer.lua
(7.25KiB)Downloaded 418 times
HUD_main.cgui
(4.56KiB)Downloaded 397 times
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Reading Components Info

Post by Carsten » 2014-08-30, 15:39

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.
Best regards,
Carsten
SoulRider
Posts:95
Joined:2014-04-06, 00:16

Re: Reading Components Info

Post by SoulRider » 2014-08-30, 19:45

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
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Reading Components Info

Post by Carsten » 2014-08-31, 14:40

Ok, that sounds great, it's good to hear that! :up:
Best regards,
Carsten
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests