[LUA] Can't get events to work

Lort Krassbeter

Chieftain
Joined
Mar 8, 2015
Messages
17
Location
Beyond Earth
Hi all,
I have some trouble getting events to work. I am trying to hide/show a UI element when the player opens/closes a city screen using the following code:
Code:
function Show()
	Controls.MyLabel:SetHide(false)
end

function Hide()
	Controls.MyLabel:SetHide(true)
end

function OnEnterCityScreen()
	Hide()
end
Events.SerialEventEnterCityScreen.Add(OnEnterCityScreen);

function OnExitCityScreen()
	Show()
end
Events.SerialEventExitCityScreen.Add(OnExitCityScreen);
When calling the Hide()/Show() methods from Firetuner it works just fine.
So I am wondering if I made a mistake on setting up the events. I've seen some mods use "Events." others use use "GameEvents." or "LuaEvents.". Can you explain the difference between those, if there are any? Do I have to do something else besides registering the function I would like to get called when the event occurs?

Thanks in advance :)
 
Start here: Lua and UI Reference

Note that under the greater "Events" column as shown under "Objects" there are three sub-types of events: Game, GameEvents, and LuaEvents. Each of these has its own specific set of hooks, so if a hook has been pre-assigned to use Game.HookSomethingHook(arg1, arg2) you can't use GameEvents.HookSomethingHook.Add(YourFunctionName) and get it to work properly.

Even though I'm comfortable using a lot of the different hooks available under each of the three types I'm still not sure I have a real clear understanding of why one hook would be a Game instead of a GameEvents. Still just very murky the distinctions, for me: I just do the classic engineer's approach and don't worry my little head too terribly much with the why it works so long as it works. :)
 
Is the file set as an InGameUIAddin? And if so, what, if anything, is in the lua.log file?

(As LeeS said, it doesn't really matter why some are Events, others are GameEvents and a few are LuaEvents, you just need to make sure to use the correct prefix - check existing code - but Events are sent from the game engine (within the .exe file), GameEvents are sent from the game core DLL (the one we have the source for) and LuaEvents are sent from Lua files)
 
Is the file set as an InGameUIAddin? And if so, what, if anything, is in the lua.log file?

(As LeeS said, it doesn't really matter why some are Events, others are GameEvents and a few are LuaEvents, you just need to make sure to use the correct prefix - check existing code - but Events are sent from the game engine (within the .exe file), GameEvents are sent from the game core DLL (the one we have the source for) and LuaEvents are sent from Lua files)
And as always, whoward explains clearly and painlessly the whys of the whats with regard to these three different hook types. :)


Spoiler :
I would have written a 900-page-long dissertation and tutorial, and never managed to get to that clear and simple explanatory paragraph :D
 
Thanks for the reference and explaining what the differences are. I got it to work by just removing the semicolons behind the "Events." lines. Sorry about even asking, I guess I need to abandon my C++ habit in Lua ;)
 
Back
Top Bottom