Page 1 of 1
Extending GameMode-object + getHours() and getMinutes()
Posted: Tue Nov 11, 2014 10:46 pm
by JKos
I noticed something pretty cool, and I hope AH will not "fix" this, but it is possible to extend the GameMode-object with properties and methods AND IT IS SAVE GAME COMPATIBLE. Tested it a couple of times because I didn't believe it at first

. So I added a couple of useful methods to my GameMode-object which probably are useful for many of you.
Just copy paste this to any script entity
Code: Select all
GameMode.getHours = function()
local hour = math.floor(GameMode.getTimeOfDay()/(2/24))+6 -- add 6 hours because 0.0 = 6:00
return hour%24
end
GameMode.getMinutes = function()
return math.floor(GameMode.getTimeOfDay()/(2/24/60)%60)
end
Now you can get Grimrock-time converted to real hours and minutes by calling those methods.
Re: Extending GameMode-object + getHours() and getMinutes()
Posted: Tue Nov 11, 2014 10:51 pm
by cromcrom
Niiiiice, thanks a lot. Introducing Scroll Watch ?
Re: Extending GameMode-object + getHours() and getMinutes()
Posted: Wed Nov 12, 2014 2:47 am
by Batty
Yes, that's a good one, thanks JKos.
Can we create methods with all the objects or just GameMode?
Re: Extending GameMode-object + getHours() and getMinutes()
Posted: Thu Nov 27, 2014 1:56 pm
by cromcrom
Thanks a lot again JKos, using this baby for my sleepiness system, and crediting you oc.
Re: Extending GameMode-object + getHours() and getMinutes()
Posted: Sat Dec 27, 2014 10:25 am
by minmay
Using this as part of a hack, I discovered there is a nasty caveat: when you add a field to GameMode (and probably many other global objects), it stays there even after restarting dungeon preview or loading a different mod. To reset GameMode, you have to go back to the main menu. Which makes sense, but is potentially inconvenient from a scripting perspective.
Re: Extending GameMode-object + getHours() and getMinutes()
Posted: Thu Dec 03, 2015 9:07 am
by minmay
I'm a year late here, but what do you mean by "IT IS SAVE GAME COMPATIBLE"? If you save the game, GameMode's fields don't get saved. If you close Grimrock 2 and load your saved game, any changes you made to GameMode or other global tables will be gone. The objects persist across game sessions but this doesn't mean they are "SAVE GAME COMPATIBLE": those objects simply aren't touched by saving/loading in the first place. Try it yourself, go into some dungeon and set GameMode.asdf = 1, then load some other save game and print GameMode.asdf - you'll get 1. This is the opposite of save game compatible as far as I'm concerned.
Re: Extending GameMode-object + getHours() and getMinutes()
Posted: Fri Dec 04, 2015 10:51 pm
by JKos
Obviously I was mistaken. I didn't know at that time that the game objects do persists inside of a game session, if you don't close the game entirely. So It's NOT SAVE GAME COMPATIBLE, don't use it, put those methods to a some other object instead.
Re: Extending GameMode-object + getHours() and getMinutes()
Posted: Sat Dec 05, 2015 12:09 am
by minmay
Well, it depends on what you're doing. If you wanted to add getHours() and getMinutes() functions for example, you could just do it in your mod's init.lua. That way they'll be added every time the mod is loaded.
I can even think of places where this specific behaviour is useful. For example, maybe you have a huge lookup table. You could make your init.lua store it in one of the global tables if the mod is loaded and it doesn't already exist. Then the game wouldn't have to serialize the huge lookup table, whereas it would have to serialize it if you stored it in a script entity.