Hook similar to "Initialize" where functions I have in my file will work
4 replies, posted
Hello. In a gamemode I'm working on, I'm trying to call a function as soon as the game starts. But the problem I'm running into is that there aren't any hooks I know of that run at the beginning of the game and allow you to call functions that you have in your file in them; for example
[code]function GM:Initialize()
GAMEMODE:StartRound()
end[/code]
or GM:InitPostEntity, and for that matter GM:PostGamemodeLoaded too give me this error, even though the function exists:
[code]
[ERROR] addons/war_gamemode/gamemodes/war/gamemode/init.lua:4: attempt to call method 'StartRound' (a nil value)
1. unknown - addons/war_gamemode/gamemodes/war/gamemode/init.lua:4
Couldn't Load Init Script: 'war/gamemode/init.lua'
[/code]
Is there any "beginning of the game" hook in which I can call functions I have in my file in?
Initialize is called after everything is loaded, are you sure you are calling it in the right realm? It might also be because you are using GAMEMODE instead of self.
[QUOTE=James xX;48044387]Initialize is called after everything is loaded, are you sure you are calling it in the right realm? It might also be because you are using GAMEMODE instead of self.[/QUOTE]
You can use self in initialize hooks? Oh. Let me try that...
only if you define it as
[lua]function GM:Initialize() ... end[/lua]
Why are you calling GAMEMODE:StartRound() when GAMEMODE is simply an alias for GM, since GM cannot be accessed after the necessary files have loaded. At the point Initialize is called, I'm not sure that the GAMEMODE alias/table exists yet.
Sorry, you need to Log In to post a reply to this thread.