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?
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.
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’.
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?
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
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.
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.
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.
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?
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.