Jump to content

[Solved] Simple Counter


Recommended Posts

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 by RedHairedHero
Link to comment
Share on other sites

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

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

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

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