Jump to content

[solved] Two characters share the same variable (how to stop?)

Recommended Posts

local MyComp = Class(function(self, inst)
    self.inst = inst
    self.myvariable = nil
    -- you can add as many vairables you like to

function MyComp:OnSave()
    local data = {}
    data.myvariable = self.myvariable -- save variable
    return data

function MyComp:OnLoad(data)
    if data.myvariable ~= nil then
        self.myvariable = data.myvariable -- load my variable

return MyComp

put this into a script in your mod folder scripts/components. Of course you can rename "MyComp" and "myvariable" to whatever you prefer, but the name of the file should be the same name like you chose for "MyComp"but in lower letters.
And in your characterfile you make "inst:AddComponent("MyComp")" where you also added other components (I guess it is in master_postinit.

Now whenever you change the value for your character change it with:
inst.components.mycomp.myvariable = x

Edited by Serpens
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

  • Create New...