Cyde042 Posted December 21, 2015 Share Posted December 21, 2015 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 endthe first line of the function is the issue, it says this in the log: attempt to index field 'leader' (a nil value) Any help? Link to comment https://forums.kleientertainment.com/forums/topic/61142-packim-doesnt-have-a-leader/ Share on other sites More sharing options...
Blueberrys Posted December 21, 2015 Share Posted December 21, 2015 @Cyde042 Check if inst.components.follower.leader is valid before trying to access its content.if inst.components.follower.leader then -- ...endorif inst.components.follower and inst.components.follower.leader and inst.components.follower.leader.components.inventoryitem and ... Link to comment https://forums.kleientertainment.com/forums/topic/61142-packim-doesnt-have-a-leader/#findComment-700238 Share on other sites More sharing options...
Cyde042 Posted December 22, 2015 Author Share Posted December 22, 2015 @Cyde042 Check if inst.components.follower.leader is valid before trying to access its content.if inst.components.follower.leader then -- ...endorif 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) endI can't understand what's wrong. Link to comment https://forums.kleientertainment.com/forums/topic/61142-packim-doesnt-have-a-leader/#findComment-700553 Share on other sites More sharing options...
Blueberrys Posted December 22, 2015 Share Posted December 22, 2015 @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. Link to comment https://forums.kleientertainment.com/forums/topic/61142-packim-doesnt-have-a-leader/#findComment-700810 Share on other sites More sharing options...
Cyde042 Posted December 25, 2015 Author Share Posted December 25, 2015 @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)endinst.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? Link to comment https://forums.kleientertainment.com/forums/topic/61142-packim-doesnt-have-a-leader/#findComment-701963 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now