Setting Alt variables when creating enemies with string

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hi,

    I'm working on a game with a level editor. In this level editor you can create level tiles and enemies, which are stored in a 3-dimensional array (tiles on Z=1, enemies on Z=2). The enemies are stored as a string, e.g. "1", "2", "3', etc, so when loading the level, I can create them as an active object using their name. So a fastloop reading through the array and creating the enemies through CreateStr$(ValueAtXYZ"Array"). It then creates the enemy that is stored in the current position of the Array, e.g. enemy 1, 2, 3, etc.

    I would like to store specific enemy behaviours in the same X,Y position of the array, but then in Z=3 (vs Z=2 where the enemy type is stored). This way, I can use one enemy type, but have different characteristics stored in Z=3. For example the amount of life. So if an enemy from Z=2 in the array is loaded, that when creating this enemy, at the same time it loads the value from Z=3 and assigns this to Alterable Value A (which is used for enemy life points).

    I've tried to do this directly when creating the enemy and then Assigning Alt.Variable A of group Enemies to ArrayX,Y,Z=3 , but what happens is that ALL enemies are affected, instead of the object (enemy) that was just created using the CreateStr$(ValueAtXYZ"Array") function.

    So my question is: how I could assign specific values to a specific object created using string name? Hope this is possible, thanks!

  • Copy and paste your create code.

    Your post sounds like create object by name combined with referencing a qualifier breaks scope. I just tested it in a standalone MFA and it does not break scope.

    Makes sure that your variables are set immediately after creation of your objects. If you do anything else inbetween scope will be broken and all instances of objects within your qualifier will be affected.

  • Copy and paste your create code.

    Your post sounds like create object by name combined with referencing a qualifier breaks scope. I just tested it in a standalone MFA and it does not break scope.

    Makes sure that your variables are set immediately after creation of your objects. If you do anything else inbetween scope will be broken and all instances of objects within your qualifier will be affected.

    Yes, indeed that seems the case. I'm doing it exactly after creation, but it seems it doesn't link the qualifier "Enemies" with the Create object by name. My create code is as follows:

    On loop "BuildRowEnemies"
    Set X position ActiveObject to X ("ActiveObject") + value ("Counter_gridsize")
    Ad 1 to X dimension indeze of Array
    CreateStr$(ValueAtXYX"Array", index x("Array"), index y("Array"), 2) at (0,0) from ActiveObject
    Group.Enemies : Set AlterableValue A to ValueAtXYZ ("Array"), index x("Array"), indez y("Array"), 3)

    So I move the active object horizontally across the screen and create the enemies based on the array values. But what happens is that all enemies end up with the AlterableValueA as the last enemie, instead of each having their own specific value.

    Thanks for helping out!

  • Yes, indeed that seems the case. I'm doing it exactly after creation, but it seems it doesn't link the qualifier "Enemies" with the Create object by name. My create code is as follows:

    On loop "BuildRowEnemies"
    Set X position ActiveObject to X ("ActiveObject") + value ("Counter_gridsize")
    Ad 1 to X dimension indeze of Array
    CreateStr$(ValueAtXYX"Array", index x("Array"), index y("Array"), 2) at (0,0) from ActiveObject
    Group.Enemies : Set AlterableValue A to ValueAtXYZ ("Array"), index x("Array"), indez y("Array"), 3)

    So I move the active object horizontally across the screen and create the enemies based on the array values. But what happens is that all enemies end up with the AlterableValueA as the last enemie, instead of each having their own specific value.

    Thanks for helping out!

    I'm not sure why it's not working. I also use a combination of fast loops, create by name, and qualifiers, and it works for me. Below is one of my events for reference (the flower icon is a qualifier).

    Does your example work if you remove all references to ActiveObject in your event? So, for example, instead of creating at ActiveObject, what happens if you create at something like x=random(500), y=random(500)?


    Please login to see this picture.


    By the way, if your game is likely to get really big, then consider switching from a 3-dimensional to a 2-dimensional array to potentially improve filesize and performance. An array is kind of like an excel spreadsheet and, naturally, you can fit an awful lot of data into an excel spreadsheet without the need for 3 dimensions. If I understand your description properly, then your data could be organised something like this:


    Please login to see this picture.


    In this example, the Y dimension is used to store individual objects, with every individual object (whether enemy or tile) going on a different position of the Y dimension (ie. on a different row). Then the X dimension (ie. the columns) is used to gather all the relevant information about that object, and it can handle as much information as you throw at it (just keep adding columns). No need for a Z dimension.

    This array would need to store 72 units of information (8x9 = 72). But if we added, say, 5 'rows' of a Z dimension, it would suddenly be a lot bigger (8x9x5 = 360), and this may affect processing time.

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

    Edited 4 times, last by Volnaiskra (February 13, 2023 at 5:57 AM).

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!