Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Rolando on Thu 20/06/2013 14:30:36

Title: Store a sound in a variable
Post by: Rolando on Thu 20/06/2013 14:30:36
Hello everyone!, this is my first post so i apologize if this was asked before (wich i guess it was). Im finishing my first game demo and im working on sounds. I need to store a sound in a variable for playing it later but i cant find how to do this.

I need something like..

SoundTypeVar s1;
s1 = soundstored;
s1.play();

Thank you very much.
Title: Re: Store a sound in a variable
Post by: Phemar on Thu 20/06/2013 15:05:21
Code (ags) Select
AudioClip * sound = aSound1;
AudioChannel * ac = sound.Play ();
Title: Re: Store a sound in a variable
Post by: Rolando on Thu 20/06/2013 15:23:41
Thank you very much Phemar, it works great. Just one question: what is the '*' before the variable name for????
Title: Re: Store a sound in a variable
Post by: Crimson Wizard on Thu 20/06/2013 15:45:17
Quote from: Rolando on Thu 20/06/2013 15:23:41
Thank you very much Phemar, it works great. Just one question: what is the '*' before the variable name for????

That's pointer.
Related manual article, strongly recommended for reading:
http://www.adventuregamestudio.co.uk/wiki/Pointers_in_AGS
Title: Re: Store a sound in a variable
Post by: Rolando on Thu 20/06/2013 15:56:13
Thanks a lot Crimson! I never got into pointers, i definitly have to read that!
Title: Re: Store a sound in a variable
Post by: Crimson Wizard on Thu 20/06/2013 16:00:42
Pointer is like an arrow sign on the road with city name on it. It points to something (like a city), but it is not a city itself.

You can change same pointer to point to different objects whenever you want. But when the program uses the pointer it does not care what object exactly it points to, it just takes whatever is there. This allows to run same commands with different objects.