Sum of an array column & Excluding numbers in a random

  • Good Morning,

    First off, hello Scirra community! With my learning of Construct 2, I've made heavy use of Google with Construct 2 in the field and also the forums. It has helped me immensely in deciphering the logic needed to create. I've done, what I feel, a thorough search of the forums/tutorials and haven't been able to find a straight enough answer for the basics of these two problems I'm having.

    First:

    I'm trying to add all values in the (x,1) area of the array.. All values in the x width of the y=1 heighth. I want to get the sum of them to set the value of a specific variable.

    I've seen examples some where multiple actions were done containing this, but I'm unfamiliar with it and couldn't break it out.

    _________

    Second:

    Another thing I'm trying to accomplish is a command that pulls a random number. The next time the random is run, it excludes any and all numbers previously ran by it.

    Let's say I have this:

    On Left Click on Object - set Array.At(CurrentAnimation.AnimationFrame, random(0,53))

    Let's say that the random(0,53) gave us an number of 42.

    Then, the next time any of that object type/family is clicked, How do I make the random(0,53) make an exception of '43' and any other numbers if it were clicked again?

    _________

    Please let me know if this vague and I need to do a better job at explaining.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi j0hnbane

    Re: Question 2:

    the screenshot below is from a code I wrote last week for a C2 project.

    Two steps:

    1) Create a 1-d array of numbers - in the example, I'm creating "x,y" pairs to populate a grid

    2) Draw a random number from the array, and remove it. Next call to "RandomPosition" function will necessarily exclude any previously used positions.

    This technique is used (and my C2 implementation inspired by) a Unity3D tutorial:

    http://unity3d.com/learn/tutorials/projects/2d-roguelike

    I was quite surprised how easy it was to to follow a Unity tutorial while implementing it in C2.

    G.

  • Thank you for the response CJK with screenshots and a link. I just got home from work and will be attempting this now.

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