GUI access from map script

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
cthoennes
Posts: 13
Joined: 2012-08-30, 19:26

GUI access from map script

Post by cthoennes » 2012-11-20, 09:20

Hello,

I would like to display a GUI from my map script, i.E. if the player enters a certain trigger volume, display a text on the screen (A tutorial mode). In the docs, there is the "gui" object, but it seems to be accessible only from the cgui files. Do I really need to write/build a whole new GUI just for displaying text on the screen?
And if so, how do I display it ingame? Not on an object like a terminal or so, but rather on an area on the screen itself. To point that out (Pseodo code):

Code: Select all

tutorialTrigger:OnTrigger()
tutorialTrigger:Deactivate();
show_text_on_screen("Press [Spacebar] to jump"); // maybe even with a nice looking image?
wait(5):
hide_text();
tutorialTrigger:Activate();
end
Thanks for the help and the Deactivate/Activate example in "TechDemo" - it really helped me when triggering a speaker (kept repeating the first second or so until I did it like that).
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: GUI access from map script

Post by Carsten » 2012-11-20, 22:32

Hi cthoennes,

as a basis, please consider this example of a trigger handler:

Code: Select all

function TestTrigger:OnTrigger(Activator)
    -- Choose the variant of logic you want to test.
    local variant=0;

    -- ...
    Console.Print(Activator:GetName());
end
Note that Activator is typically the human player entity -- which also happens to hold the HUD GUI in which you could display your text!

That is, you could write e.g.

Code: Select all

function TestTrigger:OnTrigger(Activator)
    -- deactivation and re-activation omitted...

    Activator:ShowHelpText("Press Spacebar to jump");
    wait()
    Activator:ShowHelpText("");   -- or simply (nil), or ()
end
All that you have to implement is the ShowHelpText() script function in the human player entity. It could, for example, find a predefined, but initially hidden window in the HUD GUI, and if the given string is non-empty, set the string as the window text and show the window. Vice versa when the string is empty (or not given at all).

Alternatively, if you have a recent release of the source code, you can also make the HUD GUI "poll" the human player entity for a string to be shown (which would require another script method, e.g. GetHelpText() in the human player. The result will be the same, but the logic of showing or hiding the window with your text is in the HUD rather than in the human player entity code.

Does that help?
Please let me know if you need help with e.g. the ShowHelpText() script function. :up:

(As a completely different alternative, it would also possible to (mis-)use the chat system for issuing a message, but you'd have much less control over the details, and would not be able to e.g. add a custom image etc.)
Best regards,
Carsten
cthoennes
Posts: 13
Joined: 2012-08-30, 19:26

Re: GUI access from map script

Post by cthoennes » 2012-12-29, 02:33

So, I modified HumanPlayer.cpp, inserted a method named drawHelpText with a text parameter into it and recompiled the source code with scons (Former CPP programmer's perk 8) Must have been of use for something)
Now, after all, if I call it from the map script using "Activator:drawHelpText("Press Spacebar to Jump")", the engine tells me that this method is not known...
Well, of course it isn't... I coded it into the C++ source, recompiled all of it into a (hopefully) nice looking, beautiful and tidy *.obj file.
But how exactly can I point the engine onto that function so it can be called from the map script? It sure is that famous (or infamous) last button to push... But I can't find it. Could sb help me?
Thanks in advance!
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: GUI access from map script

Post by Carsten » 2012-12-29, 11:29

cthoennes wrote:But how exactly can I point the engine onto that function so it can be called from the map script? It sure is that famous (or infamous) last button to push... But I can't find it. Could sb help me?
Thanks in advance!
Did you add the new script method to the

Code: Select all

const luaL_Reg EntHumanPlayerT::MethodsList[] = ...
list near the top of HumanPlayer.cpp?
Best regards,
Carsten
cthoennes
Posts: 13
Joined: 2012-08-30, 19:26

Re: GUI access from map script

Post by cthoennes » 2012-12-29, 16:06

OK, it partially works now. It compiles, but doesn't link, after I changed the string to char*, made the function int and static and removed all parameters from it:
Infected.lib(HumanPlayer.obj) : error LNK2019: Verweis auf nicht aufgelöstes ext
ernes Symbol ""public: static char * Infected::EntHumanPlayerT::toDraw" (?toDraw
@EntHumanPlayerT@Infected@@2PEADEA)" in Funktion ""private: static int __cdecl I
nfected::EntHumanPlayerT::drawHelpText(struct lua_State *)" (?drawHelpText@EntHu
manPlayerT@Infected@@CAHPEAUlua_State@@@Z)".
build\win32\vc10\amd64\release\Ca3DE\Cafu.exe : fatal error LNK1120: 1 nicht auf
gelöste externe Verweise.
scons: *** [build\win32\vc10\amd64\release\Ca3DE\Cafu.exe] Error 1120
scons: building terminated because of errors.

I don't see the problem here, as char is a built in C++ (and C) data type and so are pointers. Also, when using a string, it complains the same way, which is why I decided to use char*. Slowly, I get thinking that Visual C++, or even Microsoft in total sucks...

Could you help me (other than pointing me on that fact?)
Last edited by cthoennes on 2013-01-14, 20:34, edited 1 time in total.
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: GUI access from map script

Post by Carsten » 2012-12-29, 17:04

Uh... the formatting of the message that you pasted is really difficult to read...

But essentially, you can take the error message verbatim:
You have declared a (static?) method toDraw(), and you're calling it, but the compiler never found a definition for it, and thus the linker cannot resolve the reference to it.

This usually happens when the definition of a (especially static) method mismatches the declaration. This is the first item that I'd check.
Slowly, I get thinking that Visual C++, or even Microsoft in total sucks...
Well, I cannot say that. Their compiler has become very good in the past years. The error messages can sometimes be pretty misleading, and it is possible that the solution is not actually obvious from the error message alone, but almost always, the matter is right and it's the own program, not the compiler, that is at fault. :cheesy: :up:
Best regards,
Carsten
cthoennes
Posts: 13
Joined: 2012-08-30, 19:26

Re: GUI access from map script

Post by cthoennes » 2013-01-18, 19:10

Well, that wasn't about the error itself, but rather about the confusing format that the message is - that's how it looked like on the cmd. Sorry, could have formatted it.
Anyway, I found it by looking into the msdn database: toPrint is a static variable, but I haven't defined it. After doing so, everything compiled fine, but when I copy the new cafu.exe and all other files to the main directory, it doesn't run my game. Deathmatch runs fine, but as soon as I want to start a level in it, it crashes ("Has encountered problem and needs to be closed"). The logfile created with the -log parameter doesn't show any error messages.
Anything I did wrong? I already recompiled the level, but that didn't help at all.
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: GUI access from map script

Post by Carsten » 2013-01-19, 10:58

cthoennes wrote:Anything I did wrong?
Well, as I don't know what you did, I cannot tell if you did anything wrong. Can you run (the debug build) of Cafu.exe under debugger control, and inspect the stack trace to learn where and why it halts?
Best regards,
Carsten
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests