Move X objects

I want to be able to move set numbers of objects and variable numbers of objects in one go, but I’m having a lot of trouble doing this and I’m wondering if anyone can help. :wink: I would like to just say ‘Move X objects’, but I can’t. I tried using this script that Eleas gave me, but I can’t work out a way to stop it or set the number of objects it can move. I also tried it with an extreme number of objects as a stress test and found it crashes with an error if it tries to move more than 63, This in itself wouldn’t be a big problem, if I could limit the number of times it repeats.

[code]A coin is a kind of thing.
The treasury is a room. 10 coins are in the treasury.

When play begins:
repeat with lucre running through coins in the treasury:
now the lucre is in Home.

Home is a room. The player is in home.[/code]

I’m also really not sure what the ‘lucre’ part of this is doing since I didn’t specify that the coins were lucre. It won’t seem to work with a temporary number like ‘repeat with X’.

Just solved it! I’ll leave this for anyone else with the same problem:

Let X be the number of bullets carried by the player; repeat with bullets running from 1 to X:

“Lucre” is just a temporary variable. So “repeat with lucre running through coins in the treasury” basically means: “Take the first coin in the treasury and call it lucre. Do something to it. Then call the second coin lucre. Do something to it.” and so on. You could use any word in place of “lucre” (unless maybe it was a word that was reserved for something else) and it’d be fine.

Also, I didn’t find any problems with a stress test–I set the number of coins in the treasury to 100 and it worked fine.

In this case, however, you could simply say:

When play begins: now every coin in the Treasury is in Home.

and it would work.

That wouldn’t help with moving a limited number of things, though. I didn’t really follow your solution (in that solution, the second “bullets” is actually a temporary variable for a number that will count from 1 to X), but you could do something like this:

[code]A coin is a kind of thing.
The treasury is a room. 100 coins are in the treasury.

When play begins:
repeat with X running from 1 to 63:
if a coin (called lucre) is in the treasury:
now lucre is in Home.

Home is a room. The player is in home.[/code]

There are two temporary variables here. The X is just a number that steps up from 1 to 63, which ensures that the next loop runs 63 times. (And since we never refer back to X, that’s all it does.) Then in the conditional that tests whether there’s a coin in the treasury, we actually give the first coin it finds the temporary name “lucre,” which allows us to move that coin.

Let X be the number of bullets carried by the player; repeat with bullets running from 1 to X:

Bad idea. You’re using “bullets” as a temporary variable, hiding the general definition of “bullets” as a kind of thing. You shouldn’t do that; it will at minimum confuse onlookers, probably also yourself.

If you’re going to be doing a whole lot of this kind of thing, you might want a custom phrase to make it quicker. Here’s one I minimally tested:

[code]A coin is a kind of thing. A platinum coin is a kind of coin. A silver coin is a kind of coin. An electrum coin is a kind of coin.
The treasury is a room. 100 platinum coins, 100 silver coins, and 100 electrum coins are in the treasury.

When play begins:
move 63 of the platinum coins in the treasury to home;
move 24 of the silver coins in the treasury to home;
move 83 of the electrum coins in the treasury to home.

Home is a room. The player is in home.

To move (N - a number) of (OS - description of things) to (new place - an object):
let L be the list of OS;
repeat with X running from 1 to N:
if N is at least X:
move entry X of L to new place.[/code]

The sneaky thing here is that you can input a “description of things” to a phrase–this could be something like “coins” or “electrum coins in the treasury” or what have you–and then you can wrap it up in a list and do things with it. Here we use the temporary number value X to move along the list and grab the first N entries and move them. (This may be undocumented and not guaranteed to continue to work in future versions–I stumbled across it in the Standard Rules or the Complex Listing extension one time.)

Ah, thanks guys, that explains some bugs I’ve been having.

By the way, would any of you know how to calculate the number of a noun at a location? I can’t seem to do it. I wanted to do it with ‘visible objects’ but apparently that means ‘every object of that type in the game’

“The number of electrum coins in Home” should work, or whatever it is–what’s the problem you’ve been having?

(One issue is that “in the home” only catches things directly in the location, not on supporters or in your inventory or whatever. Then you’d need “the number of electrum coins enclosed by Home” or “the number of electrum coins enclosed by the location” if you want to check whatever room the player is in.)

In fact “the number of visible electrum coins” should catch all and only the one the player can see.

Basically, I want to turn ammo into a number instead of objects to make the inventory neater, but I can’t get it to work. Basically what I have is:

Instead of taking a Revolver Bullet: move every noun at the location to the player; Let X be the number of Revolver Bullet carried by the player; Increase Revolver Ammo by X;

What I want it to do is hoover up all the ammo at once, shift it off screen, and increase the ammo the player holds, but I can’t think of any method that doesn’t generate a hell of a lot of text, or try to grab every bullet in the game. What I really want to say is:

Move every Revolver Bullet visible to the player...

I think if I can say that much, your script will let me move everything I need to.

It seems like you might want something like this:

Instead of taking a Revolver Bullet: let X be the number of touchable revolver bullets; increase revolver ammo by X; now every touchable revolver bullet is off-stage; say "You grab [X] bullets and now have [revolver ammo] bullets."

[CODE EDITED in accordance with Draconis’s correction below]

You want “touchable” rather than “visible” so you don’t wind up hoovering up the bullets that are in a locked transparent container or something. Anyway there’s no need to move the bullets to the player if ultimately they wind up off-stage and get represented by a number.

One issue here is that if there are six bullets and the player types “Take all bullets” they still get an unwieldy amount of text, as it performs the taking action separately for each of the six bullets (and gives an annoying message for the last five, since they’ve been moved off-stage already). You could look at this IFAnswer of mine for a suggestion as to how to take care of that.

One note: change the last instance of “visible” to “touchable” on line 5, so that it won’t move visible but untouchable bullets offstage.

Thanks, it does it now! But I can’t get the message suppressing script to work. It compiles, but it doesn’t actually seem to work.

Yeah, I’m having trouble getting it to work too. It takes some fiddling, which I don’t have time to do right now.

Honestly, if you don’t really need to implement every bullet as a separate thing, maybe one thing to do would be to have some “bunch of bullets” objects with a bullet count. Then when the player takes the bunch of bullets it would just add the ammo count of the bunch to the player’s ammo count, you could have several bunches of bullets in different places if you needed, and you wouldn’t need to worry about suppressing multiple objets.

That is a good plan. I think I may have solved the messaging problem by moving them to the player and having a separate ‘every turn’ script that dumps every bullet carried by the player somewhere else. You still need that message suppressing script, but it seems to get rid of all the errors completely and it triggers instantly with no messages, so there doesn’t seem to be any problems or bugs.