Hello there!
First of all I’ll explain my current situation - I’ve made an AI-like (Artificial Intelligence) application in pure applescript (before I decided to finally add a normal UI to it), which basically works in the following way: it displays a text field in a dialogue, checks which text was entered in it, sets a variable with this text, and then checks if it fits any “command”.
It has few dialogue commands which work the following way:
if firstquestion is in nice then
display dialog "How do you feel?" with icon file [icon path] default answer ""
set heyreply to text returned of result
if heyreply contains "great" then
display dialog "I'm glad! Mine was great too!" with icon file [icon path] default answer ""
else if heyreply contains "good" then
display dialog "Just good? Eh, I hope it gets better!" with icon file [icon path] default answer ""
else if firstquestion is not in nice then
end if
“nice” is a list variable which checks if the user was nice and contains words like “hey, hello, yo” etc.
It continues like that far down, with many more reactions.
I decided it’s time to move it to xCode in AppleScriptObjC format to add a better UI and make everything in the same window instead of using dozens of dialogue boxes.
What I did so far:
I’ve bound the property of the text field and set it to execute code when a button is being pressed, there’s the property “theCommand” which is bound to the text field and updates the value.
Then “set theText to theCommand() as text” sets it as variable…
By pressing the button called “Next” it executes the code which checks what string was entered (checks if variable is equal to a specific word), but the problem is… it can’t continue replying.
That’s how I managed to convert the IF reaction so far:
if theText is in nice
theReaction's setStringValue_("How do you feel?")
myImageWell's setImage_(iconHappy)
end if
theReaction is a label, and myImageWell is an image well with icons (works by other variables I’ve defined above not mentioned in this post).
I tried to do something along of these lines:
if theText is in nice
theReaction's setStringValue_("How do you feel?")
myImageWell's setImage_(iconHappy)
set goodDay to {"Great", "Good", "Perfect", "Amazing"}
if theText is in goodDay
display dialog "Works!"
end if
end if
For testing purposes it was supposed to diaplay the dialog… but it didn’t.
Is there a way to make multiple IF statements in AppleScriptObjC? (If inside an If)
For example the AI greets the user, and asks him how he feels if the user replied. The user types a string such as “good” or “great”, and if the text field’s string value is equal to the string above (good or great, etc), it’ll display a reaction such as “My day was great too.”
I’ve managed to do it with two buttons but what I want is it being in one button. (Obviously in pure Applescript it works flawlessly as described above, but in xCode… not quite.)
And one smaller question - is it possible to set a default button that’ll be pressed every time I press enter? (like the default button function in an Applescript dialog box)?
Thanks for reading!