Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: barefoot on Wed 04/05/2011 11:22:34

Title: Trying to stop character's having a collision event after inventory used.
Post by: barefoot on Wed 04/05/2011 11:22:34
Hi

I'm trying to work out what would be the most efficient way to stop character's having a collision event.

I already have in rep execute:


if (cskeleton1.IsCollidingWithChar(cwizard2) == 1)



cskeleton1 changes to an animation and then to view 55 after an inventory (ifireball) is used on it.. and colllisions work fine.   So far so good.

I am trying to then put if colliding make it ==0.  Because at the moment if the main char goes near cskeleton1 the collision events happen when it should not (some text said and score adjusted);

I have this in Rep execute:

{

if (cskeleton1.IsCollidingWithChar(cwizard2) == 1)

{

 cwizard2.Say("Aghhh!!");
GiveScore (-1);
 SetGlobalInt (1, 100);
cwizard2.Walk(cwizard2.x + 20, cwizard2.y +0, eBlock, eAnywhere);
{


And this when Inv is used:


function cskeleton1_UseInv()
{
if (player.ActiveInventory==ifireball){

player.ActiveInventory=null;
cskeleton1.ManualScaling=true;
cskeleton1.Scaling=28;
cskeleton1.ChangeView(54);
cskeleton1.Animate(0, 5, 0, eBlock, eBackwards);
cskeleton1.UnlockView();
cskeleton1.ChangeView(55);
cskeleton1.FollowCharacter(null);
Display("The skeleton is now burnt to a crisp and lifeless!");

 }


Hope this is understandable though I'm certain the solution may well be simple yet been overlooked.

cheers

barefoot








Title: Re: Trying to stop character's having a collision event after inventory used.
Post by: Khris on Wed 04/05/2011 11:40:20
Both functions are inside the global script, so just put this at the top of Global.asc:
bool skeleton_alive = true;

Then use:
if (cskeleton1.IsCollidingWithChar(cwizard2) && skeleton_alive)  // you don't need ==1

Then add this to your UseInv/fireball block:
  skeleton_alive = false;

And please, please bookmark this or one of your other ten "you need a variable" threads. :=
Title: Re: Trying to stop character's having a collision event after inventory used.
Post by: barefoot on Wed 04/05/2011 11:45:45
Hi Khris

It certainly is in my top ten now....... I already had one in the Global already...

How could I not remember.. I will now...

Thanks so much Khris

:=

barefoot




Title: Re: Trying to stop character's having a collision event after inventory used.
Post by: barefoot on Thu 05/05/2011 11:26:05
Hi Khris

script error says: Failed to save room room30.crm; details below
room30.asc(148): Error (line 148): undefined symbol 'skeleton_alive'

that line is the collision script rep exec:

if (cskeleton1.IsCollidingWithChar(cwizard2) && skeleton_alive)

Have also declared it in Global as instructed top part and when inv used.

barefoot



Title: Re: Trying to stop character's having a collision event after inventory used.
Post by: Khris on Thu 05/05/2011 11:45:53
Oh, you're doing this inside a room script?
Then you have to make it an actual global variable.

Remove the "bool skeleton_alive = true;" line from the global script and create the variable using the Global variables pane.
Title: Re: Trying to stop character's having a collision event after inventory used.
Post by: barefoot on Thu 05/05/2011 11:53:22
Hi Khris

Yes, just the one room.

I created Variable in pane and it now works as it should..

I can use this type of variable for a number of things now.

Many many thanks

:=

barefoot