How do I Control Spawn Variables

0 favourites
  • 12 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hey there,

    I am currently working on an RPG and I am using predetermined spawn points to spawn enemies. As seen here.

    Now this works just fine, but only for one monster.

    I have created a Monster Array and loaded five monsters into said array. I need a way to randomly select from a set range of levels. So if its a "newb map", only level 1 to level 4 monsters will spawn there. I saved the monsters level to (x, 1). I also want to be able to set the monsters current frame to the current X. I am using static images for my monsters, not animations.

    I tried a for each X element but that doesn't seem to work. This image is what I had working in my previous project, but I can't seem to transfer the logic over.

    Any help would be greatly appreciated.

    Thank you,


  • Anyone? Surprised there is only 8 views on this thing after 12 hours.

  • For an even chance of spawning all monsters within the specified level range, I would use a second array. The first array would contain all monsters, the second array would be generated to contain monsters eligible to spawn.

    You would use a for each x, and check the level at curx,1 to see if it qualifies, then push it to three second array if it does. After all qualified entries have been added to the second array, you can use floor (random (array2.Width)) to pick a random index from the second array.

    For a brute force method, you can pick a random index from your main array, check of the level is within your criteria, and repick if it is not. But this method can be inefficient.

  • Hey this is exactly im working on but I have a question here as well

    Is there a way to do something like I have a global variable called location. and i have an array that has the row for each location and id like to do something like this

    " For each, data of [location] does not equal to zero then + 1 to the [pool]"

    And next id have something like Choose random(1-[pool])

    And then have it to where what ever number it choose it has the name of the monster and i can use that to pull the data for that monster alone.

    This is what Ive thought of but how do I write that as an expression for construct to use ? Because let say on route one there is only three monster but on "Route 5" there's ten monster. So in other word the [pool] can be 3 or ten

    I believe this can apply to levels as well ?

  • I'm not sure I understand what you are going for... could you clarify? Here is an example of the method I described in my post. ... .capx?dl=0

  • I understand Arrays. I just can't seem to understand the logic behind them and how people are able to just cycle through their data and know which ones to select, etc.

  • Oh I was replying to gearworkdragon actually.

    But basically you do a for each x/y on an array, which will run through each cell, and you can add conditions to specify which row or what content you are looking for.

  • oosyrag Your example is sorta almost to what i have in mind but What i have set up is one array to have all the location and their spawn pool monster.

    Such as this Route 1 | Slime | Bat | Cat |

    Route 2 | Slime | Cat | Wolf | Giant Turtle | Lion

    And those are in the same array just the X value of Route 1 is at 0 and Route 2 is at 1. I want to do a call back system where if i am on the section of the Map Route one. I have a global variable to include the area name Route 1

    and so id like the contruct two to quickly find in the array of the route 1 and use a random modifier to choose between Slime bat cat for route one but if i am on route two use the slime,cat, wolf, Giant turtle, lion.

    And my idea was to use something like to check the array on the X axis of the area name such as route 2 to add one variable count to the local variable pool to use so that If you are on route one the pool would be Four and id would just minus one at the end so that it would be three. So then Id would have contruct two to use the local variable Pool for the max number of monster to choose from and then it could just be ( choose (1- pool) ) and then next it would use that new chosen value to find the array monster in the function of []

    And then use that found and chosen array value to be use as the enemy in a 1v1 setting.

    And this would just be all in one function so that for every new route id create it would just be in the array so that it would just be me creating art and maps lol.

    But I do like your example btw can you explain the event conditions they are a tad confusing to know where you got your result to be like that.

    My main problem is getting construct two to find the right loop to check for the data and then set it to the local variable called pool.

    I hope this makes sense

  • Ok I get what you are trying to do I think.

    In your case, if you don't need a specific route name, you can just use the x index as your "route number", starting with 0 (If you do, you can use the indexof() expression).

    Your conditions would include:

    Array for each XY

    System Compare two values Array.CurY = routeNumber

    Array Compare Current Value !=0 (because you don't have the same number of monsters per route, some cells will be empty, or 0 - you don't want those)

    The action would be:

    randomizerArray - Push back Array.CurValue

    (You only need one action because you are only pushing one value to the new array. The randomizer array should start out as 0 width, 1 height, 1 depth)

    Then use floor(random(randomizerArray.Width)) to pick a random index from the randomizerArray, and reset the array by setting it back to 0 width.

  • oosyrag when you say " array compare current Value != 0 ) How do i do this to include the "!" or did you mean "not equal to "

    Ok um it works but it still giving me the blank spaces in the randomizer array. ? Will i have to recheck the array and delete the last X axis. Or can i get it to stop just right before the blank spot.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • != means not equal to

    Is the blank space always at the front/back? Are you sure your array is default width 0?

  • oosyrag Ok yeah ummm i feel dumb i just added another array contain value not equal to "blank" and you cant use Or block for it either has to be include as a whole condition.

    Btw is there a way to delete off the first value element so that its one width shorter, since it's just a location name and number Im guessing it would be delete an element to the front and how and where would i put it so that after its done with populating the array i can just delete off the extra element.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)