HomShaBom Posted October 4, 2015 Share Posted October 4, 2015 I'm adding a new "action" in my mod, and I have it working up to the point where I can do the action in-game and it runs my action's "fn", but this is all defined in modmain.lua and I need to call a method that is defined in my prefab file. Here's what I haveDRESSUP.fn = function(act)print("in DRESSUP.fn")print(act.target)print(act.invobject) if act.invobject then act.target:ChangeHat(act.target, act.invobject) act.invobject:Remove() return true endendIn the print messages I can see that act.target is the prefab that I have created in my mod, and the thing that I clicked on to do action. I can also see that act.invobject is the item that I had on my cursor at the time. But when ChangeHat is called (this code exists inside of the function that is creating my prefab)... inst.ChangeHat = function(thetarget, theitem)print("in inst.ChangeHat()")print(thetarget)print(theitem) endNow in the debug messages I see that "thetarget" and "theitem" are the same. Even though i'm passing act.invobject into theitem parameter, the value that it is receiving is act.target instead of act.invobject. What is going on here? Link to comment Share on other sites More sharing options...
ZupaleX Posted October 7, 2015 Share Posted October 7, 2015 I checked really quickly and I may say bullshit but from my fast glance I would say it is due to how you define and call the function :inst.ChangeHat = function(thetarget, theitem)you define here a function with 2 parametersact.target:ChangeHat(act.target, act.invobject)you call here the function but gives 3 parameters, the third one is ignored. Indeed writing act.target:ChangeHat(act.target, act.invobject)is the same as writing act.target.ChangeHat(act.target, act.target, act.invobject)thus the 2 first parameters are the same and the third one is ignored. You should call it like thatact.target:ChangeHat(act.invobject)oract.target.ChangeHat(act.target, act.invobject) Link to comment 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