party:onTurn

Are you looking for fun Custom Dungeons that you could play or do you want to share your mod with others? Then this forum is for you!
Post Reply
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

party:onTurn

Post 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.
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: party:onTurn

Post 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.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: party:onTurn

Post 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",	
	}
}
Post Reply