Duplicates again, with a twist

I have a strange situation. I create a kind of gold coin, and I can have the player carry any number of them if the code is placed near the definition. However, if I try to have the player carry them inside a rule, I get an error, which I infer to be “kind-related”. Code is below.

[CASH, MONEY, and COINS]
A coin is a kind of thing. Weight of coin is COINWT.
A gold coin is a kind of coin. Cost of gold coin is 1.0.
A silver coin is a kind of coin. Cost of silver coin is 0.1.

[Comment 1: The player carries 27 gold coins.]

[Rule to generate initial class-based money as a real number.]
This is the initMoney rule:
	let Ng be initGold;
	let Ns be initSilver;
	now moneyAmt of money is Ng + (0.1  * Ns);
	say "Player has [description of money].[line break]";
[ Comment 2: 	now player carries 3 gold coins;]

If I activate Comment 1, all works fine. If I activate Comment 2, I get the error:

You wrote ‘now player carries 3 gold coins’ but this can’t be made true with ‘now’, because it is too vague about what it applies to. It’s fine to say ‘now all the doors are open’ or ‘now none of the doors is open’, because that clearly tells me which doors are affected; but if you write ‘now six of the doors are open’ or ‘now almost all the doors are open’, what am I to do?

Why does one work and not the other?

The one that works is declaring the existence of the coins. The one that doesn’t work is changing the location of the coins, but since there are many gold coins, it can’t figure out which one you want to move. Thus, you need to use “random” to tell it to just pick one.

2 Likes

I thought that might be the case, but when I say

This is the initMoney rule:
	let Ng be initGold;
	let Ns be initSilver;
	now moneyAmt of money is Ng + (0.1  * Ns);
	say "Player has [description of money].[line break]";
	now player carries 3 random gold coins;

I get the error:
In the sentence ‘now player carries 3 random gold coins’, I was expecting to read a condition, but instead found some text that I couldn’t understand - ‘player carries 3 random gold coins’.

Code outside of rules is declarative: it lays out the initial state of the world.

Code inside rules is imperative: it tells the program to do something (like changing the state of the world).

“The player carries five gold coins” is fine declarative code. That’s a perfectly reasonable way for the world to be laid out.

But “now the player carries five gold coins” is ambiguous in imperative code. Which five gold coins?

“Now the player carries five random gold coins” should be fine if there are five gold coins in the world for the player to grab:

There are twenty gold coins.
2 Likes

I placed 20 gold coins in a room for such a purpose: VSpace. So when I say random gold coins (which are out of play), Inform moves them from VSpace to my player?

It might be the ones in VSpace, or might be any other gold coins in the world. If you want to specifically use the ones in VSpace, then say that:

now five random gold coins in VSpace are carried by the player.
3 Likes

That’s what I thought too. When I try it, I get the following error:
In the sentence ‘now five random gold coins in VSpace are carried by the player’, I was expecting to read a condition, but instead found some text that I couldn’t understand - ‘five random gold coins in VSpace are carried by the player’.

I guess what I want ultimately is to have the player carry a random number of gold coins (and silver coins) in his/her small belt pouch. However, a random number works only in operational space and not declarative space. How do I get what I want?

The random number is a function of various attributes of the player, so I can’t just assign a fixed number of coins to the player.

Hmm. I think it might be the case that “random” just doesn’t support putting a number in front. So, instead of “now five random coins are carried by the player”, I think you could try this:

repeat with n running from 1 to 5:
  now a random coin in VSpace is carried by the player
1 Like

Yes, this kinda works. I get a long list of individual coins carried by the player; in this case, 5 gold coins. I know that if I have 5 gold coins in the location, “take all coins” gives me an inventory list that says “5 gold coins” instead of listing “a gold coin” five times. I will try playing with the multiples-object list but that seems like awkward overkill.

On a side note: Can I move the five coins into the belt pouch carried by the player? There seems to be no syntax for that in this case.

move a random coin in VSpace to the belt pouch should work.

Although I would think a simple now a random coin in VSpace is in the belt pouch would work too?

All this supposing the belt pouch is a container, of course.

Your first example works only if it is in a loop N number of times, but then I get N individual coins in my inventory, which is quite inconvenient for 27 arrows or 100 coins.

What behavior do you expect, other than having N individual coins in your inventory? Isn’t that the point of making a bunch of duplicates?

I wonder if the issue is that they’re not being grouped in inventory? That should be the default behavior for duplicates though, unless there’s some other rule intervening.

1 Like

Yes, my code built on Celtic’s code, which was a loop. So that was what I thought you were asking for.

I’m confused, isn’t that what you wanted?

Edit: I see, you’re talking about the grouping. My original reply was just about how to modify the code to move them to the belt pouch. It’s not clear to me if the grouping issue is occurring when you’re taking inventory or not, but see the manual again on how to make grouping rules:

Huh? That’s weird though. If they’re duplicates, wouldn’t they be grouped together by default? Is there something else in your code that’s altering grouping rules?

1 Like

Mike, I do have my own inventory rule, so I will handle the grouping there. I thought there was something I was missing.

1 Like

This doesn’t help much. I need to get into the multiples-object list to solve this, which I did elsewhere in my code. The docs have little on the M-OL.