Help with a Team component
As I am very new to C++, I am having troubles creating my Team Component. There are a few syntax errors, but I am a bit confused so I'd thought I'd post my work so far, and look for some explanations on what I am doing wrong, and what I am not understanding.
I am trying to create a CompTeam, but I seem to have made a bit of a mess of it. I started off with CompBasics and began editing that into CompTeam. I would appreciate a few pointers on where I am going wrong
Files are attached below.
I am trying to create a variable m_TeamNum and want lua functions to get and set team number.
I am trying to create a CompTeam, but I seem to have made a bit of a mess of it. I started off with CompBasics and began editing that into CompTeam. I would appreciate a few pointers on where I am going wrong
Files are attached below.
I am trying to create a variable m_TeamNum and want lua functions to get and set team number.
- Attachments
-
- CompTeam.hpp
- The Header file
- (2.73KiB)Downloaded 617 times
-
- CompTeam.cpp
- The cpp file
- (5.19KiB)Downloaded 611 times
Re: Help with a Team component
Hi SoulRider,
I've just had a look at your files. Generally, they look very good. I think what got you caught was the very first two lines in the header file:
The problem is the "BASICS" part, that is, these two lines are the same as in the
This error now and then happens to me, too, and often in such cases it is completely unclear from compiler output that this is the root of the problem, because the error messages tend to point entirely elsewhere. If you change these two lines to e.g.
the problem will be solved, and any subsequent compiler error messages start to make sense again.
I'm sure you can figure out the subsequent problems on your own, but I too looked a bit further: Most errors are trivial, such as a missing trailing T in
I saw that you implemented
See the example scripts in
Of course, using these methods with the string parameters is somewhat inconvenient, and implementing custom methods as you are doing is a good method to bridge the gap until our component system can automatically provide script access such as
Finally, in the code in the
I've just had a look at your files. Generally, they look very good. I think what got you caught was the very first two lines in the header file:
Code: Select all
#ifndef CAFU_GAMESYS_COMPONENT_ENTITY_BASICS_HPP_INCLUDED
#define CAFU_GAMESYS_COMPONENT_ENTITY_BASICS_HPP_INCLUDED
CompBasics.hpp
file.This error now and then happens to me, too, and often in such cases it is completely unclear from compiler output that this is the root of the problem, because the error messages tend to point entirely elsewhere. If you change these two lines to e.g.
Code: Select all
#ifndef CAFU_GAMESYS_COMPONENT_ENTITY_TEAM_HPP_INCLUDED
#define CAFU_GAMESYS_COMPONENT_ENTITY_TEAM_HPP_INCLUDED
I'm sure you can figure out the subsequent problems on your own, but I too looked a bit further: Most errors are trivial, such as a missing trailing T in
ComponentTeamT
, a single colon where double colon :: is needed, and so on.I saw that you implemented
GetTeamNumber()
and SetTeamNumber()
. This is of course possible, but with variables that are declared of type TypeSys::VarT<...>
and processed by method FillMemberVars()
, although it does no harm, it is not necessary, because the component system automatically provides you with Lua get and set methods for such variables:
Code: Select all
-- in Lua code, if Team is your team component:
local tn = Team:get("TeamNum") -- "TeamNum" is the string given in the C++ constructor.
Team:set("TeamNum", 1 - tn) -- toggle 0 and 1 ;-)
Games/DeathMatch/Scripts
for plenty of similar examples of the other components, and see the Base component reference documentation for more details about the get()
and set()
methods.Of course, using these methods with the string parameters is somewhat inconvenient, and implementing custom methods as you are doing is a good method to bridge the gap until our component system can automatically provide script access such as
Team.TeamNum
etc. Another reason for custom methods is any functionality that is not covered by the automatically provided methods.Finally, in the code in the
cpp
file that mentions ComponentTeamT::EntityTeamT
, I didn't know what to do with it, and this is where I stopped for now.Best regards,
Carsten
Carsten
Re: Help with a Team component
Thanks a lot for the help so far. I will go through it again, and then will update with any further issues I am having. As I am a play and learn person, I generally ask questions until I reach a better understanding
I am really enjoying taking on this project, it is great fun, although a little brain twisting at times
I am really enjoying taking on this project, it is great fun, although a little brain twisting at times
Re: Help with a Team component
OK, I have read your instructions on get() and set(), and yet I cannot get them working....
When I use this code:
I have made lots of small changes, and generated lots of different errors, but I cannot work out the correct method of using get() and set(), as copying the method in the documentation doesn't work.
EDIT---------------------------------
Sorry, I just realised get() and set() are lua methods.... So I don't need to implement any functions in this component at all, only the variable?
When I use this code:
Code: Select all
int ComponentTeamT::GetTeamNumber(lua_State* LuaState)
{
int tn = ComponentTeamT:get("TeamNum");
lua_pushinteger(LuaState, tn);
return 1;
}
int ComponentTeamT::SetTeamNumber(lua_State* LuaState)
{
if (lua_isnumber(LuaState, 4))
{
ComponentTeamT:set("TeamNum", LuaState);
return 1;
}
}
Code: Select all
I get these errors:
Libs\GameSys\CompTeam.cpp(84) : error C2275: 'cf::GameSys::ComponentTeamT' : ill
egal use of this type as an expression
Libs\GameSys\CompTeam.cpp(84) : error C2275: 'cf::GameSys::ComponentTeamT' : ill
egal use of this type as an expression
Libs\GameSys\CompTeam.cpp(84) : error C2143: syntax error : missing ';' before '
:'
Libs\GameSys\CompTeam.cpp(84) : error C2143: syntax error : missing ';' before '
:'
Libs\GameSys\CompTeam.cpp(94) : error C3861: 'set': identifier not found
scons: *** [Libs\build\win32\vc10\x86\release\GameSys\CompTeam.obj] Error 2
scons: building terminated because of errors.
EDIT---------------------------------
Sorry, I just realised get() and set() are lua methods.... So I don't need to implement any functions in this component at all, only the variable?
Last edited by SoulRider on 2014-08-15, 21:06, edited 2 times in total.
Re: Help with a Team component
Correct!SoulRider wrote:Sorry, I just realised get() and set() are lua methods.... So I don't need to implement any functions in this component at all, only the variable?
Best regards,
Carsten
Carsten
Re: Help with a Team component
Well, now that is sorted, all seems to be ok. Component compiles correctly, woohoo.
A quick question about scripts. I have noticed for example the door object script. It has no C++ component code, it appears to be a script created entirely in lua from components. Is this correct? It sure makes things easier for me to use that approach
Here attached are the Team files again now they are completed (subject to testing).
A quick question about scripts. I have noticed for example the door object script. It has no C++ component code, it appears to be a script created entirely in lua from components. Is this correct? It sure makes things easier for me to use that approach
Here attached are the Team files again now they are completed (subject to testing).
- Attachments
-
- CompTeam.hpp
- Header
- (2.5KiB)Downloaded 583 times
-
- CompTeam.cpp
- cpp
- (3.16KiB)Downloaded 589 times
Re: Help with a Team component
Yes, this is correct.SoulRider wrote:A quick question about scripts. I have noticed for example the door object script. It has no C++ component code, it appears to be a script created entirely in lua from components. Is this correct? It sure makes things easier for me to use that approach
Whenever you need components that define the "behavior" of an entity, using the Script component as seen in the example with the doors is a good way to go -- this is what Script components were made for. The only "downside" of this approach is that immediately related variables, although they can freely be defined and used in the Lua script code, cannot be seen in the Map Editor's grid view (the "Entity Inspector"). You can complement this with extra components such as your Team component at any time, of course, and/or "bypass" this limitation via the ScriptCode property of the Script components (the doors in map Kidney use this approach, too).
Looking good!Here attached are the Team files again now they are completed (subject to testing).
Best regards,
Carsten
Carsten
Re: Help with a Team component
Quick question, How do I get my new component to show up in CaWE?
I have added it to the HumanPlayer component, but I also want to add it to the editor list of components, so I can make objects team specific within the maps.
I have added it to the HumanPlayer component, but I also want to add it to the editor list of components, so I can make objects team specific within the maps.
Re: Help with a Team component
Did you add it to the list at the bottom of theSoulRider wrote:Quick question, How do I get my new component to show up in CaWE?
Libs/GameSys/AllComponents.cpp
file? (Requires a matching #include
at the top as well.)(The comment in the file explains why this inconvenient list is unfortunately necessary.)
This should be enough for the component to appear in CaWE.
Best regards,
Carsten
Carsten
Re: Help with a Team component
Thanks Carsten. Everything working correctly so far.
It seems that changes to AllComponents.cpp causes a large portion of the engine to be rebuilt
It seems that changes to AllComponents.cpp causes a large portion of the engine to be rebuilt
Who is online
Users browsing this forum: No registered users and 11 guests