Re: Inform Code help - random held item?


23 Jan 1995 10:03:06 GMT

Armande (furiop@vccsouth28.its.rpi.edu) writes:
> I want to write some code that causes a random item held by the player
> to be mentioned in text or dropped by the player "accidentally". The
> item must be held and not worn, and cannot be inside another item.

You need something like this:

[ RandomHeldObject i j k
! count number of items in player
objectloop(i in player) if (i hasnt worn) j++;

! Maybe the player isn't carrying anything?
if (j == 0) return 0;

! pick a random object
k = random(j);

! find it and return it
objectloop(i in player)
if (i hasnt worn) {
j ++;
if (j == k) return i;
}

! shouldn't reach this code
print "** Bug in RandomHeldObject **^";
return 0;
];

--
Gareth Rees