Timer?

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
zeltak
Posts: 119
Joined: Fri May 04, 2012 2:33 am

Timer?

Post by zeltak » Mon Oct 27, 2014 5:29 pm

It seems that timer works a little differently than in LoG1. I can't figure out how to use them so that they don't start at the beginning of the game/level.. I tried to use pressure plates so that as pressure plate is activated it starts the timer and when it is deactivated it would stop it. But the timer runs without waiting for the activation? O.o

Is this a bug, or am I missing something?

User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: Timer?

Post by Lark » Mon Oct 27, 2014 6:55 pm

Select the timer, then under "Components" you will see a checkbox in front of "timer". Leave it checked for the timer to start immediately, and uncheck it to disable the timer until explicitly started.

User avatar
zeltak
Posts: 119
Joined: Fri May 04, 2012 2:33 am

Re: Timer?

Post by zeltak » Mon Oct 27, 2014 6:57 pm

Thank you! I knew I was missing something.

User avatar
zeltak
Posts: 119
Joined: Fri May 04, 2012 2:33 am

Re: Timer?

Post by zeltak » Fri Nov 07, 2014 7:26 pm

I'll add my question here, as it got buried in that general thread without an answer. If this has been covered in some tutorial or somewhere else, I would appreciate a nudge to right direction.

What does the "currentLevelOnly" do in timers? It seems that timers pause even without it when you're in a different level. And is there a way to make them tick even when you're not in the same level as the timer?

User avatar
Phitt
Posts: 442
Joined: Tue Aug 14, 2012 9:43 am

Re: Timer?

Post by Phitt » Fri Nov 07, 2014 7:38 pm

zeltak wrote:I'll add my question here, as it got buried in that general thread without an answer. If this has been covered in some tutorial or somewhere else, I would appreciate a nudge to right direction.

What does the "currentLevelOnly" do in timers? It seems that timers pause even without it when you're in a different level. And is there a way to make them tick even when you're not in the same level as the timer?
Timers keep running when the box isn't checked. However they only run in a 1:1 timescale if you are in the same level as the timer. The farther away you are from the timer, the less often it will update. This was done to save performance. If you need accurate timing across levels you can set up a timer in each level that get enabled on entering the level (and disable the previous timer).

User avatar
zeltak
Posts: 119
Joined: Fri May 04, 2012 2:33 am

Re: Timer?

Post by zeltak » Fri Nov 07, 2014 7:45 pm

Alright, thanks. I was trying to figure out a way to accomplish what I wanted. But I didn't think of the easy solution of double timers. Thanks.

User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: Timer?

Post by akroma222 » Fri Nov 14, 2014 2:58 am

The party can be given Counters and Timers as components...
You can create a party timer with this code that will not suffer timescale issues
(I tested it by printing the counter value each second, and then jumping down a bunch of pits)

Place the definition in your init.lua
SpoilerShow

Code: Select all

-----------------------------------------------party timer

defineObject{
       name = "party",
       baseObject = "party",
       components = {
		{
		class = "Counter",
		name = "partycounter",
		},	
          	{
             	class = "Timer",
		name = "partytimer",
		timerInterval = 1.0,
		triggerOnStart = true,
		onActivate = function(self)
			self.go.partycounter:increment()
			local v = self.go.partycounter:getValue()
			return hudPrint("Time = "..v.."")
		end
          	},
	}
    }

User avatar
Komag
Posts: 3637
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Timer?

Post by Komag » Sat Nov 15, 2014 12:21 am

wow, what an easy perfect solution! any downside?
Finished Dungeons - complete mods to play

User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: Timer?

Post by akroma222 » Sat Nov 15, 2014 12:33 am

I have not found anything yet...
But that has me feeling quite suspicious haha :lol:

Going to keep running some more tests today,
I am hoping I can use it as a standardiser for other timers....
or just base timed scripts off the party timer.... hopefully it works as intended!

User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: Timer?

Post by akroma222 » Sat Nov 15, 2014 3:43 am

Ok, I have made a simple script for giving the party water breathing for 60 seconds
and the timing is based from the partytimer
just add a connector from partytimer to oa spawned waterBreathCounter and set onActivate (partytimer) to decrement waterBreathCounter
add a connector from waterBreathCounter to game script and set onActivate (waterBreathCounter ) to activate the clean up (waterBreathStop())script
I tested this out by connecting a pressure plate to the script and then starting the party on the plate square
that way partytimer (or partycounter) should = waterBreathCounter even if we go jumping down pits for a minute
SpoilerShow

Code: Select all

function waterBreath()
	local t = party.partytimer
	local c = findEntity("waterBreathCounter")
	
	if c ~= nil then
		c:destroy()
	end
        t:removeConnector("onActivate", "waterBreathCounter", "decrement")
	spawn("counter",party.level,party.x,party.y,party.elevation,party.facing,"waterBreathCounter")
	waterBreathCounter.counter:setValue(60)
	t:addConnector("onActivate", "waterBreathCounter", "decrement")
	waterBreathCounter.counter:addConnector("onActivate", "game", "waterBreathStop")
    
	playSound("generic_spell")
    for i = 1, 4, 1 do
        if party.party:getChampion(i):isAlive() then
            party.party:getChampion(i):setCondition("water_breathing", 10)
        end
    end
end

function waterBreathStop()
	local t = party.partytimer
	local c = findEntity("waterBreathCounter")
	
	if c then
		c:destroy()
	end
	t:removeConnector("onActivate", "waterBreathCounter", "decrement")
	for i = 1, 4, 1 do
        if party.party:getChampion(i):isAlive() then
            party.party:getChampion(i):removeCondition("water_breathing")
        end
    end
	hudPrint("this works")
end

Post Reply