How to get info from a teleporter?

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!
Post Reply
User avatar
mahric
Posts: 192
Joined: Sun Nov 04, 2012 3:05 pm

How to get info from a teleporter?

Post by mahric »

For my mod I need two get two pieces of information from a teleporter:

1) to see if it is active
I can make a teleporter active with the script "teleporter_1.controller:activate()" and deactivate it with "teleporter_1.controller:deactivate()". But I can't seem to find a function that tells me if the teleporter itself is active or not. The controller module has an isEnabled() function, but it returns whether the controller itself is enabled, not the teleporter. Other objects (like the door) have isOpen() and isClosed() functions to query it, but a teleporter doesn't seem to have any such function.

What am I missing?


2) the target location of a teleporter
According to the scripting reference there's a function that returns the target location of a teleporter, but it seems to only return the level, not the x, y and elevation.
Is this a bug, or am I missing something again?


A nudge in the right direction for either problems will help me a lot.

Thanks!
Did you visit the Wine Merchant's Basement? And heard about the Awakening of Taarnab?
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: How to get info from a teleporter?

Post by JKos »

Well if nothing else is working you can always implement your own "controller" like this:

Code: Select all

defineObject{
   name = "teleporter",
   baseObject = "teleporter",
   components = {
		{
			class="Script",
			name="state",
			source = [[
active = false
function isActive()
	return active
end
function activate()
	active = true
	self.go.controller:activate()
end
function deactivate()
	active = false
	self.go.controller:deactivate()
end
]]
		}
	}
}
now you can control your teleporters with state component instead on controller-component

Code: Select all

teleporter_1.state:activate()
teleporter_1.state:deactivate()
teleporter_1.state:isActive()
Edit: This wasn't very good solution, because it doesn't work with connectors, so if you are gonna use this you must control teleporter status by scripting.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: How to get info from a teleporter?

Post by JKos »

Here is a better workaround, which works with connectors too.

Code: Select all

defineObject{
   name = "teleporter",
   baseObject = "teleporter",
   components = {
		{
			class="Controller",
			
			onInitialActivate = function(c)
				c.go.particle:enable()
				c.go.teleporter:enable()
				c.go.light:enable()
				c.go.sound:enable()
			end,
			onActivate = function(c)
				c.go.particle:enable()
				c.go.teleporter:enable()
				c.go.light:enable()
				c.go.sound:enable()
			end,
			onInitialDeactivate = function(c)
				c.go.particle:disable()
				c.go.teleporter:disable()
				c.go.light:disable()
				c.go.sound:disable()
			end,			
			onDeactivate = function(c)
				c.go.particle:disable()
				c.go.teleporter:disable()
				c.go.light:disable()
				c.go.sound:disable()
			end,
			onToggle = function(c)
				if c.go.teleporter:isEnabled() then
					c.go.controller:deactivate()
				else
					c.go.controller:activate()
				end
			end
		}
	}
}
You can check teleport state by calling
teleporter_1.teleporter:isEnabled()

This is a bit hacky, but it seems to be impossible to get the state of the default teleporter. tested teleporter_1.light:isEnabled() etc. nothing worked. I hope that someone figures out a bit easier method than this :)
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
sps999
Posts: 44
Joined: Sun Oct 26, 2014 11:16 pm

Re: How to get info from a teleporter?

Post by sps999 »

If you wanted to get lazy you could make another object that you know you can check, such as a script entity with a variable or even a hidden door or lever. Then any time you activate the teleporter also activate the hidden object and check the object for the status.
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: How to get info from a teleporter?

Post by GoldenShadowGS »

sps999 wrote:If you wanted to get lazy you could make another object that you know you can check, such as a script entity with a variable or even a hidden door or lever. Then any time you activate the teleporter also activate the hidden object and check the object for the status.
Here is an example.

Code: Select all

teleportActive = false

function tele()
if teleportActive == false then
    teleport_1.controller:deactivate()
else
    teleport_1.controller:activate()
end
end
With your other code, just check if teleportActive is true or false and set it accordingly. then run tele() to make the actual teleport entity match the variable.
User avatar
mahric
Posts: 192
Joined: Sun Nov 04, 2012 3:05 pm

Re: How to get info from a teleporter?

Post by mahric »

Thank you all, this will keep the development of my mod in top gear! :)
Did you visit the Wine Merchant's Basement? And heard about the Awakening of Taarnab?
Post Reply