How to access GameTokens in C++ ?

Hi. Does anyone know how I can access my GameTokens in C++?
What I need to do is to read the value of a GameToken and I need to write a new value for a GameToken.

I found this here: ... kenIt.html

But I'm not really sure how I should use it. Do I really need to iterate over every GameToken? And how do I read/write to a GameToken.

My current approach is this:

Code: Select all

void test() { IGameTokenSystem* pTokenSystem = CCryAction::GetCryAction()->GetIGameTokenSystem(); IGameToken* pToken = pTokenSystem->FindToken("Test"); TFlowInputData data; data.Set(15); int value = (int) pToken->GetValueAsString(); CryLogAlways((char*)value); //pTokenSystem->SetOrCreateToken(pToken->GetName(), data); pToken->SetValue(data); }
But I'm getting an error when I build the solution:
Error LNK2001 unresolved external symbol "private: static class CCryAction * CCryAction::m_pThis" (?m_pThis@CCryAction@@0PEAV1@EA)

Thanks for your time.
- Jannis

Re: How to access GameTokens in C++ ?

We need a bit more information on where your code is in your project.

For starters if this is outside of CryAction and inside your game project you should be accessing the GameToken interface like this:


Code: Select all

IGameTokenSystem* pTokenSystem = gEnv->pGame->GetIGameFramework()->GetIGameTokenSystem()

Code: Select all

IGameTokenSystem* pTokenSystem = gEnv->pGameFramework->GetIGameTokenSystem()
If you are doing it in CryAction it looks like you might be missing an include for CCryAction.

Code: Select all

#include "CryAction.h"

Re: How to access GameTokens in C++ ?

Thank you very much fudsine.
The code is inside my game project. I included the CryAction.h but that does not seem to work inside the game project.
But your code for 5.3 works fine for me. Furthermore, I found out, that I need to pass the name of the GameToken's library into the "FindToken()" function aswell.
So I now use your code for 5.3 and instead of FindToken("Test"); I use FindToken("Level.Test");
Now everything works fine. Thank you.

Who is online

Users browsing this forum: No registered users and 2 guests