Ludeon Forums

RimWorld => Mods => Help => Topic started by: eatKenny on December 24, 2014, 09:52:52 AM

Title: a noob c# question, about a tick based loop
Post by: eatKenny on December 24, 2014, 09:52:52 AM
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);
            }
Title: Re: a noob c# question, about a tick based loop
Post by: 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);
            }
Title: Re: a noob c# question, about a tick based loop
Post by: eatKenny on December 24, 2014, 11:36:34 AM
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 ;)
Title: Re: a noob c# question, about a tick based loop
Post by: VapidLinus on December 24, 2014, 11:21:22 PM
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;
}
}