I have done a lot of research on this forum and I have been unable to find a definitive answer to my question.
So here is the problem:
- I use only events & functions, no JS.
- I have 10 sprite objects: the “digits” (one for each digit), available in each level of my game.
- I want an arbitrary number of “levels”: the goal here is to add levels easily.
- In each level I have the digits set as either a “goal” or an “obstacle” (exclusive or).
- My player is the “monster”: it must eat the goals and avoid the obstacles, which will by themselves be different at each level.
I have the basic first level working: it has only 1 goal and several obstacles (hard-coded logic here).
In order to factorize my events & functions and to further add levels, I thought about having a global variable “levels” which would have children variables: a “goal” array of arrays for each level (which would contain the goals to eat for the level) and an obstacle array of arrays for each level (which would contain the obstacles for the level). Then, I thought that I would just have to put the array of goals and obstacles in place of the single goal and obstacles of the first level to further augment it. The digits would have been accessed by their name stored in the arrays.
But… I can not access an object by name, as documented. How would you address this kind of problem, please?
I have thought about groups, but I can not access a group name by a variable value, if I understand things correctly. Any more idea? The goal is to create more levels just by editing the “levels” data structure: is it just possible? What would be your advice, if you try and avoid hard-coding your levels?
Thanks & regards,