Professional Web Applications Themes

math question - Macromedia Director Lingo

Hi there, I was wondering if there is a math equation that I could get these results into the linear list stackSprites so that I can create a repeat loop instead of all of these add handlers. If any of you could take a moment and see if you can come up with a repeat loop, I would greatly appeciate it. I tried doing a repeat loop but couldn't figure out how I could add the zeros. on beginSprite me stackSprites = [] add stackSprites, [8, 22, 37, 53, 70, 88, 107] add stackSprites, [0, 23, 38, 54, 71, 89, ...

  1. #1

    Default math question

    Hi there,
    I was wondering if there is a math equation that I could get these results into the linear list stackSprites so that I can create a repeat loop instead of all of these add handlers. If any of you could take a moment and see if you can come up with a repeat loop, I would greatly appeciate it. I tried doing a repeat loop but couldn't figure out how I could add the zeros.

    on beginSprite me
    stackSprites = []
    add stackSprites, [8, 22, 37, 53, 70, 88, 107]
    add stackSprites, [0, 23, 38, 54, 71, 89, 108]
    add stackSprites, [0, 0, 39, 55, 72, 90, 109]
    add stackSprites, [0, 0, 0, 56, 73, 91, 110]
    add stackSprites, [0, 0, 0, 0, 74, 92, 111]
    add stackSprites, [0, 0, 0, 0, 0, 93, 112]
    add stackSprites, [0, 0, 0, 0, 0, 0, 113]

    end beginSprite




    Roofy webforumsuser@macromedia.com Guest

  2. #2

    Default Re: math question


    "Roofy" <webforumsusermacromedia.com> wrote in message
    news:bfo266$i8$1forums.macromedia.com...
    > Hi there,
    > I was wondering if there is a math equation that I could get these results
    into the linear list stackSprites so that I can create a repeat loop instead
    of all of these add handlers. If any of you could take a moment and see if
    you can come up with a repeat loop, I would greatly appeciate it. I tried
    doing a repeat loop but couldn't figure out how I could add the zeros.
    >
    > on beginSprite me
    > stackSprites = []
    > add stackSprites, [8, 22, 37, 53, 70, 88, 107]
    > add stackSprites, [0, 23, 38, 54, 71, 89, 108]
    > add stackSprites, [0, 0, 39, 55, 72, 90, 109]
    > add stackSprites, [0, 0, 0, 56, 73, 91, 110]
    > add stackSprites, [0, 0, 0, 0, 74, 92, 111]
    > add stackSprites, [0, 0, 0, 0, 0, 93, 112]
    > add stackSprites, [0, 0, 0, 0, 0, 0, 113]
    >
    > end beginSprite
    Hi
    I'm not a maths person. Is there any way of deriving the results in the
    first array? Anyway, assuming there isn't, what about something like this:

    on doit me
    stackSprites = []
    old = [8, 22, 37, 53, 70, 88, 107]
    sizeOld = old.count
    stackSprites.add(old)
    i = 1
    repeat while i <= 6
    nextEntry = []
    j = 1
    repeat while j <= i
    nextEntry[j] = 0
    j = j + 1
    end repeat

    -- now fill in the rest
    j = nextEntry.count + 1
    repeat while j <= sizeOld
    nextEntry[j] = old[j] + 1
    j = j + 1
    end repeat

    stackSprites.add( nextEntry )
    old = nextEntry
    i = i + 1
    end repeat
    put stackSprites
    end

    David.


    David Downie Guest

  3. #3

    Default Re: math question

    I can see the pattern in the first line now 8 + 14 + 15 + 16 etc. So you
    could use that to do the first list. But I don't see the point. is this an
    exercise.

    "Roofy" <webforumsusermacromedia.com> wrote in message
    news:bfo266$i8$1forums.macromedia.com...
    > Hi there,
    > I was wondering if there is a math equation that I could get these results
    into the linear list stackSprites so that I can create a repeat loop instead
    of all of these add handlers. If any of you could take a moment and see if
    you can come up with a repeat loop, I would greatly appeciate it. I tried
    doing a repeat loop but couldn't figure out how I could add the zeros.
    >
    > on beginSprite me
    > stackSprites = []
    > add stackSprites, [8, 22, 37, 53, 70, 88, 107]
    > add stackSprites, [0, 23, 38, 54, 71, 89, 108]
    > add stackSprites, [0, 0, 39, 55, 72, 90, 109]
    > add stackSprites, [0, 0, 0, 56, 73, 91, 110]
    > add stackSprites, [0, 0, 0, 0, 74, 92, 111]
    > add stackSprites, [0, 0, 0, 0, 0, 93, 112]
    > add stackSprites, [0, 0, 0, 0, 0, 0, 113]
    >
    > end beginSprite
    >
    >
    >
    >

    David Downie Guest

  4. #4

    Default Re: math question

    Yes, but it's not pretty:-

    on makeList
    a=[8, 22, 37, 53, 70, 88, 107]
    out=[]
    n=count(a)
    j=1
    repeat with i=1 to n
    b=[]
    repeat with k=j to n
    b[k]=a[k]+j-1
    end repeat
    add out, b
    j=j+1
    end repeat
    return out
    end makeList

    put makelist()
    -- [[8, 22, 37, 53, 70, 88, 107], [0, 23, 38, 54, 71, 89, 108], [0, 0, 39, 55,
    72, 90, 109], [0, 0, 0, 56, 73, 91, 110], [0, 0, 0, 0, 74, 92, 111], [0, 0, 0,
    0, 0, 93, 112], [0, 0, 0, 0, 0, 0, 113]]

    You're better off the way you've done it - it's more readable and it's faster.
    Unless you want to extend the pattern to much longer lists.

    Andrew Morton

    Andrew Morton Guest

  5. #5

    Default Re: math question

    Can you assume the uninitalised values of the arrays are 0? I had a quick
    look in my books and couldn't see it. I know it seems to be that way, but
    can it be relied on?
    David

    "Andrew Morton" <akmin-press.co.uk.invalid> wrote in message
    news:bfo3m3$31d$1forums.macromedia.com...
    > Yes, but it's not pretty:-
    >
    > on makeList
    > a=[8, 22, 37, 53, 70, 88, 107]
    > out=[]
    > n=count(a)
    > j=1
    > repeat with i=1 to n
    > b=[]
    > repeat with k=j to n
    > b[k]=a[k]+j-1
    > end repeat
    > add out, b
    > j=j+1
    > end repeat
    > return out
    > end makeList
    >
    > put makelist()
    > -- [[8, 22, 37, 53, 70, 88, 107], [0, 23, 38, 54, 71, 89, 108], [0, 0, 39,
    55,
    > 72, 90, 109], [0, 0, 0, 56, 73, 91, 110], [0, 0, 0, 0, 74, 92, 111], [0,
    0, 0,
    > 0, 0, 93, 112], [0, 0, 0, 0, 0, 0, 113]]
    >
    > You're better off the way you've done it - it's more readable and it's
    faster.
    > Unless you want to extend the pattern to much longer lists.
    >
    > Andrew Morton
    >

    David Downie Guest

  6. #6

    Default Re: math question

    > Can you assume the uninitalised values of the arrays are 0? I had a quick
    > look in my books and couldn't see it. I know it seems to be that way, but
    > can it be relied on?
    Yes; it is in the docs somewhere.

    Andrew
    Andrew Morton Guest

  7. #7

    Default Re: math question

    I figured it out, and if it is a little slower, I don't think that it matters much since it is done on beginSprite which is just an initializer. Any way for any of you that are currious, I created this list so that I can mulltiple that position in the linear list to 80.

    for example using this list...
    stackSprites = []
    add stackSprites, [8, 22, 37, 53, 70, 88, 107]
    add stackSprites, [0, 23, 38, 54, 71, 89, 108]
    add stackSprites, [0, 0, 39, 55, 72, 90, 109]
    add stackSprites, [0, 0, 0, 56, 73, 91, 110]
    add stackSprites, [0, 0, 0, 0, 74, 92, 111]
    add stackSprites, [0, 0, 0, 0, 0, 93, 112]
    add stackSprites, [0, 0, 0, 0, 0, 0, 113]

    I can then find the position in the list to which sprite this handler is currently on by doing this line of code...

    myPos = getPos(stackSprites, me.spriteNum)


    then I can take myPos add 1 to it and then multiply that by 80 and that would be the total distance that the sprite needs to move from point a to point b like this...

    pDistance = (myPos + 1) * 80



    However, I found out that I can add the stackSprites in a loop by doing this

    stackSprites = [8, 22, 37, 53, 70, 88, 107]

    repeat with stack = 1 to 7
    tempStack = []
    repeat with i = 1 to 7
    if i <= stack then
    add tempStack, 0
    else
    add tempStack, stackSprites[i + (7 * (stack - 1))] + 1
    end if
    end repeat
    add stackSprite, tempStack
    end repeat



    Roofy webforumsuser@macromedia.com Guest

Similar Threads

  1. Math Actionscript question
    By The_Pierre in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: March 1st, 08:37 PM
  2. math problem will Math.floor help
    By javman webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 5
    Last Post: February 4th, 01:28 AM
  3. Replies: 4
    Last Post: December 19th, 07:09 AM
  4. OT: Math help
    By Joseph D. DeJohn in forum ASP.NET General
    Replies: 2
    Last Post: August 7th, 02:52 AM
  5. Math on Tab Control
    By Nancy in forum Microsoft Access
    Replies: 1
    Last Post: July 18th, 02:46 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139