# 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. ## 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. ## 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
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

old = nextEntry
i = i + 1
end repeat
put stackSprites
end

David.

David Downie Guest

3. ## 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. ## 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
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. ## 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
> 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. ## 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. ## 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
else
add tempStack, stackSprites[i + (7 * (stack - 1))] + 1
end if
end repeat
end repeat

Roofy webforumsuser@macromedia.com Guest

#### Posting Permissions

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