chaining random events

1 view
Skip to first unread message

Eric F.

unread,
Aug 2, 2011, 6:14:12 AM8/2/11
to jacl-discuss
Hello,

I'm trying to create several levels of random events.

For example:

{+sing_only
write "You sing something.^"
write "It's a song about " player{song}"^"
}

integer ALEATOIRE
integer ALEAT2

{+macro_song
set max_rand = 3
set ALEATOIRE = random
if ALEATOIRE = 1
setstring return_value "a man."
endif
if ALEATOIRE = 2
setstring return_value "a dog."
endif
if ALEATOIRE = 3
setstring return_value "a woman who is " player{womansong}
endif
}

{+macro_womansong
set max_rand = 2
set ALEAT2 = random
if ALEAT2 = 1
setstring return_value "called Margareth."
endif
if ALEAT2 = 2
setstring return_value "drinking a cup of tea."
endif
}

But instead of getting "It’s a song about a woman who is drinking a
cup of tea.", I only get:
"It’s a song about drinking a cup of tea.drinking a cup of tea."

Is it a bug, or is there a better way of doing this?

Thomas Schwarz

unread,
Aug 2, 2011, 7:32:53 AM8/2/11
to jacl-d...@googlegroups.com
Hi Eric,

I am pretty sure that the problem is calling a macro from within a macro definition. (and the "return_value" being set twice/stacked...)
You should try to put the code of your macro_womansong directly into the macro_song.

Regards
Thomas

Eric F.

unread,
Aug 2, 2011, 10:44:54 AM8/2/11
to jacl-discuss
it doesn't seem to work, I've copied the second macro code directly
into the first, but then I got:
"It's a song about called margareth" (the first part of the macro is
not displayed)

Thomas Schwarz

unread,
Aug 2, 2011, 10:57:49 AM8/2/11
to jacl-d...@googlegroups.com
Hi, please post the current version of the code again. I'll have a look again.

Thanks!
Thomas

Eric F.

unread,
Aug 2, 2011, 5:06:52 PM8/2/11
to jacl-discuss
I tried the code below.

I liked the first version, with macros called within other macros,
it's a thing I was used on Inform. If it's not possible, it doesn't
matter but I wanted to be sure.

--------------------

location blip


grammar sing >sing_only

{+sing_only
write "You sing something.^"
write "It's a song about " player{song}"^"

}

integer ALEATOIRE
integer ALEAT2

{+macro_song
set max_rand = 3
set ALEATOIRE = random
if ALEATOIRE = 1
setstring return_value "a man."
endif
if ALEATOIRE = 2
setstring return_value "a dog."
endif
if ALEATOIRE = 3
setstring return_value "a woman who is "
set max_rand = 2
set ALEAT2 = random
if ALEAT2 = 1
setstring return_value "called Margareth."
endif
if ALEAT2 = 2
setstring return_value "drinking a cup of tea."
endif
endif

}



object kryten: kryten myself self me moi moi-même moi-meme joueur
has ANIMATE
short name "moi"
capacity 42
parent blip
player


#include "verbs.library"

Thomas Schwarz

unread,
Aug 2, 2011, 5:17:34 PM8/2/11
to jacl-d...@googlegroups.com
Hi, you have to replace "setstring" with "addstring" here:
       if ALEAT2 = 1
          addstring return_value "called Margareth."

       endif
       if ALEAT2 = 2
          addstring return_value "drinking a cup of tea."
       endif

Otherwise the "return_value" content "a woman who is " will be replaced by the new value...

Thomas

Stuart Allen

unread,
Aug 2, 2011, 7:45:07 PM8/2/11
to jacl-d...@googlegroups.com
Hi guys, how have you both been?

Thomas is right in that changing to addstring will allow you to
concatenate more text to return_value. I'll have a look at the
interpreter code though as it probably wouldn't be too hard to make
return_value a local variable and therefore have your original code
work as is.

Take care,
Stuart

--
http://dangarstu.tumblr.com

Eric F.

unread,
Aug 3, 2011, 12:18:13 AM8/3/11
to jacl-discuss
thank you both, it's working now.

I thought the mailing list wasn't getting enough activities, so I'm
working on a new JACL game :) (in French though...)

Stuart Allen

unread,
Aug 3, 2011, 12:23:37 AM8/3/11
to jacl-d...@googlegroups.com
That's okay Eric, it's about time I brushed up on my beau francais. :)

--
http://dangarstu.tumblr.com

Reply all
Reply to author
Forward
0 new messages