Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: suicidal pencil on Wed 20/01/2010 23:25:54

Title: Object troubles (SOLVED)
Post by: suicidal pencil on Wed 20/01/2010 23:25:54
In one of my latest endeavors, I'm using objects as bullets. When a certain function is called, it should get a free object, set it's position to the top-center of the player, and change it's graphic. When the function is called, however, nothing happens. I put a 'Display()' just before the return statement at the end of the function, and it displayed, so it's running through the function, but it's not doing anything else other than that.

here's the offending function

function SetUpPlayerBullet()
{
 if(TotalBullets == 25) return 1; //need to see if the onscreen bullet cap was hit
 int FreeObject = GetUnusedObject();
 ObjectSettings[FreeObject] = 3;
 object[FreeObject].X = player.x+51;
 object[FreeObject].Y = player.y+173;
 object[FreeObject].Graphic = 11;
 BulletDirection[FreeObject] = 0;
 TotalBullets++;
 return 0;
}


and here's how I'm finding the next available object, the function being called on the 4th line.


function GetUnusedObject()
{
 int counter = 0;
 while(counter <= 39)
 {
   if(object[counter].Graphic == 0) return counter;
   else counter++;
 }
}


This has worked for me in the past for previous games...but not now for some odd reason  :-\
Title: Re: object troubles <_<
Post by: monkey0506 on Thu 21/01/2010 00:17:07
When you say it's not doing anything...what exactly does that mean?

Have you tried displaying the value of FreeObject? Try displaying various different values of your variables and see what's happening. You know the function is being called...but maybe one or more of those values isn't what you're expecting it to be...?
Title: Re: object troubles <_<
Post by: suicidal pencil on Thu 21/01/2010 00:47:45
Quote from: monkey_05_06 on Thu 21/01/2010 00:17:07
When you say it's not doing anything...what exactly does that mean?

Have you tried displaying the value of FreeObject? Try displaying various different values of your variables and see what's happening. You know the function is being called...but maybe one or more of those values isn't what you're expecting it to be...?

I checked the values at run time (FreeObject and object[FreeObject].Graphic), and they both have values that are exactly what I expected. FreeObject starts at 1 (because object 0 is already in use), and every time the function is called, the number increases by one until it hits the limit (25). The graphic is changing to the correct sprite, but the sprite does not appear.

So, the function is working correctly, but the object is not being displayed properly.

oh, and here's the sprite being used: (http://i182.photobucket.com/albums/x313/suicidal_pencil/UpBullet1.jpg)
Title: Re: object troubles <_<
Post by: monkey0506 on Thu 21/01/2010 02:15:03
Other properties I could think of to check include Transparency, X, Y, and Visible. If the values are being set as expected then I can't think of any reason why it shouldn't be showing up as expected unless something else has gone amiss.
Title: Re: object troubles <_<
Post by: Ryan Timothy B on Thu 21/01/2010 05:12:03
For testing purposes since you seem to be having problems, I'd make sprite number 0 a visible sprite and align all the objects in a visible row in the room, then when the function is called, see if any of the objects in the row move to the correct place or if they disappear.  They could be moving off-screen.

Edit: Actually it probably is moving off-screen.  You wrote: "set it's position to the top-center of the player", but you're doing: object[FreeObject].Y = player.y+173, which would be under the character.  Try player.y-173.  Also it could be appearing behind a walkbehind. :P
Title: Re: object troubles <_<
Post by: Khris on Thu 21/01/2010 09:01:32
Also, x-centered should probably be:

  object[FreeObject].X = player.x-5;

(Character's are displayed centered at their x coordinate while the object sprite's width is 10.)
Title: Re: object troubles <_<
Post by: suicidal pencil on Thu 21/01/2010 13:20:52
Quote from: Khris on Thu 21/01/2010 09:01:32
(Character's are displayed centered at their x coordinate while the object sprite's width is 10.)

While not what was being looked for, you still helped me out. Characters aren't actually used in my game, everything is done with objects. In the code, I'm moving the bullet objects to the unused player character, instead of the object representing the player.

what the problem is:

object[FreeObject].X = player.x+51;
object[FreeObject].Y = player.y+173;


and the solution

object[FreeObject].X = object[0].X+51;
object[FreeObject].Y = object[0].Y+173;


Thanks for the help! ;D (oh, and as it turns out, the top-center of the object is (51, -173). Thanks Tim