What is the best way to set verbs for objects?

Dongers
22 Jan 2022, 12:46

I know that object.displayverbs = object.displayverbs is necessary for any of them to work, but should I use object.displaverbs = Split("Look at;other option1;orher option2") afterward to have the displayverbs appear/disappear or should I use if (not ListContains (object.displayverbs, "other option1")) { list add (object.displayverbs, "other option1") } for the individual verbs?
What's the better method?


mrangel
22 Jan 2022, 14:34

It depends how many things you want to change.

Using Split is faster (and doesn't require object.displayverbs = object.displayverbs first because it's creating a replacement list, rather than modifying the existing one). But it does mean that if you decide to give the object another verb at some point, you'd have to look for all the other places that displayverbs has changed, and make sure they all do it right.

Using Split also has the advantage that it keeps your list of verbs in the right order; whereas list add will always add new items to the end, which could bug some players.

One alternative if you're changing them a lot but want to keep them in the right order would be to use a list that checks each verb, and changes it appropriately. For example, you could make a function that does something like this:

bob.displayverbs = Split (ProcessText ("[LookAt];{either bob.health>0:[TalkTo];Fight{if player.class=thief:Pickpocket}:Search;Hide}"))

This has the result of setting the displayverbs to Look at;Talk to;Fight if bob is alive, Look at;Talk to;Fight;Pickpocket if the player's class attribute is set to "thief", and Look at;Search;Hide if bob is dead (so you can either loot or hide the corpse).

This is less efficient, but can easily be put in one function so that you can just call that function whenever something happens that might change one of those verbs. There are two conditions here that change the verbs, but you know the code that changes one of them won't mess up the verbs for the other.


Dongers
22 Jan 2022, 14:42

"But it does mean that if you decide to give the object another verb at some point, you'd have to look for all the other places that displayverbs has changed, and make sure they all do it right."

What exactly does that mean? Will I have problems if I use Split too many times to set the displayverbs of an object?


mrangel
22 Jan 2022, 17:36

It means that if you use Split like that, you have to include all the object's displayverbs every time.

Like in your example, you have Split ("Look at;other option 1;other option 2").

Imagine you're testing the game, and you realise the object should have a "Listen to" verb as well as "Look at". (I know, it's a silly example).
If you're doing the simple method with Split, you would have to go back and add 'Listen to' to all of those lines. If you miss one, that verb could disappear unexpectedly and confuse the player.

If there's just one verb being added and removed, it's not a big problem. But the more places you change the same list, the harder it gets to keep all of them right.

(I've seen large, popular games with this kind of problem… sometimes a method that's simpler to write will be harder to update if you want to change anything.)