Code Contingent on User Input

Howdy!

I have been trying to write code that reflects the words the player uses to refer to an in-game object, but I seem to be just spinning my wheels:

(current player #player)
(#player is #in #room)

#room
(room *)

#sparky
(name *)
  (temporary name * [])
  Sparky
(name *)
  (temporary name * $Temporary)
  (Print Words $Temporary)
  (now)(temporary name * [])
(temporary name * [])
(dict *) Sparky dog
(proper *)
(descr *)
  Isn't (name *) just the most precious thing?
(* is #in #room)

(understand [call doggo] as [call #sparky])
  (now)(temporary name #sparky [ Doggo ])

(understand [x doggo] as [examine #sparky])
  (now)(temporary name #sparky [ Doggo ])

(perform [call #sparky])
  (name #sparky) now has your full attention.

Although (understand $ as $) gets called, the game never refers to the object as Doggo, as seen below:

> call doggo
Sparky now has your full attention.

> x doggo
Isn't Sparky just the most precious thing?

Should I be going about this differently?

1 Like

Something like this works: I’ve just used a global flag to decide what name is printed.

(current player #player)
(#player is #in #room)

#room
(room *)

#sparky
(name *) ~(temporary name applies)
  Sparky
(name *) (temporary name applies)
  Doggo
(dict *) Sparky dog
(proper *)
(descr *)
  Isn't (name *) just the most precious thing?
(* is #in #room)
~(temporary name applies)

(understand [call doggo] as [call #sparky])
  (now)(temporary name applies)
 
(understand [call sparky] as [call #sparky])
  (now)~(temporary name applies)

(perform [call #sparky])
  (name #sparky) now has your full attention.

This plays as:

> x doggo
(I only understood you as far as wanting to examine something.)

> call doggo
Doggo now has your full attention.

> x doggo
Isn't Doggo just the most precious thing?

> call sparky
Sparky now has your full attention.

> x sparky
Isn't Sparky just the most precious thing?

> call doggo
Doggo now has your full attention.

> x sparky
Isn't Doggo just the most precious thing?

Hope this helps.

1 Like

This is great! My only concern is that when I add new pets and new nicknames, using flags pervasively might get unwieldy.

All the same, the code you have given me works flawlessly, which is myriad steps up from where I started. Thank you so much!

This is more in line with your original post, and should be easily expandable.

(current player #player)
(#player is #in #room)

#room
(room *)

#sparky
(male *)
(pet *)
(name *)
	(printed name * [name]) Sparky
(name *)
	(printed name * [nickname]) Doggo
(dict *) Sparky dog %% always able to refer to main name
(appearance *) (name *) wags his tail. 
(proper *)
(descr *)
  Isn't (name *) just the most precious thing?
(* is #in #room)
(printed name * [name])

#becky
(female *)
(pet *)
(name *)
	(printed name * [name]) Becky
(name *)
	(printed name * [nickname]) Becs
(dict *) Becky cat
(appearance *) (name *) looks at you with contempt.
(proper *)
(descr *)
  Isn't (name *) just the most precious thing?
(* is #in #room)
(printed name * [name])

%% call is a library command that redirects to shout to,
%% which in turn redirects to talk to.

%% this is just a toggle between name states
(perform [talk to (pet $pet)]) 
	(if) (printed name $pet [name]) (then)
		(now) (printed name $pet [nickname])
	(else)
		(now) (printed name $pet [name])
	(endif)
	(name $pet) now has your full attention.


1 Like

:grinning_face_with_smiling_eyes:

Thank you for giving me not one but two coded solutions to my problem—and with such flair!

1 Like