My memory game app doesn't seem to work on some computers!

Hi everyone…

Ok, so I made a memory game for my mom on mother’s day… And it plays fine on her computers as well as mine… But now two other people that I have sent it to claim to get applescript errors when they run it… One of them is on tiger 10.4.9, the other is on panther 10.3.9

The error I was told they received was NSCannotCreateScriptCommandError(10)

I am wondering if this is related to the To Rand2 method that I borrowed from someone on this forum for randomizing my image list… I assumed the error was related to this because that section has a “script” command.

Anyway, I have uploaded my entire project if anyone here might have some ideas on what the compatibility issues could be (why would someone on tiger (same as me) be unable to run this??)

http://www.collinatorstudios.com/dev/memorygame.tgz

Of course, as I have limited experience with AS and xcode, I would very much love other feedback on how to do things more efficiently… One question off the top of my head is, when I reveal all images (with the reveal all button), the images appear somewhat slowly-- and I am wondering how would you master programmers do this so that the images appear faster so that you don’t see a left-to-right effect of images displaying?

Thank you in advance.
-patrick

Patrick,

What is likely causing your problems on other machines is that your build style was “Debug”. You need to build in “Release” mode when you are going to distribute the app. Aside from that, I’m having all sorts of errors with your sound files. For some reason, it’s not loading the sounds properly, and every time it tries to play or delete a sound, it errors that the variable is not defined. You may be having a conflict with trying to delete the sound before it’s actually played. I’m unclear why you are even loading and then deleting the sounds every time they are played. They are resources that should be loaded once into memory and reused, not loaded every time they are played. Create a property for each sound, and in the awake from nib or launched handler for the application object, load the sound only once into the persistent variable.

You’ve also got a file (error2.aif) in your project Groups&Files list that has been deleted from the project’s resources folder, so the app won’t compile until I delete the reference, and then delete all lines referencing the file from the script.

As far as your image cascading effect when loading them all at once, you’re running into the same problem as with the sound files. You can’t expect to load dozens of images dynamically into memory without some overhead. Depending on the format and compression of the images being used, you’re loading a lot of data (something applescript’s already poor at), just to flash them on the screen and then delete them all a second later. It’s probably best to load them all into memory when the game begins, and then show and hide the images as necessary. That way the loading part is done before the game ever begins. Also, instead of deleting the image from the image views when the reveal is complete, preload an additional placeholder image instead, and set the image of all of the image views to that image. Deleting the images is unnecessary, and probably has some processing overhead, too.

I think the real message I’d convey to you is that you’re trying too hard to manage all of the data… both the sounds and the images… dynamically. Loading and deleting data like that on the fly is a waste of resources. Simply load all of your images and sounds once into the applications memory, and then come up with code that manages those resources from memory… not from disk. It takes a lot less time to simply display an image or play a file from memory than it does to load it and then display it.

As a note about distribution of development projects, ALWAYS MANUALLY clean your projects before posting them for download. By “manual”, I mean manually go into your project directory, grab the entire contents of the “Build” folder, and trash it. Your project went from 66mb to 17mb by simply throwing away the unnecessary build files. We all have Xcode, and can build it ourselves. Not only is this better for downloading, you should always look at fresh builds of an app when troubleshooting, because problems can often be solved by simply cleaning and rebuilding. If you were to .dmg.zip the resulting folder, it would be significantly smaller still. Another thing I noticed, is that there are seemingly dozens of extra sound and image files in the distribution. Only a small percent of the sound files are actually in use, so why make us download the rest?

Hope this leads you in the right direction to solving some of your issues…
j

First: Thank you very much for the reply, and your time spent looking at my program.

Strange-- I am showing that my build results are set to RELEASE, not debug… Is there somewhere that you are seeing otherwise?

Regarding Error2.aif… I also am at a loss because in my project file (I am looking at it right now), this file is there and I get no errors of it not being there!!! I am completely confused how this didn’t end up being included in my .tgz file.

I understand what you said about images and sounds being loaded and deleted… This was purely from my lack of knowing how to properly display and play these sort of files. I actually looked up on this forum how to play audio-- and the example I saw was load, play, delete… so I just incorporated it similarly in my app… The same goes for images.

So, ideally then I should just load all my sounds and images… Do I ever want to delete them? On quitting the app, will they be automatically deleted, or should that be something that I set my program to do upon quitting?

Thank you again for the help.

-patrick

First, I must say that this is one of the most common problems in this particular forum.

It should be noted that some settings are stored on a per-user basis.

Patrick seems to have the right configuration:

(I would expect the app to not even launch with a debug build.)

I mentioned this briefly in an email I sent you…

I think you may have added an reference to the item without copying it to your project folder. (The file of such a reference would still end up in a built target.)

Ok, Thanks to Bruce Phillips, I found that the error2.aif file was actually on my Desktop, rather than in the audio folder with the other files…

I also modified my script to use sound properties, and have re-uploaded it at the same location:
http://www.collinatorstudios.com/dev/memorygame.tgz

My question now is… I am defining properties for the sound choices:

property snd_correct1 : missing value
property snd_correct2 : missing value
property snd_correct3 : missing value
property snd_correct4 : missing value

and then loading sounds to them in my on will finish launching handler:

	set snd_correct1 to load sound "correct1"
	set snd_correct2 to load sound "correct2"
	set snd_correct3 to load sound "correct3"
	set snd_correct4 to load sound "correct4"

But when you match two images, It is randomly choosing which sound it will play:

			set correct_audio to {"correct1", "correct2", "correct3", "correct4"}
						set correct_choice to item (random number from 1 to count correct_audio) of correct_audio

But I don’t know how to make correct_choice be a reference to snd_correct1-4… How does one do this?

Similarly, I am not sure how do the same thing in regard to displaying images… I was thinking, I could copy a loaded image to the end of a list, and have a list of variables that are images. Is that the best way to do this sort of thing (while keeping all of the images in memory).

thanks again.

-patrick

I too am having a similar problem with the file being reported to not run on 10.3.9 but working file on 10.4.9, and I am certain I am building it as a release and not debug.
http://itags.dreamhosters.com

After commenting out the current code, this worked for me:

play some item of {¬
	a reference to snd_correct1, ¬
	a reference to snd_correct2, ¬
	a reference to snd_correct3, ¬
	a reference to snd_correct4}

Thanks Bruce! I needed a way to make a file a reference to another, and all I needed was “a reference to”-- imagine that!

I ended up having to do something slightly different, because if the same sound was chosen twice, it doesn’t get played… So I had to do:

	repeat
							set correct_sound to some item of {¬
								snd_correct1, ¬
								snd_correct2, ¬
								snd_correct3, ¬
								snd_correct4}
							if correct_sound ≠ current_sound then exit repeat
						end repeat
						play correct_sound

Which still if you uncover multiple matches fast enough, it still is possible that one of the correct sounds will not play… Not really sure what to do about that other than maybe make a list that holds more than one current_sound, and once it contains maybe 3 items, to clear it…

Anyway, I reuploaded the new version… and I am now preloading images… Things are pretty fast… but one thing that seems to happen randomly on my system, is I will click an image view and then all of a sudden a bunch of them will disappear and I will see the brushed metal background behind them-- Upon clicking the regions where the image views are, they will uncover one by one again… But this is a strange bug, and I am not clear what is causing it, and what I should do to fix it? Any thoughts anyone?

Here is a screen shot of what happens:
http://www.collinatorstudios.com/dev/mg.png

strange…

-patrick