Page 1 of 1

party:onTurn

Posted: Mon Jan 25, 2021 9:50 pm
by RayB
I am trying to get the party:onTurn component to work.

I created the following test code and placed it as a script in the dungeon editor...

function pmove()
party.party:addConnector("onMove", self.go.id, "move")
party.party:addConnector("onTurn", self.go.id, "pturn")
end

function move(self,dir)
print(self.go.name .. " move",dir)
end
function pturn(self,dir)
print(self.go.name .. " move",dir)
end

pmove()

The onMove connector works fine. I have tried onRest and onWakeUp also and they all work but I cannot get the onTurn commector to work and I am wondering why.

Re: party:onTurn

Posted: Mon Jan 25, 2021 10:55 pm
by minmay
onTurn only triggers if the hook is registered. You have to put an onTurn hook in your PartyComponent definition. Then you'll be able to use connectors from it.

Re: party:onTurn

Posted: Tue Jan 26, 2021 12:09 am
by Isaac
Also... The hooks allow for canceling the [attempted] action before it happens, but not when called via connectors.
To have them able to cancel a movement, the hook(s) must return false. To do this the hook must be defined in the definition.

One way to do this —while using functions within a script_entity— is to call those functions directly from within the defined hooks, and return what [boolean] values they give.

This allows you to return true or false from the script_entity functions, thus allowing you to approve or cancel the attempted actions—if wanted.

Example:

Code: Select all

defineObject{
	class = "party",
	components = {
		{
			class = "Party",
			onMove = function(self, dir)
				return my_script_entity_1.script:pmove(self,dir) 
			end,
			onTurn = function(self, dir)
				return my_script_entity_1.script:pturn(self,dir)      
			end,
			--Where both pturn and pmove may now return True or False to either allow or cancel the movement action.
		},
		{
			class = "Light",
			name = "torch",
			range = 12,
		},
	},
	editorIcon = 32,
	placement = "floor",	
	}
}