Jump to content

Need help with custom action


Recommended Posts

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 have

DRESSUP.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  endend

In 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)  end

Now 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

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 parameters

act.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 that

act.target:ChangeHat(act.invobject)

or

act.target.ChangeHat(act.target, act.invobject)
Link to comment
Share on other sites

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
 Share

×
  • Create New...