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!
Quick Reply
Search this Thread
Test Subject
Original Poster
#1 Old 15th Jul 2023 at 6:55 PM
Default Struggling with alarm in run() method
Hi everyone, as the title says, I am currently struggling with adding an alarm in my run() method. (That will also be persistable.)

What I am trying to do is when I click on an interaction, that it will launch a timer of 6 hours (kind of like the dryer) and when the timer is finished, I would like it so the state of my object change to "done".
That way, in another interaction, my test method will detect the change of state of the object and return true.

I think I get how to achieve this code, but I'm really stuck with the alarm...

Thanks for your help,

P16
Advertisement
Forum Resident
#2 Old 17th Jul 2023 at 8:28 PM
I dont know exactly what you are doing, so for illustration purposes let's assume you have created a scripted game object named CustomDryer to your game and the custom Dryer has a custom interaction added to it.

In the CustomDryer class you would add a method like


// in the scripted object class
public void OnTimerFinished()
{
// beep beep i'm done
}

To trigger the method with a delay from your interaction's run() method write something like...

(my assumption is that we are talking about a Sim/Gameobject interaction where Actor is the Sim and Target is of type GameObject or type CustomDryer.)

// in the interaction's run() method
CustomDryer dryer = Target as CustomDryer;
dryer.AddAlarm(6f, TimeUnit.Hours, new AlarmTimerCallback(dryer.OnTimerFinished), "blah", AlarmType.AlwaysPersisted);

Find my Mods: Here at MTS, over at Simlogical
Test Subject
Original Poster
#3 Old 19th Jul 2023 at 6:47 PM
Well you guess just right!
That was exactly what I tried to do and was struggling for days with the alarm that wasn't work...

Well I saw that at least I was close, but was missing the object reference for the alarm and I put the callback in the interaction class instead of the object class...

Again, thanks a lot @Consort for helping me with my script!

P16
Back to top