AmpedRobot's Recent Forum Activity

  • This is a corollary to my post about filling a 1D array with an incremented variable.

    I then wanted to pick 4 unique non-repeating values out of that array, which wasn't difficult to code by using another array, but the non-repeating part has proven a bit of a challenge. Basically I have a roller with Choose, but to make sure the values don't repeat I delete the rolled value out of the original array.

    The problem then is that rarely, depending on the odds, I get a 0 value out of the 4 chosen when it rolls into one of the deleted cells.

    There is an easy solution, don't spawn want I want to spawn if it's the 0 value, but this screws up my odds a little.

    I tried coding this a dozen different ways using the system repeat and various sub-event structures/flags with no success.

    Basically nothing works, but there should be a clean solution to this.

    ----

    I tried as a flag, for example, compare current value in the original array, if it does not equal 0, do your thing, but if it equals 0, reroll to hopefully hit another cell.

    I'm not sure this works properly within the Construct logic or if there's another solution for this.

    Is there something like Roll A Random Number As Many Times As Needed Until A Specified Condition Is Met?

    And how would one integrate that into a typical finite system repeat block (not once per tick)?

    P.S. I thought I solved this until I discovered the rare 0 values on rolls and realized what was happening.

    ---

    P.S. Here's the capx.

    http://www.darksunpictures.com/public/array2.capx

    Also, is there a cleaner way of stopping the infinite loop of system repeat w/o having to increment the flag? I tried doing it with a flip between 0/1, but it didn't work.

    It's doable doing it in this weird sequence, but gets a little annoying having to increment the flag on every copy of the block.

    Just wondering if somebody figured out a cleaner solution.

  • To someone returning to Construct 2 after several years it wasn't obvious.

    And that's an Events page, dealing with event structure.

    System-Repeat is classified as an object in the Scirra manual.

    So if someone's just returning and looks this up, a bit of transparency would've been helpful, especially when it seems counter-intuitive.

    This is before I discovered Trigger - Once, mind you.

  • I read that section a zillion times before for other things.

    "This means most system conditions do not pick any instances: they are either true or false. *If they are false the event stops running, otherwise the event continues* without the picked instances having been changed. "

    Boy, that is really buried in there.

    Unfortunately, I did not correlate the two. Maybe there should be some sort of preamble at the beginning of the System Conditions section of the manual?

    That's what naturally comes up on Google search.

  • Is System-Repeat every tick? How would I know that by reading the manual?

    "Repeat

    Simply repeat the event a given number of times. This tests any conditions following it on every repeat, and if those conditions are met also runs the actions and any sub-events on every repeat."

    https://www.scirra.com/manual/124/system-conditions

    It seems to be because it needs a condition to break the infinite loop, which is confirmed by debugger. The manual states it tests "any conditions", not that you have to have conditions to break the infinite loop. This caused me some time in testing initially because I couldn't figure out why it wasn't working and I didn't fully figure it out until I found other people's code examples and then a lot of testing.

    Unless this is some general rule which was stated at the beginning of the manual that "everything is per system tick" unless stated otherwise.

    From logic alone, one would think if you have repeat something x times, it should be repeated x times and that's it.

  • Nvm, now it shows up in debugger, maybe it was some crazy run time error.

    Err, now that I think about it, maybe I didn't know I was supposed to click on the array name on the left and maybe I just didn't notice it.

    First time using the debugger too (and everything else showed on the main screen which is I think where I was looking for it).

    Thanks very much for checking!

  • Wow, thanks guys.

    That's really funny, but yeah I thought they would be a shortcut to a zillion things.

  • Really? Maybe I'm doing something wrong. Why the heck would I not see it in the debugger? Screenshot maybe?

    Thank you for replying btw.

    On an unrelated note, how would I pick 4 random non-repeated values out of that list? (NVM, just figured this out! )

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi, all.

    I read what I could find on arrays on the official Construct 2 threads and I still can't figure out why my capx doesn't work. The array doesn't even show in the debugger.

    The simpler ones do, when filled manually with lists.

    I'm trying to fill a 1D array with this list of 96 values:

    20 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400 420 440 460 480 500 520 540 560 580 600 620 640 660 680 700 720 740 760 780 800 820 840 860 880 900 920 940 960 980 1000 1020 1040 1060 1080 1100 1120 1140 1160 1180 1200 1220 1240 1260 1280 1300 1320 1340 1360 1380 1400 1420 1440 1460 1480 1500 1520 1540 1560 1580 1600 1620 1640 1660 1680 1700 1720 1740 1760 1780 1800 1820 1840 1860 1880 1900 1920

    Is current supposed to be in there somewhere?

    This is my first attempt to use an array.

    http://www.darksunpictures.com/public/array.capx

  • Hey, guys.

    Quick question, if any1 has the time.

    Is it possible to use a collision mask of an invisible sprite? I mean is this independent of the actual image?

    All I really need is a rectangle for detection, so if the mask would not work, maybe bounding box?

    I haven't attempted to code this yet, but thinking ahead as it would be useful for something else, so setting up the AI now.

  • Yes got it to work perfectly!

    Thanx so much!

    Owe ya.

    On another note the -system-repeat- seems to have trouble with ELSE statements if you're doing a lot of different probabilities, but no problem with OR blocks.

    I may not be understanding the ELSE logic properly, but from what I read it should've been working.

    Eh, doesn't matter.

    OR works.

    Thanks again.

  • Ok, it's absolutely bizarre.

    The 1 line spawns 49 blocks, but it's not what the code is supposed to do because of some built in chance.

    But the 2 lines don't spawn all the way to the edge of the screen (same cloned group) because the code is working as intended, so it's an easy fix.

    I thought the repeat x times (without a loopindex condition to end) was creating an invisible infinite loop, but it's not based on the number of spawned blocks checked with a text variable, just 49.

    So it seems to be a bug, but the code works correctly in the multiple spawn line version, which is what I need.

    If anybody cares, the code started working correctly only after the loopindex, variable resets, and #oflinesspawned were added (now does the same thing for 1 group or 2).

    Otherwise it was counting a non-spawn because of chance as if it didn't happen at all and going to the next possible spawn (the internal loop index in the repeat) was not updating at all.

    This doesn't seem to be explained anywhere in the documentation as far as I can tell.

    -----

    Ok, I got this. Which is a bit ahead of myself

    It's not a bug. The way I had it set-up with the variable checking for whether to execute the repeat or not, it wasn't updating the variable for the condition check because I had the variable incrementation done on only 1 out of 3 possibilities, so it could go up to 49.

    What it fixed it was the variable reset on actual loop index check (it could no longer keep going up to satisfy the condition), thus doing the odds properly.

    I learned a lot

    (Sorry for the multiple posts.)

  • Ok, turns out the sequence thing is easy just by incrementing and making a new variable.

    Also, loopindex needed to be 48 like you said (forgot about the 0 thing).

    So it is spawning 2 lines for me now, but not all the way to the edge of the layout, like it did when I was just using the first spawning group for 1 horizontal line.

    Will play with it to figure it out.

    Thanks so much for the help.

AmpedRobot's avatar

AmpedRobot

Member since 4 Jul, 2013

Twitter
AmpedRobot has 1 followers

Trophy Case

  • 11-Year Club

Progress

11/44
How to earn trophies