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

Dict and dict operations #68

Closed
MaanooAk opened this issue Oct 5, 2019 · 3 comments · Fixed by #87
Closed

Dict and dict operations #68

MaanooAk opened this issue Oct 5, 2019 · 3 comments · Fixed by #87
Labels
c++ involves C++ code nice new thing ☺ adds new functionality specification involves the nyan language specification

Comments

@MaanooAk
Copy link
Contributor

MaanooAk commented Oct 5, 2019

For openage dicts will be very useful in order to deal with what in the engine are called ResourceBundle.

In nyan creating a set of something like ResourceAmount would be very verbose, but with dict(Resource, float) a collection of resources can encoded very nicely:

Unit():
    cost : dict(Resource, float)

Knight(Unit):
    cost = {Food: 70, Gold: 75}

However, there is a need to be able to access the dict values separately. I would suggest something like that:

CheaperKnights<Knight>():
    cost[Gold] -= 20

Sidenote: Time (training time) could also be modeled as a Resource and be included in the cost

@TheJJ TheJJ mentioned this issue Oct 5, 2019
@TheJJ
Copy link
Member

TheJJ commented Oct 5, 2019

I was always unsure about adding a dict-type, because it may have <gmanvoice> unforseen consequences </gmanvoice>:
Currently you can implement dicts by using a set of objects, and the objects then have some values. Those objects are always referencable, as they have a name. Thus they can always be patched. When we add a real key-value type, values can get lost. If valueType is an object, the object is always referencable. Non-object values can get lost when it is updated in the dict. Which may not be desirable.

I guess that we should add dicts, though. Intuitively they seem a good addition, and loosing non-object values is probably okay, because who cares for a "random string" or a number like 235. If you overwrite it, you likely won't revert.

So all in all I think you are right and we should add a dict-type.

@MaanooAk
Copy link
Contributor Author

MaanooAk commented Oct 5, 2019

Yes but its huge

Something():
    FoodCost(ResourceAmount):
        resource: Food
        amount: 50
    WoodCost(ResourceAmount):
        resource: Wood
        amount: 50
    cost: {FoodCost, WoodCost}

My first thought was some kind of an anonymous object, but then you have something that cannot be referenced so why not just dicts.

Also having a bunch of prebuild WoodCost50, WoodCost75 but again you cannot patch them.

Maybe having a way to inline it, but then it gets ugly...

@TheJJ
Copy link
Member

TheJJ commented Oct 5, 2019

Yea indeed, so let's go for dict :)

@TheJJ TheJJ added specification involves the nyan language specification nice new thing ☺ adds new functionality c++ involves C++ code labels Oct 5, 2019
@heinezen heinezen linked a pull request Oct 5, 2020 that will close this issue
8 tasks
@TheJJ TheJJ closed this as completed in #87 Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ involves C++ code nice new thing ☺ adds new functionality specification involves the nyan language specification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants