Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Virtual gardener
staff: administrator
Original Poster
#1 Old 5th Jul 2021 at 5:03 PM
Default Alarm is being reset despite being repeating and persisted
Heya!

Currently I'm working on a new mod that is heavily dependant on alarms. It's not the first time I've had to work with alarms but every time I work with them it's just a PITA to do :p

Currently I'm applying 2 alarms on a gameObject. Now, I've done this in the past and this would always stick around, except for this time, where after a few hours in, it works and then after those hours have passed, it's not being called anymore.

Code:
        public override void OnCreation()
        {
            mShouldIMoveAlarm = base.AddAlarmRepeating(0f, TimeUnit.Hours, ShouldIMove, 1f, TimeUnit.Hours, "Should_I_Move_" + this.ObjectId, AlarmType.AlwaysPersisted);
            mNeedsAlarm = base.AddAlarmRepeating(0f, TimeUnit.Hours, UpdateSheepNeeds, 1f, TimeUnit.Hours, "Update_Sheep_needs_" + this.ObjectId, AlarmType.AlwaysPersisted);

            base.OnCreation();
        }


I'm personally out of ideas, since it's not the function, it's literally that it's not repeating it anymore
Advertisement
Forum Resident
#2 Old 5th Jul 2021 at 7:49 PM
I don't know what exactly it does, but I always wrap the actual method in an AlarmTimerCallback like so:

mNeedsAlarm = base.AddAlarmRepeating(0f, TimeUnit.Hours, new AlarmTimerCallback(UpdateSheepNeeds), 1f, TimeUnit.Hours, "Update_Sheep_needs_" + this.ObjectId, AlarmType.AlwaysPersisted);

maybe it helps.

You can also try to wrap the method in a try/catch with no throw. If it throws a null exception or something the AlarmManager will not call it again.

Find my Mods: Here at MTS, over at Simlogical
Virtual gardener
staff: administrator
Original Poster
#3 Old 6th Jul 2021 at 10:37 AM
Quote: Originally posted by Consort
I don't know what exactly it does, but I always wrap the actual method in an AlarmTimerCallback like so:

mNeedsAlarm = base.AddAlarmRepeating(0f, TimeUnit.Hours, new AlarmTimerCallback(UpdateSheepNeeds), 1f, TimeUnit.Hours, "Update_Sheep_needs_" + this.ObjectId, AlarmType.AlwaysPersisted);

maybe it helps.

You can also try to wrap the method in a try/catch with no throw. If it throws a null exception or something the AlarmManager will not call it again.


Thanks for the reply!

Yeah, it was actually the fact that the function linked to it, when it reaches the 'else' I got in place, it will stop running since there's a null reference, so I should have tried it with a try/catch to begin with. :p
Back to top