RedHairedHero Posted May 22, 2018 Share Posted May 22, 2018 (edited) Hello, It's always these easy things that I struggle with. So what I'm looking to do is to create a counter. While the player is moving the counter will increase by 1 each second. Once the counter has reached 800, perform a function. If the player is not moving, the counter will not increase. I think the main issue I'm running into is figuring out how to pass the count variable into the counter. Example local function counter(inst) if inst.sg:HasStateTag("moving") then count = count + 1 end end local master_postinit = function(inst) local count = 0 return inst end Any help out would be appreciated. Thanks, Nathan Edited May 22, 2018 by RedHairedHero Link to comment Share on other sites More sharing options...
. . . Posted May 22, 2018 Share Posted May 22, 2018 maybe something like this work? local function counter(inst) if inst.sg:HasStateTag("moving") then inst.count = inst.count + 1 end end local master_postinit = function(inst) inst.count = 0 end Link to comment Share on other sites More sharing options...
RedHairedHero Posted May 22, 2018 Author Share Posted May 22, 2018 15 minutes ago, SuperDavid said: maybe something like this work? local function counter(inst) if inst.sg:HasStateTag("moving") then inst.count = inst.count + 1 end end local master_postinit = function(inst) inst.count = 0 end This will work, had to move some things so here's the end result. local function counter(inst) inst = ThePlayer inst.count = inst.count + 1 return inst.count end local function moving(inst) if inst.sg:HasStateTag("moving") then counter() end end local master_postinit = function(inst) inst.count = 0 end Link to comment Share on other sites More sharing options...
Kronas Posted June 2, 2018 Share Posted June 2, 2018 On 5/22/2018 at 4:25 AM, RedHairedHero said: This will work, had to move some things so here's the end result. local function counter(inst) inst = ThePlayer inst.count = inst.count + 1 return inst.count end local function moving(inst) if inst.sg:HasStateTag("moving") then counter() end end local master_postinit = function(inst) inst.count = 0 end i'm curious about this what is it about ? what does the count defines 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