OH NO! Help...

I have an application that is a simple button pressing app. I’m going to add on to it as it starts to work.

My problem is that when it starts up, it says to press B (keyboard or screen), and when you do it, it beeps and tells you to press space. When I press space, nothing happens! It’s set up to do something. To download the project, click here or above on “an application.” Here is the code (also included in the project):

--
--  iQuestionAppDelegate.applescript
--  iQuestion
--
--  Created by Dylan Weber on Friday, April 2, 2010.
--  Copyright 2010 Dylan Weber. All rights reserved.
--

script iQuestionAppDelegate
	property parent : class "NSObject"
	property thelabel : missing value
	
	property a : missing value
	property b : missing value
	property c : missing value
	property d : missing value
	property e : missing value
	property f : missing value
	property g : missing value
	property h : missing value
	property i : missing value
	property j : missing value
	property k : missing value
	property l : missing value
	property m : missing value
	property n : missing value
	property o : missing value
	property p : missing value
	property q : missing value
	property r : missing value
	property s : missing value
	property t : missing value
	property u : missing value
	property v : missing value
	property w : missing value
	property x : missing value
	property y : missing value
	property z : missing value
	
	on displaygood()
		thelabel's setStringValue_(some item of {"Good.", "Great.", "Wonderful."})
		if _a then
			set theitem to "_a:"
		end if
		if _b then
			set theitem to "_b:"
		end if
		if _c then
			set theitem to "_c:"
		end if
		if _d then
			set theitem to "_d:"
		end if
		if _e then
			set theitem to "_e:"
		end if
		if _f then
			set theitem to "_f:"
		end if
		if _g then
			set theitem to "_g:"
		end if
		if _h then
			set theitem to "_h:"
		end if
		if _i then
			set theitem to "_i:"
		end if
		if _j then
			set theitem to "_j:"
		end if
		if _k then
			set theitem to "_k:"
		end if
		if _l then
			set theitem to "_l:"
		end if
		if _m then
			set theitem to "_m:"
		end if
		if _n then
			set theitem to "_n:"
		end if
		if _o then
			set theitem to "_o:"
		end if
		if _p then
			set theitem to "_p:"
		end if
		if _q then
			set theitem to "_q:"
		end if
		if _r then
			set theitem to "_r:"
		end if
		if _s then
			set theitem to "_s:"
		end if
		if _t then
			set theitem to "_t:"
		end if
		if _u then
			set theitem to "_u:"
		end if
		if _v then
			set theitem to "_v:"
		end if
		if _w then
			set theitem to "_w:"
		end if
		if _x then
			set theitem to "_x:"
		end if
		if _y then
			set theitem to "_y:"
		end if
		if _z then
			set theitem to "_z:"
		end if
		set myTimer to NSTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(3, me, theitem, missing value, true)
	end displaygood
	
	on a_(sender)
		if _a then
			
		end if
	end a_
	
	on b_(sender)
		if _b then
			beep
			thelabel's setStringValue_("Press \"Space\".")
			set _space to true
		end if
	end b_
	
	on c_(sender)
		if _c then
			
		end if
	end c_
	
	on d_(sender)
		if _d then
			
		end if
	end d_
	
	on e_(sender)
		if _e then
			
		end if
	end e_
	
	on f_(sender)
		if _f then
			
		end if
	end f_
	
	on g_(sender)
		if _g then
			
		end if
	end g_
	
	on h_(sender)
		if _h then
			
		end if
	end h_
	
	on i_(sender)
		if _i then
			
		end if
	end i_
	
	on j_(sender)
		if _j then
			
		end if
	end j_
	
	on k_(sender)
		if _k then
			
		end if
	end k_
	
	on l_(sender)
		if _l then
			
		end if
	end l_
	
	on m_(sender)
		if _m then
			
		end if
	end m_
	
	on n_(sender)
		if _n then
			
		end if
	end n_
	
	on o_(sender)
		if _o then
			
		end if
	end o_
	
	on p_(sender)
		if _p then
			
		end if
	end p_
	
	on q_(sender)
		if _q then
			
		end if
	end q_
	
	on r_(sender)
		if _r then
			
		end if
	end r_
	
	on s_(sender)
		if _s then
			
		end if
	end s_
	
	on t_(sender)
		if _t then
			
		end if
	end t_
	
	on u_(sender)
		if _u then
			
		end if
	end u_
	
	on v_(sender)
		if _v then
			
		end if
	end v_
	
	on w_(sender)
		if _w then
			
		end if
	end w_
	
	on x_(sender)
		if _x then
			
		end if
	end x_
	
	on y_(sender)
		if _y then
			
		end if
	end y_
	
	on z_(sender)
		if _z then
			
		end if
	end z_
	
	on space_(sender)
		if _space then
			beep
		end if
	end space_
	
	on applicationWillFinishLaunching_(aNotification)
		thelabel's setStringValue_("Press \"B\".")
		set _b to true
	end applicationWillFinishLaunching_
	
	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits 
		return current application's NSTerminateNow
	end applicationShouldTerminate_
	
end script

I’m not sure what your trying to do so I can only point you in what I think may be the correct direction.

  1. Your if statements aren’t doing anything and are what are blocking “b” from communicating with “space”
  2. neither b or space are set up to do anything
    3.remove the if statement from “b” and space , you’ll notice a change
  3. theitem isn’t doing anything
  4. it doesn look like displaygood is ever called therefore your timer is never called

you’ll need to be more specific as what you’re trying to do

Explain what you said, I don’t understand you.
The if statements are there because I don’t want anything to happen without the variable concerning the letter is true.

And displaygood() will be called when I get this thing to work!

Dylan,
I downloaded your project, and when I pressed the “B” button nothing happened. This is because _b is a local variable to your applicationWillFinishLaunching method. If you add the following two statements to the top of your program, then it does say Press “Space” and beep after you press “B”, and it beeps after you press “space”.

property _b: false
property _space: false

What you want to happen after that isn’t clear to me.

The if statements are doing nothing the way you have them set up, they are blocking your application you have to do what rdelmar did

I’ll get to fixing stuff!

Dylan,

If all you want to get when you press a key is what letter it was, then you don’t need to have all those variables connected to each key, and you don’t need a separate method for each key. You only need one method – if you call it whichLetter_(sender), and connect it to all the buttons in your nib, then if you have something like:

On whichLetter_(sender)
set myVar to sender’s title
end whichLetter_

myVar will now contain the letter you clicked on. You can then use myVar to do whatever logic you want to do to flesh out the rest of the program.

It worked.

rdelmar, I’ll try your method later. :smiley: