Alarm Clock App

Dingo

  • Posts: 15
Is it possible to create an alarm clock app for iOS using iStencyl?  Something that would run in the background?

Play

  • Posts: 165
I don't think so, at least I haven't found a way. For one thing, Stencyl doesn't seem to support actions which are to be carried out while the game is backgrounded. Also, I have asked many times and nobody seems to know how to access the time. Some have said that it would not be that hard to get the time from the phone's clock but I haven't seen anyone accomplish it.

Both of those things are features which I think Stencyl for iOS must support! hint hint to any members of staff which might be reading  :P

psyche

  • *
  • Posts: 236
well, if you set up some text attributes : year, month, day, hour, minute, second
the following code will set them with current date/time :

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateFormat:@"yyyy"];
_year = [dateFormatter stringFromDate:[NSDate date]];

[dateFormatter setDateFormat:@"MM"];
_month = [dateFormatter stringFromDate:[NSDate date]];

[dateFormatter setDateFormat:@"dd"];
_day = [dateFormatter stringFromDate:[NSDate date]];

[dateFormatter setDateFormat:@"HH"];
_hour = [dateFormatter stringFromDate:[NSDate date]];

[dateFormatter setDateFormat:@"mm"];
_minute = [dateFormatter stringFromDate:[NSDate date]];

[dateFormatter setDateFormat:@"ss"];
_second = [dateFormatter stringFromDate:[NSDate date]];

[dateFormatter release];

If you want to have number attributes something like that should work :
_second = [[dateFormatter stringFromDate:[NSDate date]] floatValue]
or you could use the "as number" block

Play

  • Posts: 165
Thank you very much psyche! I'll try that out when I get home. Just to be sure, should that work for iOS specifically? I have seen others post code to find the time but it ended up only working for flash.

Edit: It works perfectly! Wooooo

While this may have been a somewhat trivial accomplishment for all I know, to someone like me - a complete amateur with absolutely no coding background - this opens up a word of possibilities. :)

« Last Edit: April 18, 2012, 11:58:36 am by Play »

psyche

  • *
  • Posts: 236
:) glad to be of help

just to answer your question, yes this is for iOS only, it won't work in flash. So, make certain you use it in a "do only in iOS" block if you are to publish it in flash too.

For flash there are some good behaviours you can find in stencylforge, Date n' Time is one.

Play

  • Posts: 165
Sorry to be a nuisance, but this code crashes my game during the fade-in part of scene transitions. I can't figure out any way to avoid the crash other than to turn the clock off and was wondering if you knew how.

Edit: I fixed the crashing by making sure to turn off the clock event prior to switching/reloading the scene. Also, the clock cannot be triggered automatically when a scene loads -- without a small delay it still crashes. I also had to make sure that the code was placed in the same behavior as the trigger to switch/reload the scene.

Edit 2: Eh... this fix seems to only be working some of the time. Any suggestions to make it work better would be greatly appreciated.

« Last Edit: April 22, 2012, 10:43:20 pm by Play »

psyche

  • *
  • Posts: 236
 :-\
Well... it doesn't crash in my tests.
Can you post some screenshot of how you're using it?
It could be related to how you are trying to use those values.

Play

  • Posts: 165
Here is how I'm using:

In a scene behavior, I have it set to begin getting and displaying the time 3 seconds after the scene is created, then stop getting and displaying the time 3 seconds before the scene fades out.

It works as intended until I try to reload the scene. Then the game crashes and Xcode shows me that last attachment.


psyche

  • *
  • Posts: 236
My guess would be that you are trying to access an actor property (x=center of player, y-center of player) when the actor does not exist.

Depending on when the [if...] statement gets executed during reload (before or after the actor has been initialised) the game crashes or not.

Apart from that, generally it is a waste of resources to update the clock at every frame, when your clock resolution is seconds.

Try to put the set "Total Time to" calculation (along with the clock code) inside a "do every 1 second" block inside a "when created" event.

I can tell you for sure that the clock code has nothing to do with scene transitions.
[oh, and given that year, month, day, etc are text attributes, I don't think you need the "as text" conversion]

Play

  • Posts: 165
I took your advice and changed things around to match your suggestions but I'm still having the same problem; it doesn't seem like the issue is trying to access the actor because the scene will reload if I merely deactivate the code. I will try working with this code in other ways as I'm sure there's something I mixed up and am overlooking that is causing this issue. Thanks for all the help!

psyche

  • *
  • Posts: 236
try to encapsulate the "if x-center etc" inside an
if scene not transitioning
         if player has value and player is alive

[if you try to access actor or scene attributes elsewhere as well, might be good to do the above for all such occasions]

BAD_ACCESS means you are trying to access soemthing that is not there.
That this is happening on a scene transition, is a strong indication that it has to do either with an actor (that is killed and re-created) or the scene (which is destroyed and recreated).

« Last Edit: April 23, 2012, 12:04:18 am by psyche »

Play

  • Posts: 165
Hey psyche,

I've tried everything possible you've said, I've even completely taken off the conditional check for if the player is on the screen or not. I have an actor which merely checks the time every 1 second in all circumstances, yet the game still crashes whenever I reload the scene. It seems to be trying to access the time variables when the actor or scene doesn't exist, although I really don't know for sure.

Would you mind posting a simple example of how you use it? I will to just copy your method exactly.

Edit: I got it to work for me! I switched the code around to look more like the code for a typical setter. I'm not exactly sure what the difference is, but with this change my game no longer crashes during scene transitions.

Code: [Select]
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateFormat:@"yyyy"];
tempHolder = _year;_year = [dateFormatter stringFromDate:[NSDate date]];
[_year retain];
[tempHolder release];

[dateFormatter setDateFormat:@"MM"];
tempHolder = _month;_month = [dateFormatter stringFromDate:[NSDate date]];
[_month retain];
[tempHolder release];

[dateFormatter setDateFormat:@"dd"];
tempHolder = _day;_day = [dateFormatter stringFromDate:[NSDate date]];
[_day retain];
[tempHolder release];

[dateFormatter setDateFormat:@"HH"];
tempHolder = _hour;_hour = [dateFormatter stringFromDate:[NSDate date]];
[_hour retain];
[tempHolder release];

[dateFormatter setDateFormat:@"mm"];
tempHolder = _minute;_minute = [dateFormatter stringFromDate:[NSDate date]];
[_minute retain];
[tempHolder release];

[dateFormatter setDateFormat:@"ss"];
tempHolder = _second;_second = [dateFormatter stringFromDate:[NSDate date]];
[_second retain];
[tempHolder release];

[dateFormatter release];

« Last Edit: April 25, 2012, 06:38:37 pm by Play »

psyche

  • *
  • Posts: 236
I don't do anything special, in a when created block a i have a "do every 1 second" with the code block you have.

In the beginning you said the code was part of a scene behaviour, and now that an actor checks that periodically. Maybe there is the problem? At some point the actor exists and tries to access the behaviours variables that have been destroyed? Maybe using global variables would have a difference?

Beats me really... But if you got it working, you got it working :p

« Last Edit: April 25, 2012, 10:06:52 pm by psyche »

Play

  • Posts: 165
I was going to try global variables but I couldn't figure out how to edit the code for that so I did this:

tempHolder = _time;_time = [dateFormatter stringFromDate:[NSDate date]];
[_time retain];
[tempHolder release];

The tempHolder and retain thing kept it from trying to access the time variables when the scene or actor (I tried it in both) was dead. If you haven't tried yet you might want to test scene transitions and see if you don't have the same issue I had.

psyche

  • *
  • Posts: 236
i've tried it in a scene behaviour, and didn't have any crashes with transitions...