I’m still a bit new to this so apologies for dumb questions. ChoiceScript does not, as far as I can tell, support objects.
I found Objects in ChoiceScript but it looks like some form of extension with commands like *define_object_type and *create_object, which I can’t find in the official documentation. The internal link to this code gives a 404 so I can’t follow it further.
Anyway, what I came up with is the following and I’d appreciate any feedback on whether this is a good idea or not.
Sample problem: D&D-type monsters with consistent attributes. The monster might be one of many, so the monster ‘object’ must be generic to avoid code repetition.
You have a good use case there. Unfortunately, I don’t think there’s a straightforward way of doing objects. Your way is as good as any. I would add an index so that I could keep multiple copies of a type of object.
If you want to simulate class behaviour, create separete scenes with class methods. Such as a dragon.txt and passing the index as reference. I wouldn’t take it too far though. Try replacing OOP for FP whenever possible.
You can simplify the above to: ${{monster&"_name"}}.
The second ${} is unnecessary.
For me the hardest part of this has always been that you can’t create variables (and therefore objects) dynamically. So, much like with arrays, you end up having to "*create" a pool of objects/array elements that you can re-use. Which gets messy.
I did experiment with making this very generic:
*gosub_scene utils get_attribute “wyvern” “strength”
which works for anything (and you could add an “index” param) but it’s very verbose when you use it all over the place.
Creating separate files for each ‘class’ is probably overkill in my case. ChoiceScript isn’t really cut out for it.
Thanks for your help.
If you do happen to go all out with this, and come up with a system you think is beneficial and reusable, could you please let us know? I’d likely try and encourage you to let us include it in CSLIB: 🧰 [TOOL] CSLIB - ChoiceScript Library.