Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gabarts on Sun 15/06/2014 15:43:44

Title: Calling Object from Global Script {Solved}
Post by: Gabarts on Sun 15/06/2014 15:43:44
It's first time I try to animate an object. But I need to operate from the Global Script since it's inside a character interaction.

It gives me Undefined token oEffetto1

Here part of the code I have:

Code (ags) Select
cGabbiano.UnlockView();
       Wait(40);
       oEffetto1.Visible = true;
       oEffetto1.SetView(38);
       oEffetto1.Animate(0, 4, eRepeat, eBlock, eForwards);
       Wait(60);
       oEffetto1.Visible = false;
       aGabbiano.Play();
       cGabbiano.Walk(220, 45, eBlock, eAnywhere);


I've tried using the object[0] ID but cannot find how to call from global script. I've used once to call from inside a dialog and it works but here it's the first time I face this error.
Title: Re: Calling Object from Global Script
Post by: Adeel on Sun 15/06/2014 17:11:40
Globally, the objects are referenced with their IDs, not by their names.

Code (ags) Select
cGabbiano.UnlockView();
       Wait(40);
       object[0].Visible = true;
       object[0].SetView(38);
       object[0].Animate(0, 4, eRepeat, eBlock, eForwards);
       Wait(60);
       oEffetto1.Visible = false;
       aGabbiano.Play();
       cGabbiano.Walk(220, 45, eBlock, eAnywhere);


Have you tried using the above code? Also, are you sure that the id of object oEffetto1 is ZERO (0)?
Title: Re: Calling Object from Global Script
Post by: Gabarts on Sun 15/06/2014 17:27:17
I have to check. I've tried using object[0] since I've already used for another script but maybe I've missed something.

If you use object[ID] inside a function it always search for the object inside the relative room?

Thanks for reply.
Title: Re: Calling Object from Global Script
Post by: Adeel on Sun 15/06/2014 17:46:00
Quote from: Gabarts on Sun 15/06/2014 17:27:17
I have to check. I've tried using object[0] since I've already used for another script but maybe I've missed something.

Each created object has its own unique ID. Hence using object[0] for the object whose ID is 1 will, obviously, won't help. My example will work only, if the ID of oEffeto1 is ZERO (0).

Quote from: Gabarts on Sun 15/06/2014 17:27:17
If you use object[ID] inside a function it always search for the object inside the relative room?

Yes, you understood correct!

Quote from: Gabarts on Sun 15/06/2014 17:27:17
Thanks for reply.

My pleasure. :)
Title: Re: Calling Object from Global Script {Solved}
Post by: Gabarts on Sun 15/06/2014 20:27:08
Thanks again for the clarification.

I simply typed Object[0] instead of object[0]. etc etc
AGS has also the auto-coding function, I could make some tries before asking for help... :-X
Anyway, I learned it.
Title: Re: Calling Object from Global Script {Solved}
Post by: Khris on Sun 15/06/2014 21:36:10
Yeah, convention says that capital names are Class names, while variables are lowercase.
Title: Re: Calling Object from Global Script {Solved}
Post by: Adeel on Mon 16/06/2014 13:25:48
Quote from: Gabarts on Sun 15/06/2014 20:27:08
I simply typed Object[0] instead of object[0]. etc etc

It happens, Gabarts... It happens to the best of us. You're not alone. :)