Jump to content

Character Transformation Coding Issue


Recommended Posts

Hia… So I'm working on this character that will be able to take on a different form much like Woodie can, and I'm pretty new to modding and coding... I've been doing what I can, but when I fire up the game, everything works for a few seconds before I get a "Warning!" screen, that states that the variable "V" can't be defined. I'm unsure how to fix this. Help please? I'll include the modmain file in this just in case.

Here's the chunk of code that I think is the issue: 

-- Special abilities.
local function OnKeyPressed(inst, data)
  if data.inst == ThePlayer then
    if data.key == V then -- You can change LEFTBRACKET to something like A or Z or B ect.
      if TheWorld.ismastersim then
      BufferedAction(inst, inst, ACTIONS.TRANSFORM):Do()
      else
      SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.TRANSFORM.code, inst, ACTIONS.TRANSFORM.mod_name)
      end
      elseif data.key == R then
      if TheWorld.ismastersim then
      BufferedAction(inst, inst, ACTIONS.TRANSFORMBACK):Do()
      else
      SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.TRANSFORMBACK.code, inst, ACTIONS.TRANSFORMBACK.mod_name)
      end
    end
  end
end

modmain.lua

Link to comment
Share on other sites

Although I have never done keypresses, there is a strong difference between

V and "V"

The former references a variable labeled V that must exist within the scope available to the code. The latter is a string of V which is a type of data.

I am guessing you might need to make them like the latter.

If that doesn't work

There are quite a few mods in the workshop that use keypresses so it might be useful to double check the syntax that they are using to see what is working.

Link to comment
Share on other sites

GLOBAL.TheInput:AddKeyUpHandler(
    GLOBAL.KEY_V,
    function()
        -- Do work
    end
)

Though I'd recommend looking into letting the user customize the hotkey as well.

As for using two keys to go into and then go out of the state, I'd again recommend using just one key to toggle the state back and forth.

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