Retrieving Object Parameter Values

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!
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Retrieving Object Parameter Values

Post by NutJob »

How do I get component parameter states/values?

Ex. I can turn on [an already shut off] lantern with a lever with this code:

Code: Select all

dungeon_wall_lantern_1.light:enable()
But I need to write a conditional to turn it back off with that same lever, so I need to check it's state. I can't figure out the function to retrieve that information.

Is there universal function that I can test the state (retrieve it's value) of anything within an object?

I must be overlooking something extremely simple.
Last edited by NutJob on Tue Oct 21, 2014 7:43 pm, edited 1 time in total.
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: Object Parameters

Post by SnowyOwl47 »

NutJob wrote:How do I get component parameter states/values?

Ex. I can turn on [an already shut off] lantern with a lever with this code:

Code: Select all

dungeon_wall_lantern_1.light:enable()
But I need to write a conditional to turn it back off with that same lever, so I need to check it's state. I can't figure out the function to retrieve that information.

Is there universal function that I can test the state (retrieve it's value) of anything within an object?

I must be overlooking something extremely simple.

Code: Select all

if dungeon_wall_lantern_1.light:enable() == enable then
else if dungeon_wall_lantern_1.light:disable() == disable then
end
That should do it
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Object Parameters

Post by NutJob »

SnowyOwl47 wrote:

Code: Select all

if dungeon_wall_lantern_1.light:enable() == enable then
else if dungeon_wall_lantern_1.light:disable() == disable then
end
That should do it
Not too sure why that would work but once I get back I'll give it a shot. Thanks.


--
Edit
Would be nice if there was something like:

Code: Select all

v = object_name_x.some_componant:getEnabled()
or

Code: Select all

v = object_name_x.some_componant:getState()
or, even

Code: Select all

v = object_name_x.some_componant;
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: Object Parameters

Post by SnowyOwl47 »

NutJob wrote:
SnowyOwl47 wrote:

Code: Select all

if dungeon_wall_lantern_1.light:enable() == enable then
else if dungeon_wall_lantern_1.light:disable() == disable then
end
That should do it
Not too sure why that would work but once I get back I'll give it a shot. Thanks.


--
Edit
Would be nice if there was something like:

Code: Select all

v = object_name_x.some_componant:getEnabled()
or

Code: Select all

v = object_name_x.some_componant:getState()
or, even

Code: Select all

v = object_name_x.some_componant;
I'm actually working on that, in a script_entity I have that copy paste on Basic Scripting that is called easy commands I'm working on adding a ton of new code for just fiscally getting if something is enabled or not :D
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Retrieving Object Parameter Values

Post by NutJob »

found the method call, it's:

Code: Select all

v = dungeon_wall_lantern_1.light:isEnabled()
Will return true or false.

Wow, that only took about 50 guesses. heh
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Retrieving Object Parameter Values

Post by NutJob »

Instead of making a new thread I'll bump this one with a slightly related question. So many questions! ha!

I've set up a Lever, a Button, and a Floor Trigger and they all connect to one script_entity and call this function:

Code: Select all

function sayAmsg()
	hudPrint(self.id)
end
So, my question is "How do I get the object calling my function?"

With the code above I expected "Lever_3" in hopes of being able to use the "calling" object properties to progress some other code.
User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

Re: Retrieving Object Parameter Values

Post by AdrTru »

Code: Select all

function sayAmsg(entity)
   hudPrint(entity.go.id)
end
All connectors send function(self).
( "self" isnt visible in editor during making connector )
My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Retrieving Object Parameter Values

Post by NutJob »

AdrTru wrote:

Code: Select all

function sayAmsg(entity)
   hudPrint(entity.go.id)
end
All connectors send function(self).
( "self" isnt visible in editor during making connector )
I use it in JavaScript I write, always. In that language it'll return the element and all it's properties that made the method call. I expected this would behave the same, but I'm not getting the results back due to [????].

So I just put a scalar into the function header? "entity" then I can use the properties from the object making the call?
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: Retrieving Object Parameter Values

Post by SnowyOwl47 »

NutJob wrote:
AdrTru wrote:

Code: Select all

function sayAmsg(entity)
   hudPrint(entity.go.id)
end
All connectors send function(self).
( "self" isnt visible in editor during making connector )
I use it in JavaScript I write, always. In that language it'll return the element and all it's properties that made the method call. I expected this would behave the same, but I'm not getting the results back due to [????].

So I just put a scalar into the function header? "entity" then I can use the properties from the object making the call?
This is lua not javascript and another thing, well what are you trying to get with the hudPrint?
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Retrieving Object Parameter Values

Post by NutJob »

SnowyOwl47 wrote:This is lua not javascript and another thing, well what are you trying to get with the hudPrint?
This.
NutJob wrote:
I've set up a Lever, a Button, and a Floor Trigger and they all connect to one script_entity and call this function:

Code: Select all

function sayAmsg()
	hudPrint(self.id)
end
So, my question is "How do I get the object calling my function?"

With the code above I expected "Lever_3" in hopes of being able to use the "calling" object properties to progress some other code.
Post Reply