How to get ListenToGameEvent to work?

I have the following code in my 'addon_game_mode.lua' file :

function CAddonTemplateGameMode:InitGameMode()
    print( "Template addon is loaded." )
    GameRules:GetGameModeEntity():SetThink( "OnThink", self, "GlobalThink", 2 )
    ListenToGameEvent("dota_inventory_item_changed", Dynamic_Wrap(CAddonTemplateGameMode, 'InventoryChange'), self)
end

And elsewhere in the same file :

function CAddonTemplateGameMode:InventoryChange(keys)

[rest of code here]

The rest of the code inside of InventoryChange does not matter, since it appears the interior of the InventoryChange function is not ever accessed.

I have tried the 'dota_inventory_changed' game event as well, which did not appear to work either.

What am I doing wrong? I cannot seem to find any tutorials on global events.

Comments

  • Posts: 858

    dota_inventory_changed is a clientside event

    MAKE CUSTOM GAMES GREAT AGAIN

    Finished-
    kv checker - https://arhowk.github.io
    panorama video series - https://moddota.com/forums/discussion/2021/inclusive-panorama-tutorial-quest-box

    My pet project This Cursed World/Crestfallen (name pending)
    https://moddota.com/forums/discussion/986/this-cursed-world-rpg#latest

  • @Arhowk

    I greatly appreciate you helping me again and again, but I think you overestimate my familiarity with lua, the dota tools, and modding in general. I have no idea what to do with the information you just gave me, and although I am sure it would be rather simple once I figure it out, I also suspect that it will take me quite a while to find 1) what I am doing wrong in relation to client-side events and 2) what to change of what I have to make it client-side-event-friendly or 3) if I need to use clientside at all, or if it being clientside is a bad thing.

    Compounding this issue is the fact that I cannot seem to find any tutorials on this topic; for most of the other things I have asked about on this forum, someone would point me in the right direction, I think 'wat?', I read the relevant tutorial, and if I still had questions I could ask the specific questions I had, using my results so far to form said questions. With this issue, however, you and others tell me something, I think 'wat?', I search the forum for examples, I find almost nothing, I make a Frankenstein code using what little examples I could find, and it does not work at all so I have nothing to go off of to ask further questions.

    Again, I appreciate you showing up and helping in most posts. I just think that in this scenario, more specific pointers are needed. For example:

    ~ Does whatever code I do for this endeavor go in the addon_game_mode.lua file in the first place? If not, where does it go?

    ~ Do I use ListenToGameEvent at all? Does "dota_inventory_changed is a clientside event" mean that I use something else?

    ~ If I don't use ListenToGameEvent, what do I use? Where would this new thing be put?

    ~ If I do use ListenToGameEvent, do I have it in the right syntax and location?

    ~ Do I call the function correctly, or do clientside events have a different calling syntax?

    Again (again), thank you for your help.

  • Posts: 858

    man I'm not going to go typing an essay every time someone needs help, I just pop on my phone every hour or so between classes.

    clientside event means you need to use GameUI.Subscribe in Panorama code. If it needs to be lua logic just send the data over in a custom game event.

    MAKE CUSTOM GAMES GREAT AGAIN

    Finished-
    kv checker - https://arhowk.github.io
    panorama video series - https://moddota.com/forums/discussion/2021/inclusive-panorama-tutorial-quest-box

    My pet project This Cursed World/Crestfallen (name pending)
    https://moddota.com/forums/discussion/986/this-cursed-world-rpg#latest