Ask a Question related to Macromedia Director Lingo, Design and Development.
-
irwhistle webforumsuser@macromedia.com #1
To many intersect scripts make Macro a sad panda
Hello there,
I'm trying to create a 2d game. To prevent my 'player' from walking through objects I am using intersect scripts like the following :
if sprite (18) intersects sprite mySprite then
sprite (18) .locH = sprite (18) .locH -10
This for example is the script to prevent the 'player' from entering from the left. I made a script for this and attached it to all objects that shouldn't be passed through the left.
I have seperate scripts for the right, top and bottom.
Each script is attached to the objects they belong to. However... after placing these scripts on about 20 occasions I start receiving errors.
--> script error. Sprite number wrong. <--
As soon as I delete the latest attached sprite it works fine again. I don't know what the problem here is, but I figured I might prevent this by using a connector script in which I can define a list of sprites to which each script applies.
for example, like this
---- Connector script-----
on beginsprite me
set mysprite to the spritenum of me
set cbob to 18 -- sprite channel number of 'player' bob
set cbill to 19 -- sprite channel number of 'player' bill
set tblock to [23, 30, 31, 33] -- the sprite channels that should be handled with a top intersect script
set bblock to [26, 27, 28, 29, 32, 33] -- the sprite channels that should be used in ....
set rblock to [21,25,35,36,37,38,39,41] -- etc...
set lblock to [22,23] -- etc...
sendallsprites #storeShared, [#bob:cbob,#bill:cbill,#topBlock:tblock,#bottomBloc k:bblock,#rightBlock:rblock,#leftBlock:lblock]
end
--- intersect scripts--- I was planning on attaching this script to the 'player' sprites Bob and Bill
---instead of to all objects that they weren't supposed to pass. thus reducing the number of
---scripts
---from many to just 2...
property mySprite
property bob -- de sprite van Bob
property bill -- de sprite van Bill
property topBlock
property bottomBlock
property leftBlock
property rightBlock
on beginsprite me
set mySprite to the spritenum of me
end
on storeShared me, gameSprites
set bob to the bob of gamesprites -- bobs channel in de score, opgehaald in connection script
set bill to the bill of gameSprites -- idem, maar dan voor Bill
set topBlock to the topblock or gameSprites
set bottomBlock to the bottomBlock of gameSprites
set leftBlock to the leftBlock of gameSprites
set rightBlock to the rightBlock of gameSprites
end
on exitframe me
if sprite bob intersects sprite leftBlock then --- sprite leftBlock should, the way i thought it would, make sure that every sprite defined in the connector script as lBlock, in this case [22,23]
sprite (bob) .locH = sprite (bob) .locH -10
end if
if sprite bill intersects sprite leftBlock then
sprite (bill).locH = sprite (bill) .locH -10
end if
--- repeat for top, bottom and right intersects ---
end
Would anybody know either a: why I can't use my intersect scripts in a lot of different sprites
or b: how I can create but one script in which I make sure all the appropriate sprites are effected...
Thanks for taking your time to even read through this...
irwhistle webforumsuser@macromedia.com Guest
-
intersect or hit test
hi in sprite 1 i am using one swf as a sprite member which has different movieclips which are moving inside the swf. should i check the hit test or... -
Two UNION's and an INTERSECT?
Anthony Presley wrote: > Jonathan Leffler <net> wrote in message > news:<bUttb.1339$news.pas.earthlink.net>... > > > >> >>>userData: >> >>>... -
intersect sprites on still down: how?
I am creating an interactive timeline. I have a scrollbar with a thumb and another sprite (the hotspot) Now, what I want to do is while the thumb... -
Help! Sprite Intersect?
Good Morning All, Having significant trouble with Sprite Intersect. Basically, all I need to happen is for a sound to play when a draggable... -
Makefile: set macro once (Solaris make, GNU make)
Hello, I have a question on a problem that is disturbing me for some time now. I want to set a variable in a Makefile by calling a shell... -
hairybobby webforumsuser@macromedia.com #2
Re:question about using a lists to define multiple sprites in a script
well there is a lot to work through there
I cannot provide the answer but one thing you have done is to hard code the sprite numbers. eg sprites 18 and 19. Its easy to then accidently move these sprites. Check on the score to see if they are still in the same position. the same goes for the sprites which need to intersect.
HAIRYBOBBY - why didn't I choose a really cool name like the vulcanpimp
[url]http://www.geocities.com/hairybobby2000[/url]
Photography section
[url]http://www.geocities.com/hairybobby2000/px1.html[/url]
Photoshop section
[url]http://www.geocities.com/hairybobby2000/photo1.html[/url]
hairybobby webforumsuser@macromedia.com Guest
-
irwhistle webforumsuser@macromedia.com #3
Re:question about using a lists to define multiple sprites in a script
Nope, I fear that isn't it.
The example code was hard coded but in the script itself i'm setting properties like in the second example.
property bob
property bill
on beginsprite
set property bob **
set property bill **
The code works fine until I use it for the 20 somethingth time. Might it be that i'm using the same script on to many different sprites?
Thanks anyway.
irwhistle webforumsuser@macromedia.com Guest
-
Robert Tweed #4
Re: Re:question about using a lists to define multiple sprites in a script
"irwhistle" <webforumsuser@macromedia.com> wrote in message
news:bi7vtq$dpt$1@forums.macromedia.com...I suggest you post the *actual* script you're using as this will save people>
> The example code was hard coded but in the script itself i'm setting
> properties like in the second example.
guessing what might be wrong without being able to see.
- Robert
Robert Tweed Guest
-
irwhistle webforumsuser@macromedia.com #5
Re:question about using a lists to define multiple sprites in a script
SOLVED!!!! YIHAA!!!!
For those even remotely interested. I found the problem.
It turned out the reason my script didn't work after a certain sprite was because of the connector script I used.
The connector script where I had placed all the definitions of my properties was located in Sprite Frame 72. When I started using it all sprites between 23 and 72 had been empty so I had at that time enough room to work in. However, after placing more and more sprites suddenly some scripts were placed in sprite frame 73 and +, and since the connector script needs to be the last script used all scripts beyond 72 didn't connect properly. I'v placed the connector scipt in spriteframe 150 now so I should be able to work fine from now on. Phew... what a way to solve a problem a day before the deadline.
So for those ever encountering such a problem.
Make sure your connection scripts are LAST in line! :)
irwhistle webforumsuser@macromedia.com Guest
-
Roofy webforumsuser@macromedia.com #6
Re:question about using a lists to define multiple sprites in a script
sendAllSprites has no hiearchy rules on the score this is why we, or atleast me, where confused about. Meaning at the time before you figured this out, your script looked perfectly fine. HOWEVER, what was causing this was because you where tring to initialize all of the sprites before some of the evened called on beginSprite. For example,
Here is an example of why sendAllSprites would work in any sprite channel...
lets say you attach this script to sprite channel 1, and this script would be for allowing the user to drag sprite 1. Then on mouseUp, checks if the user is placeing sprite 1 onto another sprite by calling sendAllSprites with the #didItCollide. Then if any other sprites have the #didItCollide, will check if sprite 1 did collide and if so, then it will display an alert message "sprite 1 collided with such and such sprite".
-- this is the script that has the command sendAllSprites(#didItCollide) which is in sprite channel 1
property pSprite
property pDrag
property pOffset
property sp
on beginSprite me
sp = sprite(me.spriteNum)
pDrag = FALSE
end
on mouseDown
pOffset = the mouseloc - sp.loc
pDrag = TRUE
end mouseUp
on mouseUp
if not pDrag then exit
pDrag = FALSE
sendAllSprites(#didItCollide)
end mouseUp
on mouseUpOutside me
mouseUp(me)
end mouseUpOutside
on exitFrame
if pDrag then
sp.loc = the mouseLoc - pOffset
end if
end exitFrame
.... and this is the script that has the #didItCollide whicb is attached to sprite channel 2
on didItCollide me
if sprite(1).intersects(sprite(me.spriteNum)) then
alert "Sprite 1 has collided with sprite" && me.spriteNum
end if
end didItCollide
and then I added a frame script to have the frame loop like this...
on exitFrame
go to the frame
end exitFrame
as you can see sendAllsprites(#didItCollide) was not called inside of on beginSprite, and thats why hiearchy wouldn't matter.
Roofy webforumsuser@macromedia.com Guest



Reply With Quote

