Accessing objects indirectly in scenes & functions

Good morning,

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,

AlienKing

You actually can access an object by its name using the [object].ObjectName() expression. If the name of your digit objects are 0, 1, 2, etc., then I think you can even write their names in variables like this: ToNumber([object].ObjectName()).

Thanks a lot, I’ll try this syntax ASAP. Cheers!

Hi again,

Let’s say I have the following data structure:

  • levels (structure, global variable)
    • level_goals (structure)
      • level1 (array)
        • sprite1
        • sprite2

If I have an action where I want to “delete object” sprite2, shall I pass this expression as an object name to it:

[GlobalVariable(levels)[“level_goals”][“level1”][1]].ObjectName()
?

I have read this: Variables and this is my understanding of the expected syntax.

Thanks again!

Well if that works that’s certainly the way to do it.