Ask: with several words

Dear all,
to parse simple conversation I ususally use Ask: switch(second){ and a tag, e.g. ‘password’. How can I parse a combination of tags? Like, the player command is ASK NPC ABOUT PAST LIFE - ‘past’, ‘life’ would also parse ASK NPC ABOUT PAST MEAL, but I want to parse a specific combination of two words.
Thanks and kind regards, G.

The topic begins at word# consult_from in player input, and holds consult_words words.

You could print the words with code like:

for(i = 0 : i < consult_words : i++) {
  word = WordValue(consult_from + i);
  print (address) word, " ";
} 

You could check for two specific words like this:

if(consult_words == 2) {
  word1 = WordValue(consult_from);
  word2 = WordValue(consult_from + 1);
  if(word1 == 'secret' && word2 == 'mission')
    "I don't know anything about a secret mission!";
}

(EDIT: changed code to use WordValue instead of the incorrect WordAddress)

1 Like

Is that specific to PunyInform or the latest Standard Library? Using Standard Library 6.12.4, WordAddress() returns the memory address (within the text entry buffer) of the first character of a typed word, so feeding its result to print (addr) doesn’t seem to do the right thing.

Perhaps you meant WordValue()?

Ah of course. WordValue it is. I should have added that the code was just from the top of my head and hadn’t been tested.

And no, PunyInform doesn’t contain routines that are intentionally misleading, like routines that have the same name as a routine in the standard library but does something else.

1 Like

Okay, I seriously f**ked it up. Problem is that I’m still using the 6.11 library. So I DL’d the latest library, copied it over the …Lib/Base/ directory, and from then on things got worse. Luckily I had made a backup of the old 6.11 directory.

Is there some “How to update your library to the newst version for Dummies” somewhere out there?

Well, that depends on how you installed the old library and how you want to install the new library. Personally I don’t overwrite the library when installing a new version. I just install the new version in a new folder, and point to it when I compile.

1 Like

I think the question is not about installing 6/12, but updating your game code to use it properly.

I don’t think there is such a guide, though.

1 Like

The code for the WordValue() routine needed by fredrik’s solution is included (along with some other useful helper functions) in the block below. You should be able to include this in a project using Standard Library 6/11 without any trouble.

#Ifdef TARGET_ZCODE;

[ WordAddress wordnum p b;  ! Absolute addr of 'wordnum' string in buffer
    if (p==0) p=parse;
    if (b==0) b=buffer;
    return b + p->(wordnum*4+1);
];

[ WordLength wordnum p;     ! Length of 'wordnum' string in buffer
    if (p==0) p=parse;
    return p->(wordnum*4);
];

[ WordValue wordnum p;      ! Dictionary value of 'wordnum' string in buffer
    if (p==0) p=parse;
    return p-->(wordnum*2-1);
];

[ NumberWords p;            ! Number of parsed strings in buffer
    if (p==0) p=parse;
    return p->1;
];

#Ifnot; ! TARGET_GLULX

[ WordAddress wordnum p b;  ! Absolute addr of 'wordnum' string in buffer
    if (p==0) p=parse;
    if (b==0) b=buffer;
    return b + p-->(wordnum*3);
];

[ WordLength wordnum p;     ! Length of 'wordnum' string in buffer
    if (p==0) p=parse;
    return p-->(wordnum*3-1);
];

[ WordValue wordnum p;      ! Dictionary value of 'wordnum' string in buffer
    if (p==0) p=parse;
    return p-->(wordnum*3-2);
];

[ NumberWords p;            ! Number of parsed strings in buffer
    if (p==0) p=parse;
    return p-->0;
];

#Endif; ! TARGET_
1 Like

Okay I’ll try Otistdog’s code with my backup lib. But after I’ve freshly installed the Inform 6 lib, when I try to compile my game (z8) I get an error in Parser.h “All 233 global variables already declared”. Anyone got an idea what causes that? I was constantly battling memory problems but at last I only had 228/233 in use.

To be clear: That code wasn’t from me. It was copied-and-pasted from Standard Library 6.12.4. I was just pointing out that the same code should work within the context of Standard Library 6/11, so it isn’t necessary to upgrade to 6.12.x to get fredrik’s code to work.

Question: Does the 6.12 library use up more global variables than the 6.11 library so that less global variables are free for the author to use?

EDIT: My other game compiles, so I think that’s the solution for my library problem: 6.12 uses at least 6 more global variables than 6.11.

EDIT: Phew, case closed. After turning 6 global variables into attributes and internal variables, and after extending the amount of MAX_ACTIONS (which was also necessary due to the resource hungry new library) it compiled again (at which time my heartbeat reconstituted), and voila, Fredrik’s solution up there worked like a charm. Thaaanks!

1 Like