I am trying to write code that assigns names randomly. So far this is what has been most successful for me:
(current player #player)
(intro)
(assign characteristics #fish1)
(assign characteristics #fish2)
(try [look])
(assign characteristics $Obj)
(select)
(now)($Obj has color #red)(or)
(select)
(now)($Obj has name [Redford])(or)
(now)($Obj has name [Ruddy])
(at random)
(now)($Obj has color #blue)
(select)
(now)($Obj has name [Bluebeard])(or)
(now)($Obj has name [Buber])
(at random)
(at random)
#player
(* is #in #room)
#room
(room *)
(look *)
Two fish are swimming here.
#fish1
(proper *)
(name *)
(* has name $Name)
(Print Words $Name)
(dict *) fish
(* is #in #room)
#fish2
(proper *)
(name *)
(* has name $Name)
(nth $Name 1 $Element)
(Print Words $Element)
(dict *) fish
(* is #in #room)
And this is an example of the sort of output I generate with it (after the command “x fish”):
Did you want to examine Buber or?
I thought it might be a list problem, but if I replace the lists with objects, the problem persists.
Thank you! That is definitely part of it, but something still is not working as expected.
The relevant code now reads as follows:
(assign characteristics $Obj)
(select)
(now)($Obj has color #red)
(select)
(now)($Obj has name [Redford])
(or)(now)($Obj has name [Ruddy])
(at random)
(or)(now)($Obj has color #blue)
(select)
(now)($Obj has name [Bluebeard])
(or)(now)($Obj has name [Buber])
(at random)
(at random)
And this is what I got the most recent time I tried “x fish”:
Oh wait. The problem is that at some point during my revision process I did not make the fishes’ per-object properties parallel.
I would be interested in hearing whether this is the most “Dialog” approach to the random assignment of names. Would another solution be better or more idiomatic?
Anyway, for anyone who is curious here is the fixed code for the second fish:
(proper *)
(name *)
(* has name $Name)
(Print Words $Name)
(dict *) fish
(* is #in #room)
I would say yes, this is a good approach to assigning random names.
If you have many fish, you may want to generalize it into a trait:
(fish #fish1/#fish2)
(name (fish $Obj))
($Obj has name $Name)
(Print Words $Name)
(dict (fish $Obj)) fish
(*(fish $) is #in #room)
I would also recommend (purely at random) instead of (at random) here, given that there are only two options. Since (at random) avoids repetitions, it will pick a random option the first time, and then just alternate between the two cases.