a noob c# question, about a tick based loop

Started by eatKenny, December 24, 2014, 09:52:52 AM

Previous topic - Next topic

eatKenny

i'm trying to make a tick based loop to simulate smoke from chimney, basically "throw smoke" every second.

i started writing something like this but don't know how make this loop :-\


private int Burnticks = 60;

        public override void Tick()
        {
            base.Tick();
            Burnticks--;
            if (Burnticks == 0)
            {
                   MoteMaker.TryThrowSmoke(base.Position.ToVector3Shifted(), 4f);
            }

Rikiki

You must reset your Burnticks varizblr to 60 when it reaches 0.
public override void Tick()
        {
            base.Tick();
            Burnticks--;
            if (Burnticks == 0)
            {
                   Burnticks = 60;
                   MoteMaker.TryThrowSmoke(base.Position.ToVector3Shifted(), 4f);
            }

eatKenny

Quote from: Rikiki on December 24, 2014, 11:15:44 AM
You must reset your Burnticks varizblr to 60 when it reaches 0.
public override void Tick()
        {
            base.Tick();
            Burnticks--;
            if (Burnticks == 0)
            {
                   Burnticks = 60;
                   MoteMaker.TryThrowSmoke(base.Position.ToVector3Shifted(), 4f);
            }


thanks, learning so much from you ;)

VapidLinus

As a nice C# trick, you can actually shorten this by one line and turn it into this:
public override void Tick()
{
base.Tick();
if (--Burnticks == 0)
{
MoteMaker.TryThrowSmoke(base.Position.ToVector3Shifted(), 4f);
Burnticks = 60;
}
}