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
Lab Assistant
Original Poster
#1 Old 12th Jul 2015 at 9:34 AM Last edited by sachamagne : 16th Jul 2015 at 4:17 AM.
[FIXED] calling function every xx hours issue
Hi again...

I tried to call a function every xx hours and so far it failed. I know the function works and got no errors in logs.
Activating code:
Code:
 ts = services.time_service()
	span = interval_in_sim_hours(1)
	alarm_hour= ts.sim_now.hour()
	time=create_date_and_time(hours=alarm_hour)
	time=ts.sim_timeline.now + span
	write_debug_log('time={} , span {}'.format(time,span))
	AlarmHandle(StartMod, DoJob, ts.sim_timeline,time, repeating=True, repeat_interval=span, accurate_repeat=True)

Debug:
Code:
       [07/12/15 10:24:57]<DEBUG>time=02:18:57.280 day:1 week:2 , span 1.00 hours
       [07/12/15 10:24:57]<DEBUG>next call:02:18:57.280 day:1 week:2



What am i doing wrong ?
Thanks for your explanation !
Advertisement
Mad Poster
#2 Old 15th Jul 2015 at 11:48 PM
Quote: Originally posted by sachamagne
Hi again...

I tried to call a function every xx hours and so far it failed. I know the function works and got no errors in logs.
Activating code:
Code:
 ts = services.time_service()
span = interval_in_sim_hours(1)
alarm_hour= ts.sim_now.hour()
time=create_date_and_time(hours=alarm_hour)
time=ts.sim_timeline.now + span
write_debug_log('time={} , span {}'.format(time,span))
AlarmHandle(StartMod, DoJob, ts.sim_timeline,time, repeating=True, repeat_interval=span, accurate_repeat=True)

Debug:
Code:

[07/12/15 10:24:57]<DEBUG>time=02:18:57.280 day:1 week:2 , span 1.00 hours
[07/12/15 10:24:57]<DEBUG>next call:02:18:57.280 day:1 week:2



What am i doing wrong ?
Thanks for your explanation !

I believe you want to create a global variable to store your alarm handle and then use the sims4.reload.protected member to store the global between game reloads (screen switches). If the handle goes away, so does your alarm and the way you have it defined above, the handle will disappear.
Code:
with sims4.reload.protected(globals()):
    SCHEDULED_ALARM = None

Code:
        global SCHEDULED_ALARM
        ts = services.time_service()
	span = interval_in_sim_hours(1)
	alarm_hour= ts.sim_now.hour()
	time=create_date_and_time(hours=alarm_hour)
	time=ts.sim_timeline.now + span
	write_debug_log('time={} , span {}'.format(time,span))
	SCHEDULED_ALARM = AlarmHandle(StartMod, DoJob, ts.sim_timeline,time, repeating=True, repeat_interval=span, accurate_repeat=True)
Lab Assistant
Original Poster
#3 Old 16th Jul 2015 at 4:17 AM
I had a long 'talk' with a guru about that one. Short answers: Don't use AlarmHandle but add_alarm.

I link the thread for reference:

see: http://forums.thesims.com/en_US/dis...ly-alarmhandlde

Thanks all for your answers !
Back to top