I have a for loop, I need this working asap so help is greatly appreciated. I need to spawn one or both of two sprites on top of every instance that's in the family "Segments". Here's the setup I have:
For every Segment
->check if the Collision instance variable is < 900 and if SegmentCollision (a local variable meant to stop the loop) is less than the max value
-->check if the amount of image points is 2 or 3
----> if 2, spawn one Platform Collision and set its animation frame to the Segment's Collision instance variable
----> if 3, spawn one Platform Collision and one Platform Collision and set both their animation frames to the Segment's Collision variable
That's all I want it to do, check what to spawn, spawn it, then set its frame to the Segment's instance variable. It just has to do it once for each segment. Can anyone help?
Develop games in your browser. Powerful, performant & highly capable.
I'm not sure I quite understand what aspects of the code are currently not working.
The first thing I notice that might be an issue is that in your last two events, there is no icon for either the PlatformCollision object, or the PlatformCollision2 object. I don't know if that's indicative of a problem, but it might shed some light on what's going on.
In particular, in the "Set animation" actions, it looks like there's no way to visually tell which object is being acted on. I assume they should be PlatformCollision and then PlatformCollision2, but if they're not, that might be causing a problem.
It looks like every object in the Segments family has a private var named "collision", just out of curiosity, what does it do, and what would cause it to be greater than 900?
The PlatformCollision objects are blank sprites, that's why there isn't an icon. The part that isn't working is that the for loop doesn't stop and I'm not sure that it's actually spawning the PlatformCollision objects like it should. It seems to be spawning them, but I don't think it's actually spawning them at the right coordinates, is there some way I can assure that when I tell it to spawn at Segments.ImagePointX(1) that it's choosing the image point from the segment currently in the loop?
One method that can be really handy for diagnosing these kinds of problems is to create a Text object, and then create an event inside the loop to print debuging info into that Text object.
Insert the following event as a sub-event of the
"Segments.ImagePointCount = 2", and
"Segments.ImagePointCount = 3".
* Compare ( loopindex >= 0 )
* Compare ( loopindex <= 3 )
// This event will run 4 times, for the loop indexes 0, 1, 2, and 3.
* Append text ( " Loopindex:" & loopindex )
* Append text ( " SegUID:" & Segments.UID )
* Append text ( " platUID:" & PlatformCollision.UID )
* Append text ( " plat2UID:" & PlatformCollision2.UID ) // Only needed for count = 3
* Append text ( " Seg.ImgPtX1" & Segments.ImagePointX(1) )
* Append text ( " Seg.ImgPtY1" & Segments.ImagePointY(1) )
* Append text ( " Seg.ImgPtX2" & Segments.ImagePointX(2) ) // Only needed for count = 3
* Append text ( " Seg.ImgPtY2" & Segments.ImagePointY(2) ) // Only needed for count = 3
* Append text ( " Seg.Col:" & Segments.Collision)
* Append text ( newline )
The "newline" at the end will make each loop iteration print out on it's own line.
Be sure to use "Append text" and NOT "Set text".
Note that some of the actions in the above event only apply to the case where "Segments.ImagePointCount = 3", and not when it "= 2". For the "= 2" case, you can remove all the actions that are commented "// Only needed for count = 3".
You'll probably have to stretch out the text object so that it has room to display multiple lines.
You may also want to set it's font size to something, small like 8 point, and set it's initial text to be blank.