Using existing actions on values

Ack, no.

Problem. In the sentence ‘if the booknumber understood is A 1 1’ , you use the notation ‘A 1 1’ to write a constant value. But the notation was specified as ‘A 0 0’, which means that the second numerical part should range between 0 and 0.

Same with dashes. Alias didn’t get as far as having a specific reply to a specific value, and I couldn’t find anything else like it in the docs.

What if you say “A 9 9 specifies a booknumber”? Like maybe zeroes are a special case.

1 Like

Ah, yeah. When you define a kind of value including numbers like this, the number you use in the definition is how high it can go—for every number except the first, which has effectively no limit. Which is generally what you want for addition to work properly: if “$1.99 specifies a cost”, then $5.99 + $0.01 is $6.00 instead of $5.100.

So just put the maximum shelf and book number into your definition and that should cover it.

4 Likes

HAHA! It works.

Now I see they used all 9s in the Alias example, but they didn’t say why so I didn’t think about it.

Thanks!

2 Likes

The first digit (or, technically, the first sequence of contiguous digits of any length) always means an unbounded number. Each subsequent occurrence of a digit is placing a max on what digits may occur there.

Are these booknumbers going to be randomly generated? If so, will it be dynamic during the course of the game, or all set up at the beginning? About how many will there be?

There’s a problem with what you’ve got: all shelves must be “A”.

1 Like

Though that’ll change in the upcoming version of Inform where you can specify that a letter is one of the elements of the value!

3 Likes

Actually, more importantly, is it really relevant for you to be able to refer to book numbers in that format in your code? Or were you just setting it up that way for the convenience of using the booknumber understood in your action?

1 Like

You might want to pursue a strategy like:

a book-id has a text called the shelf.
a book-id has a number called the book-num.
a book-id has a number called the page-num.
a book-id can be actual or in-potentia.
a book-id has a text called the understood.
Understand the understood property as describing a book-id.
There are 50 book-ids.

to say (b - book-id): say "[shelf of b] [book-num of b] [page-num of b]".

to decide what book-id is a new book id:
  let b be a random in-potentia book-id;
  now b is actual;
  decide on b;

to decide what book-id is new book id with bookshelf (sh - text) and/-- book num (b - number) and/-- page (pg - number):
let new-book be a new book id;
now the shelf of new-book is sh;
now the book-num of new-book is b;
now the page-num of new-book is pg;
now the understood of new-book is the substituted form of "[shelf of new-book in lower case]-[book-num of new-book]-[page-num of new-book]";
say new-book;
say line break;

to recycle book id (b - book-id):
  now the shelf of b is "";
  now the book-num of b is 0;
  now the page-num of b is 0;
  now the understood of b is "";
  now b is in-potentia.

the book-id-regexp is always "\s+(<a-z>)\s+0*(\d+)\s+0*(\d+)(\s|$)".

after reading a command:
let pc be the substituted form of "[the player's command]";
  if pc matches the regular expression book-id-regexp begin;
    let the replacement be the substituted form of " [text matching subexpression 1]-[text matching subexpression 2]-[text matching subexpression 3] ";
    replace the regular expression book-id-regexp in pc with replacement;
    change the text of the player's command to pc;
  end if;

Sorry to code-dump at you, but there were enough tricky bits that it was a lot easier to code than it would be to describe…

1 Like

Figured that out all by myself! I have 6 letters, so it wasn’t an issue to just add more booknumber specifications.

I’m just super-pleased that I had the right idea at all and that minor tweaks made it work.

Does that actually work? If you write this:

A 9 9 specifies a booknumber,
B 9 9 specifies a booknumber.

I’m pretty sure that means that A 9 9 and B 9 9 are the same value – the letter doesn’t affect the value at all. Try it:

When play begins:
	if A 9 9 is B 9 9:
		say "A equals B".
1 Like

Yes! It totally works and you get the responses you want for each individual letter number number you make an answer for.

Code:

Lab is a room. 

A booknumber is a kind of value. A 0 1000 specifies a booknumber. B 0 1000 specifies a booknumber. M 0 1000 specifies a booknumber. L 0 1000 specifies a booknumber. V 0 1000 specifies a booknumber. Q 0 1000 specifies a booknumber.

Understand “examine [booknumber]” as booklooking. Understand “x [booknumber]” as booklooking. Understand “read [booknumber]” as booklooking. Understand “choose [booknumber]” as booklooking. Understand “pick [booknumber]” as booklooking. Booklooking is an action applying to one booknumber.

Report booklooking a booknumber:
	if  the booknumber understood is A 1 1:
		say "Youlearn the secret of life!";
	otherwise if the booknumber understood is B 42 963:
		say "You learn the secret of death!";
	otherwise:
		say "Reading random passages will not be useful.".
		
test me with "read A 1 1/read b 42 963/ read A 29 4"

I’m still thinking about how to report letters and numbers outside of the accepted range.

Edit- Wait! Crap. You’re right. Substituting A for B yields the same thing. Argh. Back to the drawing board.

Dude. I don’t even understand how I would use this, even after reading it through a couple of times.

I think the easier solution here would be to make it a kind of value with three parts (“0 99 999 specifies a book number”) and use a regex to change \b([abcde])(\s+\d+\s+\d+)\b into that format, no?

1 Like

That’s a reason I was asking about how desirable it was to call 'em by booknumber in the code.

lab is a room.
booknumber is a kind of value. #9-999-999 specifies a booknumber with parts shelf-num and book-num and page-num.

book-description relates one text to one booknumber.
The verb to book-describe means the book-description relation.

to decide what K is (v - value) cast as a/an/-- (name of kind of value K): (- {v} -).

#1-1-1 is book-described by "You learn the secret of life!".
#2-42-963 is book-described by "You learn the secret of death!".

the book-id-regexp is always "\s+(<a-z>)\s+0*(\d+)\s+0*(\d+)(\s|$)".

after reading a command:
let pc be the substituted form of "[the player's command]";
  if pc matches the regular expression book-id-regexp begin;
    let shelfnum be 999;
    let shelf-understood be the substituted form of the text matching subexpression 1;
    repeat with x running from 1 to 26 begin;
      let letter be "[(x + 96) cast as a unicode character]"; 
      if letter is shelf-understood begin;
        now shelfnum is x;
        break;
      end if;
   end repeat;
   let the replacement be the substituted form of " #[shelfnum]-[text matching subexpression 2]-[text matching subexpression 3] ";
    replace the regular expression book-id-regexp in pc with replacement;
    change the text of the player's command to pc;
  end if;

book-peeping is an action applying to one booknumber.

understand "examine [booknumber]" as book-peeping.
understand "read [booknumber]" as book-peeping.

carry out book-peeping a booknumber (called book):
  if a text relates to the book by the book-description relation, say "[text that relates to the book by the book-description relation][line break]";
  else say "Reading random passages will not be useful.";

to say (b - booknumber): let x be 64 + shelf-num part of b; say "[x cast as a unicode character] [book-num part of b] [page-num part of b]".

test me with "read A 1 1/read b 42 963/ read A 29 4"

That is complex. It works and it doesn’t work, though. For a specified booknumber it’s great.

The problem I am seeing:

I can’t always get the “Reading random passages will not be helpful” message when I try a booknumber I haven’t specified:

>get B 3 65

You can't see any such thing.

>get A 4 67

None of those is available.

>get b 1 1

Reading random passages will not be useful

Weird, all these different responses to different numbers.

Since I can’t make heads or tails of the code I haven’t the first clue as to how to alter it. I have 6 letters in use, and a set amount of books for each letter. If a player tries the other 20 letters, or a book number larger than the amount of books, they should ideally get a “No such book exists. There are 150 books on shelf A, 148 books on shelf B, etc” message.

In classic me fashion, I thought this would be easy and that a million people would already have done this and the docs would have a lot of examples. But no.

I think the problem is that it’s case-sensitive at the moment. The Z-machine lowercases commands before passing them to the game code but Glulx doesn’t.

Change this line:

let pc be the substituted form of "[the player's command]";

To:

let pc be the substituted form of "[the player's command]" in lower case;

And see if that fixes it?

2 Likes

Yay! It seems to. Is there a way to modify this for the following error messages:

– There is no bookshelf labelled with that letter.
– There are only x books in this bookshelf (I have a set amount of books in each section).
– If a player enters a partial number like B 87, a message saying their book number is incomplete.

1 Like

So now, any attempt to read a book will be mapped to the “book-peeping” action (though I would just call it “reading”). No magic needed after that—just normal action rules!

Definition: a number is a viable shelf if it is 1 or it is 2 or it is 13. [A, B, M]
Check book-peeping when the shelf-num part of the booknumber understood is not a viable shelf:

Check book-peeping when the book-num part of the booknumber understood is greater than 150:

Understand "A/B/M [number]" as "[incomplete book number]".
Understand "take/get/read/etc [incomplete book number]" as a mistake ("To take a book, you need to specify the shelf, the book, [italic type]and[roman type] the page, like A 1 1.").
1 Like

Sorry for the delayed thanks-- I had a houseful of guests for the eclipse. But I’ve got an OK handle on this now and have it working correctly. If I can’t get zarf’s suggestion from my other thread working as an alternative, I’m sure I’ll be back whinging about it.

Thanks for all the help as always, y’all!

2 Likes