You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You should see a button-like window appear on the left edge of the window `display-window`with the text "NAVIGATION SYSTEM FAILED".
82
+
3. Right now, the button doesn't do anything. Next, we'll connect a function to the button which can print text to `display-window`.
83
83
84
84
{% hint style="info" %}
85
-
Right now, the button doesn't do anything. Next, we'll connect a function to the button which can print text to `display`.
85
+
We can detach and remove this menu with `(DELETEMENU button-menu display-window)` . This does not delete the menu from memory. You can always repeat Step 2 to reattach the menu.
86
86
{% endhint %}
87
87
88
88
***
89
89
90
+
Let's create a list of distress calls we can randomly cycle through each time we press our button! In your Exec, type:
"Help! Nav systems compromised. What is lost will never be found."
96
+
"Help! Nav systems compromised. Lethal solar flare imminent."
97
+
"Help! Nav systems compromised. Stuck in orbit. Planetfall- ETA: 2 cycles."
98
+
"Help! Nav systems compromised. Class 3 Destroyer approaching. Contact- ETA: 6 cycles."
99
+
"Help! Nav systems compromised. Direction constant but unknown. Debris field. Contact- High."
100
+
))
101
+
```
102
+
{% endcode %}
103
+
104
+
Now, that we have a list named `distress-calls` , we can set up a function called `nav-sys` that displays a random message from this list to our `display-window` . Next, we'll connect this function to our `button-menu`.
105
+
106
+
***
107
+
90
108
We can define a new function with `DEFINEQ` . In your Exec, type:
91
109
92
-
`(DEFINEQ (print2display (LAMBDA (X) (PRIN1 "Help! Navigation system compromised. What is lost will never be found." display))))`
4.`(NTH list number)`: returns the tail of the specified `list`starting from the specified `number`. So, if we have a list `(A B C D)` and we use `(NTH (ABCD) 2)`, we'll get `(B C D)` as the output.
118
+
5.`(RAND value1 value2)`: returns a random value in a range from `value1` from `value2`.
119
+
6.`(LENGTH list)`: returns the length of the list.
1.`(RAND 1 (LENGTH distress-calls))` returns a random number between 1 and the total length of the list `distress-calls`.
122
+
2.`(NTH distress-calls` returns the tail of the list starting from the element at that random number.
123
+
3.`(CAR` returns the first element of that tail.
124
+
4.`(PRIN1 ... display-window)` prints that element to `display-window` .
125
+
5. And of course, `(DEFINEQ (nav-sys (LAMBDA (X)` gives the name `nav-sys` to our function. For our current function, we have no use for any parameters, so X is declared following conventions but unused.
126
+
127
+
***
128
+
129
+
Let's delete the button we made before with `(DELETEMENU button-menu display-window)` .
130
+
131
+
We'll make a new `nav-button` with our `nav-sys` function attached!
132
+
133
+
In your Exec, type:
93
134
94
-
This tells Medley to create a function called print2display which has a parameter `X`and a definition `(PRIN1 "Help! Navigation system compromised. What is lost will never be found." display)` .
135
+
{% code overflow="wrap" lineNumbers="true" %}
136
+
```lisp
137
+
(SETQ nav-button
138
+
(CREATE MENU
139
+
ITEMS ← '("NAVIGATION SYSTEM FAILURE")
140
+
WHENSELECTEDFN ← (FUNCTION nav-sys)
141
+
))
142
+
```
143
+
{% endcode %}
95
144
96
-
The function `prints2display`prints the text in the window `display` .
145
+
Our new button only has a small addition (and a different name). 
97
146
98
-
\[unfinished section about creating lists and cycling through them]
147
+
`WHENSELECTEDFN ← (FUNCTION nav-sys)` executes the function `nav-sys` when menu-item (our button `nav-button` ) is selected.
99
148
149
+
Go ahead and interact with your button!
100
150
151
+
Is your distress call module working? Cool! In the upcoming chapters, we'll add more features to our Display Module. While building this project, for each feature we'll explore and learn new bits of Medley Interlisp!
0 commit comments