Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify object interactions in Lua #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sunarch
Copy link
Contributor

@sunarch sunarch commented Dec 14, 2022

This change is meant to reduce the code required for object interactions, and doing the default only in the verb function.

One thing I'm not clear on is when the self.owner == nil part (now also moved) would occur. I wasn't able to test whether that part works correctly, because I wasn't able to produce that effect before the change, either.

@lminiero
Copy link
Owner

I see the same use of spaces instead of tabs that causes indentation to break, which makes it harder to review the changes. Could you take care of that?

self.owner refers to whether the object is in an actor's inventory: if it's nil, it's either an unowned object or a UI object. See addToInventory and removeFromInventory to see where it's changed.

@sunarch
Copy link
Contributor Author

sunarch commented Dec 15, 2022

Sorry, I fixed the indentation like in the other PR.

I understand the owner status, I'm just not sure how an object that is not owned could be used (and thus reach that branch of the code).

When you review, one thing to consider:

The check in the interaction is "reversed" in a way: Before, because the useWith method was being overridden, e.g. the envelope object called it with the object argument being e.g. fire. Now the interaction is happening with fire and the object is passed a envelope, from which the handlers are looked up.

This should produce the exact same behavior as before, but it's worth considering from a design intentention p.o.v. The reversal was happening in the select verb in object, the simplification there made this double twist necessary, but I think the result is simpler overall.

@lminiero
Copy link
Owner

I'm not sure I like the distinction between objects you own and objects you don't own, as far as creating objects to define interactions. It forces you to create duplicates of verbs depending on state, which is what I wanted to prevent in the first place. A verb should be able to use state to decide what to do with a specific object, which would simplify the management once state gets more complex than owned vs. not owned. A dumb example that comes to mind is you picking up a hose temporarily (selected), as it's not something you can put in your inventory, but needing to use it with the flowers. I feel it adds an unnecessary constraint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants