Randomly Assigned Names

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.

Does anyone know why this is happening?

1 Like

You’ve got an “or” in the wrong spot.

What’s happening now is, for each fish, you either:

  • Give it the color red, or
  • Name it Redford/Ruddy, then give it the color blue, then name it Bluebeard/Buber

You should move the first (or) to right before (now)($Obj has color #blue). I think that’ll fix everything.

1 Like

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”:

Did you want to examine Ruddy or?

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)
1 Like

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.

1 Like