> Why doesn't this work?
>
>
> objectloop ( i in player ) move i to room_name;
>
>
> Only the first object in the players inventory is moved.
[This is only a wild guess -- I haven't bothered trying to verify
it myself. And if it appears to be overly preachy, keep in mind
that I'm doing this for my own benefit, as well. Voicing my own
thoughts like this helps me think.]
Well, according to the manual, the above statement is equal to:
for (i = child(player) : i ~= 0 : i = sibling(i)) {
move i to room_name;
}
So the first iteration, the first object in 'player's inventory
is moved to 'room_name'. Then, 'i' is set to the sibling of said
object, which is ... well, the object 'i' just got inserted as
the eldest child of 'room_name', so sibling(i) would be the
first object that was in 'room_name', before 'i' was moved there.
Which means that if 'room_name' was empty before, the loop's
termination condition has been fulfilled - the object 'i' has no
more siblings - and the loop is done. If 'room_name' wasn't empty
... ugh, looks like it could turn into an infinite loop then.
There is a warning about this sort of things in the manual, which
does suggest an alternative way of stating it, which should work
in this case.
WARNING
When looping through the object tree, be careful if you are
altering it at the same time. For instance, objectloop (x in
rucksack) remove x; is likely to go horribly wrong - it's
safer not to cut down a tree while actually climbing it. The
safe way is to keep lopping branches off, while (child(x)~=0)
remove child(x);
Of course, if you are trying to move player and room_name are
the same object, this would be an infinite loop, but if that was
the case, there wouldn't be much sense in moving the objects in
the first place.
I hope this solves the problem for you. If not ... well, I'm
sure someone else is bound to come up with the correct solution
for both you and me, then. :-)
_
Torbjorn Andersson