Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Understanding Code

New Here ,
Feb 24, 2017 Feb 24, 2017

I was given this piece of code and am trying to understand it as best as I can. I have ran the code and understand what it does, but there are a few lines which I do not know how to explain.

RXtYlem.png

Here is what I have come up with so far:

In line 1 of the code shown, we have created a new Array called “theElements”. It contains 5 different elements named “Earth, Wind, Fire, Water & Ether.”

In line 2 of the code, we are creating a variable with a String function, however this line of code seems to be an error that was left in to the code as “element” does not feature within our code again. This line of code was used in a previous example and had been forgotten to be removed. We can successfully run the piece of code without any errors if we remove this line.

In line 3 of the code, we create a variable called “numberOfRoles” and give this a 10 value.

In line 5 of the code, we pull the Array “theElements” and  variable “numberOfRoles” and use them as attributes, while naming them both as “roleThem

In line 7 of the code, we create a function and use roleThem

In line 9 we use the while loop, which will repeat as long as the statement “numberOfRoles > 0” is true.

In line 12 we check that our variable “numberOfRoles” is always equal.

I am stuck on Line 10/11 and 16-19. I know that lines 16-19 pick 10 of the elements at random and display then which you can see, however I do not know how to explain it in the correct manner. I am still learning the basics of Actionscript so any help would be much appreciated.

Edit: Excuse my forum name lmao

TOPICS
ActionScript
227
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2017 Feb 24, 2017

that code's not going to anything other than trace an element from an array.  and there are better ways to do that.

anyway, what are you trying to do?  pick random array elements with repeats or pick random array elements without repeats?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 24, 2017 Feb 24, 2017

Not trying to do anything, the code works/runs just fine. It picks 10 random array elements (with repeats) and outputs them.

I just wanted help understanding each line of the code, particularly the ones I mentioned at the bottom of my post.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2017 Feb 24, 2017
LATEST

line 10 calls role() and line 11 traces it to the output panel.

lines 16-21 define a function (role) that creates a random number between 0 and yourarray length less 1 and uses that to return a yourarray element with that (randomly selected) index.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines