0

So right now I have built a user interface on Xcode and I am scripting AppleScriptObjC.

I have 4 radio buttons on my interface. How to I program them? This is my current code:

-- IBOutlets
property window : missing value
property question1Radio1 : missing value
property question1Radio2 : missing value
property question1Radio3 : missing value
property question1Radio4 : missing value
property enterButton : missing value

on applicationWillFinishLaunching_(aNotification)
    -- Insert code here to initialize your application before any files are opened 
end applicationWillFinishLaunching_

--Radio button script here

on applicationShouldTerminate_(sender)
    -- Insert code here to do any housekeeping before your application quits 
    return current application's NSTerminateNow
end applicationShouldTerminate_

This is the code I just tried but wouldn't work

    -- IBOutlets
property window : missing value
property question1Radio1 : missing value
property question1Radio2 : missing value
property question1Radio3 : missing value
property question1Radio4 : missing value
property enterButton : missing value

on applicationWillFinishLaunching_(aNotification)
    -- Insert code here to initialize your application before any files are opened 
end applicationWillFinishLaunching_

on buttonClicked_(sender)

    if question1Radio1 = false as boolean then display alert "Works"

end buttonClicked_

on applicationShouldTerminate_(sender)
    -- Insert code here to do any housekeeping before your application quits

    return current application's NSTerminateNow
end applicationShouldTerminate_
Jonas
  • 121,568
  • 97
  • 310
  • 388
James
  • 213
  • 1
  • 3
  • 13

2 Answers2

0

I would suggest only using an Outlet for the matrix as a whole, not the 4 individual buttons. Then, you can connect the matrix, and in the send action of the button (or of the matrix if you like), get the index of the matrix to act on it. Such as:

on buttonWasClicked_(sender)        
    set theCol to (questionMatrix's selectedColumn()) as integer
    set theRow to (questionMatrix's selectedRow()) as integer

    if {theCol, theRow} is {0,0} then 
    -- do stuff
    else if …

Your questions is pretty general. I can't tell what parts of the process you do and don't know. So, continue to clarify in comments or revising your question so we can supply what you need.

jweaks
  • 3,674
  • 1
  • 19
  • 32
  • I am currently trying to use radio buttons in a quiz I am making. – James Jun 02 '14 at 23:52
  • Then this syntax should be adaptable to your needs. Ask if you have any issues. – jweaks Jun 03 '14 at 06:02
  • Can you give me more detail as in what this script means? I have been doing applescript for about 6 months and AppleScriptObjC for only a week. – James Jun 03 '14 at 14:00
  • I will do that. But, I might could help better if you post a screenshot of your interface. – jweaks Jun 03 '14 at 17:26
  • I am trying to get the value of a radio button when it is lit and not lit. Like, When is is not lit, I get false. And when it is lit, I get true. The new code on the question is the code I just tried but wouldn't work. – James Jun 04 '14 at 13:59
0

The state of the radio button is a property of the object received, here "sender".

To retrieve state of the sender you need to call the state() method of the object received.

Thus the code that works for this is

on buttonClicked_(sender)
    set question1Radio1 to sender's state()

    if question1Radio1 as boolean then display alert "Works"
end buttonClicked_