Newbie, want to make a point system in my dress up game in godot for endings
Hello, just so you know, I'm a newbie in programming in general, so I ask you to be easy on me even if the question is resolved just by going through the docs (already did that, still have hard time understanding it).
I'm working on a dress-up game that has a character that won't want to wear certain clothes and if there are clothes on him that he doesn't like, the game will lead to a bad-ending scene and vice-versa.
I can search how to make events lead to changing a scene by myself. The actual questions are:
How do I group the clothes properly (I think I should look up global groups on docs here)?
How do I make points reset when clothes are dragged away from their perfect position (i.e. on character sprite)?
How do I make clothes correspond with eachother for the point system (explained further)?
Current issues
I'm away from my laptop, so can't provide exact code for now, so I'll do my best to explain
The code I'm using is from this tutorial
Pastebin with the drag and drop function itself as well
What I tried to do is a boolean @export for bad and good clothes, then go through if-elif statements for them in a drag and drop code, which sorta works, but:
Points get attributed only to one clothing (for example: I drag a yellow shirt as a good clothing type and get +1 to the point variable (therefore it is =1), but when I drag pants from the same type, it doesn't consider previous +1 and stays =1)
Points don't reset after clothes being reattached (if I drag away said yellow shirt and drag it back to the perfect position, it still will add a +1 and the point variable will equal 2 and so on)
I've only just started with Godot so I can't give you anything Godot-specific, but it sounds like you're asking for the logic to link things together. I'll make some recommendations here but you'll definitely have to adapt it to work for you. There's a few different ways to do this and it depends on exactly how you want your system to work. From what you've said it seems like you have (or want) two classes, a PointManager and an EquipableItem (or whatever you've called the class in your pastebin).
The first approach to grouping objects I'd use would be with enums, this gives you fixed pre-defined categories so is useful for assigning an equip slot to each item, for instance.
You can then verify this at two points: when you try to equip a new item you can verify that that slot isn't already used, and when you count points you can make sure you only count each slot once. If you want to put an item in multiple slots (eg a dress is torso+leg) you can look into bitwise enums and bitwise logic, but that's a little more advanced so I'd recommend getting the groundwork in first.
The second approach I'd use is a tags system, this is more flexible and can be be used for categorising outfits into as many categories as you want. The simplest way to do this is just an array of string IDs or ints, but this is more prone to user error since you can typo the string or enter the wrong number. On the plus side there's no central enum so you can add new categories whenever you want, even creating a custom category at runtime if you need to.
Your drag function is doing a lot so it does need split up and simplified a bit, but for our purposes it'll be enough to combine the two elif branches since they're doing the same thing, that lets us fire the event in one place for both successful and unsuccessful drag so we can recalculate the score. You'll end up with something along these lines:
The major benefit to using events here is that it almost completely decouples your scoring system from your items, your items shouldn't need to reference your scoring system at all but they'll still be counted as needed. You can swap in different items without touching the point manager, and you can write a completely new point manager without having to update anything on the items. There's exceptions for everything, but as a general rule of thumb the more tightly coupled your code is the harder it is to maintain.
Or we could use the same idea to, for instance, only score whatever outfit category appears the most
Obviously this is all very rough but it should at least give you somewhere to start with your logic.
save