Spawning randomly "When play begins" vs. "Every turn"

Quite simply, I’m finding it strange that this works:

Every turn: if a person (called the actor) is not in a room: now the actor is in a random room.

While this, which would be preferable, does not:

When play begins: repeat with the actor running through people: if the actor is not in a room: now the actor is in a random room.

How am I stupiding? :confused:

I think the problem is that “actor” is a global variable, referring to the person performing the current action. Try changing it to something else and see if that works.

Didn’t know that. I’d seen “(called the actor)” around before and adopted it out of habit for this kind of use.

But regardless, I’ve also tried “spawn”, “being”, “new person”, and “blornik”.

I can only assume it must be something I misunderstand about repeat.

Wouldn’t be surprised. I spent nearly half an hour this morning trying to ren /s in a Windows batch command before learning that rename simply doesn’t accept switches. Winning.

Could it be that initial locations are not actually set until after play begins? Try putting both of them in every turn rules and see if that fixes it.

Bang. Absolutely right.

I did accidentally have the repeat running every turn once, and it piled many people into one room, so I didn’t think it would work this time, but I guess that was a fluke of randomness.

I wonder why the rooms (or maybe the people?) don’t exist when play begins. I’ll have to be careful with that…

My guess is that they exist, and have their “location” property set, but that isn’t translated to an actual position in the object hierarchy until a When Play Begins rule. I have no idea why it would be this way, though.

Not true. All objects have their positions in the world at “when play begins” time.

(Also, “location” is not a property. It’s a function, so it’s impossible for it to differ from the world layout.)

This works:

When play begins:
     repeat with P running through people:
     	    if P is not in a room:
	       	 now P is in a random room.