heres my dilema
i currently have 5 sprites and 5 different set co ordinates for each one to spawn into with individual behaviour scripts, however i want each sprite to spawn into one of the set co ordinate without more than one of them spawning into the same point.
so eventually each sprite will spawn into a random set co ordinate
so something like
pRandomStartingLoc = (200,100) (300,100) (400,100) so each sprite spawns into only one set of cordinates without more than one spawning into the same one
You want something like the following:
-- Random Set behavior
property pSetNum
property pMySet
On GetPropertyDescriptionList me
Props = [:]
Props[#pSetNum] = [#default:#1, #format:#integer, #Range:[#min:1, #max:5], #comment:"Choose a set."]
return Props
end GetPropertyDescriptionList
on beginSprite me
Case pSetNum of
1: pMySet = [point(200,100), point(300,100), point(400,100)]
2: pMySet = [point(200,100), point(300,100), point(400,100)]
3: pMySet = [point(200,100), point(300,100), point(400,100)]
4: pMySet = [point(200,100), point(300,100), point(400,100)]
5: pMySet = [point(200,100), point(300,100), point(400,100)]
end case
put pMySet
end beginSprite
Yes you would use one behavior for all five sprites.
You need to modify the code I wrote and add it to your behavior. And, of course each "pMySet" property in the case statement would be set to a different list of points.
The general idea is that if a set of sprites all have the same behavior but some of their properties need to be set to different values, then you use the " GetPropertyDescriptionList()" handler to set those differenct values.
I thought perhaps you were using some variation of the code Mister MUX wrote.
Here's a more complete version:
-- Random Set behavior
property pSetNum
property pMySet
property pSp
property pStartLoc
On GetBehaviorDescription me
return "Sets sprite to a random location based off a predefined set."
end GetBehaviorDescription
On GetPropertyDescriptionList me
Props = [:]
Props[#pSetNum] = [#default:#1, #format:#integer, #Range:[#min:1, #max:5], #comment:"Choose a set."]
return Props
end GetPropertyDescriptionList
on beginSprite me
pSp = Sprite(me.spriteNum)
-- get my location choice set
Case pSetNum of
-- *** Change these value to what you want *****
1: pMySet = [point(200,100), point(300,100), point(400,100)]
2: pMySet = [point(100,200), point(500,105)]
3: pMySet = [point(50,70), point(478,387)]
4: pMySet = [point(400,500), point(623,245)]
5: pMySet = [point(600,400), point(284,470)]
end case
pSp.loc = pMySet[random(pMySet.count)] -- set my location
pStartLoc = pSp.loc -- store current location in case you want to return to it
end beginSprite
on goToStartLoc me
pSp.loc = pStartLoc
end
thanks this worked for the spawning however they can still spawn into the same co ordinates?
eg i tried with 2 sprites
1: pMySet = [point(100,200), point(500,105)]
2: pMySet = [point(100,200), point(500,105)]
however set 1 and set 2 sprites still sometimes spawn into the same co ordinate? i want only one sprite in one co ordinate at a time
I'm not sure what you want. Is this closer?
-- Random Set behavior
property pPosNum
property pSp
property pStartLoc
On GetBehaviorDescription me
return "Sets sprite to a random location based off a predefined set."
end GetBehaviorDescription
On GetPropertyDescriptionList me
Props = [:]
Props[#pPosNum] = [#default:#1, #format:#integer, #Range:[#min:1, #max:5], #comment:"Choose a set."]
return Props
end GetPropertyDescriptionList
on beginSprite me
pSp = Sprite(me.spriteNum)
pSp.loc = [point(200,100), point(300,100), point(400,100), point(500,100), point(600,100)][pPosNum] -- set my location
pStartLoc = pSp.loc -- store current location in case you want to return to it
end beginSprite
on goToStartLoc me
pSp.loc = pStartLoc
end
Okay fourth time may be the charm.
This behavior contains a Single Locations list that is global to all sprites with this behavior attached. Each sprite picks a random loc from the list and then deletes that value from the list so that no other sprite can use it.
Note: This uses some advanced Lingo, but you should only need to replace the point values in the list of point values.
-- Random Set behavior
property pSp -- this sprite
property pStartLoc -- this sprites location at beginsprite
-- global/static behavior property
property curLocs -- list of sprite locations used by ALL sprites with this behavior attached
on beginSprite me
-- define our quasi global locations list if it is not defined or is empty
if me.script.curLocs.voidP OR me.script.curLocs = [] then
me.script.curLocs = [point(200,100), point(300,100), point(400,100), point(500,100), point(600,100)] -- Define Sprite Locs Here
end if
Locs = me.script.curLocs
pSp = Sprite(me.spriteNum)
pSp.loc = Locs[random(Locs.count)] -- set my location to random point from list
Locs.deleteOne(pSp.loc) -- remove this Loc from list so that no other sprite can use it.
pStartLoc = pSp.loc -- store current location in case you want to return to it
-- debug code. Check message window
put "Sprite " & me.spriteNum & " is at location " & pSp.loc
end beginSprite
on goToStartLoc me
pSp.loc = pStartLoc
end
on endSprite me
me.script.curLocs = void
end
on reset me
me.endSprite()
me.beginSprite()
end
tried this with 2 objects using points [point(200,100), point(300,100)]
didnt work again, the objects were able to spawn at the same co ordinates
eg object 1 and object 2 both spawned at 200,100 when only one of them should have, then the other should have spawned at 300,100
EDIT IGNORE IT WORKED ![]()
pStartLoc holds the starting location point and you can use that to modify the code, or you can just call the goToStartLoc() handler. As in:
sprite(5).goToStartLoc()
sendAllSprites(#goToStartLoc)
Delete the "reset()" handler above. It will not work correctly. I would delete it from the forum but the forum won't let me at the moment.
I used the code above "sprite(5)goToStartLoc()" but changed the 5 to ch so I can have a universal code for all the cast members I am using, I used it to try make them respawn but they all respawned back onto the random coordinate it was assigned to i.e all to (300,100). I want it so a member who was at (400,200) will return to that exact coordinate and another member for example at (600,400) with return to that exact coordinate.
Any help will be appreciated.
sendAllSprites(#goToStartLoc)
this just sent all the sprites back to one random co ordinate, i want each sprite to return back to its each individual random cordinate that we used in the example code above
eg using your code before
me.script.curLocs = [point(200,100), point(300,100)]
if sprite 1 spawns at (200,100), sprite 2 spawns at (300,100). im creating a dragging game so if i drag the sprite 1 to a wrong location i want sprite 1 to return back to (200,100), however as you know sprite 1 could also spawn at (300,100) next time. so basically i want whatever random co cordinate the sprite spawns at the start, for it to return to that same given co cordinate if a given action occurs
North America
Europe, Middle East and Africa
Asia Pacific