Display worn clothes in a message

How can I display the current worn Clothes in a Message ?

For example : "Hey you are wearing {cloth.worn}"


There are two functions, ListWornFor and ListVisibleFor, which return lists of clothes a character is wearing. ListWornFor lists all garments; ListVisibleFor lists only the outermost item in each slot (so won't list a shirt if they have a coat over it, for example).

To turn the objectlist into a string, you would probably want to use FormatList.

So for example:

msg ("You are wearing " + FormatList (ListVisibleFor (game.pov), ", ", ", and", "nothing") + ".")

or if you want to use it in a description, a text processor version:

You are wearing {=FormatList (ListVisibleFor (game.pov), ", ", ", and", "nothing")}.

If you just want to show one item the player is wearing, rather than list everything, you could do something like:

msg ("You are wearing " + GetDisplayName (PickOneObject (ListWornFor (game.pov))) + ".")

(PickOneObject picks one item at random, GetDisplayName turns an object into a string like "a {object:jacket}")


Thank you that worked.

The only thing now is that it shows the clothes with article and (worn). Can this be changed?

I would like to display only one clothing.


Ah, looks like the wearable library messes around with the alias.

How about:

msg ("You are wearing a " + GetString (PickOneObject (ListWornFor (game.pov)), "display") + ".")

Note that this won't display the object name as a link. If you want to do that, you'd have to use two lines of code:

garment = PickOneObject (ListWornFor (game.pov))
msg ("You are wearing a {object:" + garment.name + ":" + garment.display + "}.")

(doing this within a description would require making it a function)

(off the top of my head, so I might have got something a little confused)


Thank you very much !
Now it works fine


Log in to post a reply.

Support

Forums