Jump to content

Recommended Posts

 I'm trying to make packim's speed change according to the player being on boat or on land but for some reason it doesn't recognize the fishbone as it's leader or I'm doing something wrong (which is the usual case).

function Packim(inst)	if inst.components.follower and (inst.components.follower.leader.components.inventoryitem and inst.components.follower.components.inventoryitem.owner == GetPlayer()) then		if inst.components.follower.leader:HasTag("aquatic") then			inst.components.locomotor.walkspeed = 7 		print("7") else		print("6")			inst.components.locomotor.walkspeed = 6		end		inst.components.follower.leader:ListenForEvent("mountboat", PackimSpeed) --ignore this for now		inst.components.follower.leader:ListenForEvent("dismountboat", PackimSpeed) --this too	end

the first line of the function is the issue, it says this in the log:

 

attempt to index field 'leader' (a nil value)

 

 

Any help?

@Cyde042 Check if inst.components.follower.leader is valid before trying to access its content.

if inst.components.follower.leader then    -- ...end

or

if inst.components.follower and inst.components.follower.leader    and inst.components.follower.leader.components.inventoryitem and ...

 

@Cyde042 Check if inst.components.follower.leader is valid before trying to access its content.

if inst.components.follower.leader then    -- ...end

or

if inst.components.follower and inst.components.follower.leader    and inst.components.follower.leader.components.inventoryitem and ...

 

It's invalid according to the game... But that doesn't make any sense to me, what is it following then if not the fishbone? There's even this line of code in the fishbone lua

        if packim.components.follower.leader ~= inst then            packim.components.follower:SetLeader(inst)        end

I can't understand what's wrong.

 

@Cyde042 When is the Packim function being called, on creating the prefab? It appears the leader is not set at that time, so it's nill and can't be accessed as a table.

 

 

function Packim(inst)	local function OnStartFollowing(inst)		inst:AddTag("companion")			if inst.components.follower.leader then				print("I have a leader") else print("I don't have a leader")			end			local leader = inst.components.follower.leader 			if inst.components.follower and leader then				if (leader.components.inventoryitem.owner == GetPlayer()) then					PackimSpeed();					inst.components.follower.components.inventoryitem.owner:ListenForEvent("mountboat", PackimSpeed)					inst.components.follower.components.inventoryitem.owner:ListenForEvent("dismountboat", PackimSpeed)				end			end	end	inst:ListenForEvent("startfollowing", OnStartFollowing)end

inst.components.follower.leader.components.inventoryitem.owner is at fault, 2nd components can't be indexed.

 

How can I access the leader's components in this case?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...