Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Code for "do one of the following randomly"?

0 views
Skip to first unread message

Ikz

unread,
Oct 8, 2009, 8:52:12 AM10/8/09
to
This has been bothering me. I always use a specific workaround that
does the same exact thing functionally, but I want to know the snippet
I'm actually looking for here, the part that SHOULD be in brackets to
make it work.

For sake of example let's say there's a ghost in the basement and the
player's lantern goes on and off randomly because of it. That would be
annoying in a real game, but a decent example.

Every turn:
[Do one of the following randomly:]
Now the lamp is lit;
Now the lamp is not lit;
Say "The lamp is pushed by an unseen force but the flame is
not affected.";


Now, it seems like the code to perform that shouldn't be just one line
at the top like that, but I think it's the gist of what I'm asking
here.


Victor Gijsbers

unread,
Oct 8, 2009, 9:24:14 AM10/8/09
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

How about this?


Every turn when the player is in the basement (this is the ghost lamp rule):
if a random chance of 1 in 2 succeeds:
if the lamp is lit:
now the lamp is not lit;
say "The ghost turns off your lamp!";
otherwise:
now the lamp is lit;
say "The ghost turns on your lamp!"
otherwise:
say "The lamp is pushed by an unseen force but the flame is not affected."


Regards,
Victor
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrN5/kACgkQoiOrMwvIZLxIfQCfUDQnfKaEbjak+/n4VP4/NIUG
e9MAniB0vIdbhP7HgMX+7zvnNMiEyIry
=z4Wx
-----END PGP SIGNATURE-----

Andrew Plotkin

unread,
Oct 8, 2009, 11:03:32 AM10/8/09
to

For more than two alternatives, you'd do:

if a random number from 1 to 3 is:
-- 1: [...]
-- 2: [...]
-- 3: [...]

--Z

--
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
*

Ikz

unread,
Oct 8, 2009, 1:35:12 PM10/8/09
to
> *- Hide quoted text -
>
> - Show quoted text -

Thanks for the help guys. Both are similar to what I was using,
Andrew's being closer but slightly more pleasant-looking than mine.

Guess I wasn't working around anything after all if an official
version doesn't exist, heh.

Mark Tilford

unread,
Nov 20, 2009, 9:49:26 PM11/20/09
to


Really screwed up way to do it:
(Not tested, it probably won't work, and even if it does, somebody will
post in a day or two why it's a really terrible idea)

To say rand thing a: now the lamp is lit.

To say rand thing b: now the lamp is not lit.

To say rand thing c: Say "The lamp is pushed by an unseen force but the flame is
> not affected.".

Every turn:
say "[one of][rand thing a][or][rand thing b][or][rand thing c]
[purely at random]".

------

Do all the [one of] / [or] / [purely at random] have to be in the same string?
If not, it might be possible to do it with a single:

Every turn:
say "[one of]";


now the lamp is lit;

say "[or]";
now the lamp is not lit;
say "[or]The lamp is pushed by an unseen force but the flame is
not affected.[purely at random]".

Okay, that's got to violate something.

vaporware

unread,
Nov 20, 2009, 10:29:09 PM11/20/09
to

They do all have to be in the same string, so this won't work.

vw

0 new messages