# Sum of an array column & Excluding numbers in a random

Get help using Construct 2

### » Fri Mar 13, 2015 1:49 pm

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.
I must not fear. Fear is the mind killer.
B
10
S
1
G
1
Posts: 22
Reputation: 966

### » Fri Mar 13, 2015 2:12 pm

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.
B
17
S
3
G
3
Posts: 79
Reputation: 3,698

### » Fri Mar 13, 2015 9:25 pm

Thank you for the response @cjk with screenshots and a link. I just got home from work and will be attempting this now.
I must not fear. Fear is the mind killer.
B
10
S
1
G
1
Posts: 22
Reputation: 966