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

Getting a reference to a specific entity #114

Closed
byorgey opened this issue Sep 29, 2021 · 4 comments
Closed

Getting a reference to a specific entity #114

byorgey opened this issue Sep 29, 2021 · 4 comments
Labels
C-Low Hanging Fruit Ideal issue for new contributors. G-Entities An issue having to do with game entities. L-Commands Built-in commands (e.g. move, try, if, ...) in the Swarm language. S-Moderate The fix or feature would substantially improve user experience. Z-Feature A new feature to be added to the game.

Comments

@byorgey
Copy link
Member

byorgey commented Sep 29, 2021

Normally, entities can be looked up and referred to by their name, even though entity names are not actually guaranteed to be unique. This works fine most of the time---if you refer to a log, it really doesn't matter which one you get since they are all identical. However, in some scenarios specific entities will need to be differentiated. The motivating use case is boxes: if you have several boxes in your inventory and put some items in one of them, you now want to be able to refer to the specific box containing your items as opposed to the others. I propose two operations to assist with this:

  • rename : string -> string -> cmd () takes one entity with the first name (it's undefined which) and renames it to have the second name. For example if you want to pick out a specific box to put some items in, you could first execute rename "box" "mybox". Now mybox will show up in your inventory separate from the other boxes.
  • unique_name : string -> cmd string will generate a name based on the given one which is guaranteed to be globally unique. Maybe you are programming some robots to do an automated task and you don't plan to ever look at their inventories, so you would rather just name some boxes automatically and pass around their names in variables.

I'm very open to other suggestions re: API.

@byorgey byorgey added Z-Feature A new feature to be added to the game. C-Low Hanging Fruit Ideal issue for new contributors. S-Moderate The fix or feature would substantially improve user experience. G-Entities An issue having to do with game entities. L-Commands Built-in commands (e.g. move, try, if, ...) in the Swarm language. labels Sep 29, 2021
@byorgey byorgey mentioned this issue Sep 29, 2021
@byorgey
Copy link
Member Author

byorgey commented Feb 17, 2022

After thinking about this more, it seems a bit arbitrary / unsafe to continue doing everything with strings. Another possibility might be to do something similar for entities that we have done for robots in #303 : introduce a new entity type, and give every entity a unique (internal) ID. (Entities of which we have many copies would continue to all share the same ID.) Then instead of rename we could have something like get_entity : string -> cmd entity which would actually get a reference to a specific entity with the given name (i.e. it would assign a new ID to one specific entity and return a reference to that). I'm not sure about all this --- it seems there must be a more elegant way to do it.

@byorgey byorgey changed the title Entity name management commands Getting a reference to a specific entity May 3, 2022
@byorgey
Copy link
Member Author

byorgey commented May 3, 2022

Brainstorming a bit more about having a specific entity type.

  • Suppose e.g. give now has type give : robot -> entity -> cmd (). How would you get an entity value to pass to it?
    • If it's something you just harvested, this is no problem, since presumably we would have grab : cmd entity.
    • But otherwise it seems like it's going to be annoying managing entity references.
  • I suppose there needs to be a way to turn string values into entity references, or perhaps just make string a subtype of entity?
    • entity : string -> entity ? If an entity of that name doesn't exist, we get a "null entity", perhaps. Having it be -> maybe entity would be more correct but would be harder to use in the early game...

@xsebek
Copy link
Member

xsebek commented May 22, 2022

Relatedly I needed a way to get a specific robot by its name that is specified in a challenge. #339

Maybe we could come up with a unified way to turn string into a proper type like entity or robot.

@byorgey
Copy link
Member Author

byorgey commented Jul 1, 2022

I'm going to close this issue and move the focus to #455 (which also includes a link back here so we can still read the historical discussion).

@byorgey byorgey closed this as completed Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Low Hanging Fruit Ideal issue for new contributors. G-Entities An issue having to do with game entities. L-Commands Built-in commands (e.g. move, try, if, ...) in the Swarm language. S-Moderate The fix or feature would substantially improve user experience. Z-Feature A new feature to be added to the game.
Projects
None yet
Development

No branches or pull requests

2 participants