Uses 911K of libraries. Click here for Pure Java version (13905L/73K).
1 | !7 |
2 | |
3 | static LS questions = ll( |
4 | "What's your name?", |
5 | "Do you have a car?", |
6 | "Do you have a girlfriend?", |
7 | "Do you own a boat?", |
8 | "Are you tired?", |
9 | ); |
10 | |
11 | concept Answer { |
12 | S question, answer; |
13 | } |
14 | |
15 | compact module AskQuestions > DynDialogWithUser { |
16 | class CRUD { |
17 | replace A with Answer. |
18 | CRUD() { conceptClass = A; } |
19 | !include #1026525 // DynCRUD Include |
20 | } |
21 | new CRUD crud; |
22 | |
23 | start { |
24 | crud.start_DynCRUD(); |
25 | if (empty(dialog)) |
26 | newQuestion(); |
27 | onUserInput(voidfunc(S input) { |
28 | DialogItem q = nextToLast(dialog); |
29 | if (q != null && eqic(q.author, 'Computer)) { |
30 | S oldAnswer = getString(conceptWhere(Answer, question := q.line), 'answer); |
31 | uniq_sync(Answer, question := q.line, answer := input); |
32 | if (oldAnswer != null) |
33 | if (match3_noWildcards(oldAnswer, input)) |
34 | addLine('Computer, "Yes, I know."); |
35 | else |
36 | addLine('Computer, "I thought the answer was " + quote(oldAnswer) + "?"); |
37 | else |
38 | addLine('Computer, "Thanks, saved."); |
39 | } |
40 | }); |
41 | } |
42 | |
43 | visual jtabs("Dialog" := |
44 | centerAndSouth(super, |
45 | withMargin(rightAlignedButtons("New Question", rThread newQuestion))), "CRUD" := crud.visualize()); |
46 | |
47 | void newQuestion { |
48 | addLine('Computer, random(questions)); |
49 | } |
50 | |
51 | // API |
52 | |
53 | L<Answer> concepts() { ret list(Answer); } |
54 | Concepts conceptsObject() { ret db_mainConcepts(); } |
55 | } |
download show line numbers debug dex old transpilations
Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1020938 |
Snippet name: | Ask Questions [OK, has a fixed list of questions and chooses one randomly] |
Eternal ID of this version: | #1020938/24 |
Text MD5: | 843cc26641e537b86ae93eb231346687 |
Transpilation MD5: | 8bda3f1c0fa0b775cf09a88888297def |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-01-11 17:58:08 |
Source code size: | 1460 bytes / 55 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 425 / 2007 |
Version history: | 23 change(s) |
Referenced in: | [show references] |