Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Hans on Sat 07/04/2007 15:16:31

Title: Reapeat/Block parts of script (HELP!)
Post by: Hans on Sat 07/04/2007 15:16:31
I would like to know if it is possible to repeat a whole part of the script or set its blocking style.
Title: Re: Reapeat/Block parts of script (HELP!)
Post by: Gilbert on Sat 07/04/2007 15:23:55
Make that part of codes a function and call it whenever needed.

Otherwise, you may need to elaborate more on what you actually need.
Title: Re: Reapeat/Block parts of script (HELP!)
Post by: Hans on Sat 07/04/2007 15:28:20
Is it possible to make a function like this:

myfunction (eRepeat);

???

If not, this won't help me.
Title: Re: Reapeat/Block parts of script (HELP!)
Post by: Gilbert on Sat 07/04/2007 15:39:32
Why not just call the function in repeatedly_execute[_always]() ?

Title: Re: Reapeat/Block parts of script (HELP!)
Post by: Mr Flibble on Sat 07/04/2007 16:41:38
Making a Function

Put this somewhere inbetween functions.

#sectionstart MyFunction
function MyFunction(){           //If you want it to return a value put something in between the brackets
/* Your code here. This could be anything, like adding inventory or playing a sound, or a set of variables being checked */
}
#sectionend MyFunction


Then in your Script Header

import function MyFunction();


And then whenever you want to use that block of code, just type

MyFunction();


Does that help? You can use functions to collect blocks of code you use a lot to make life easier.
Title: Re: Reapeat/Block parts of script (HELP!)
Post by: Hans on Sat 07/04/2007 23:00:39
That's how to make a function. But I want to be able to make the code repeat and set the blocking style.
Title: About SOUNDS, how to choose their blocking style and make them repeat. (SOLVED)
Post by: Hans on Sat 07/04/2007 23:04:38
I have a sound1.wav
I can play it with PlaySound(1);
But how do I make it repeat?
And how do I make the script wait until the sound is finished? (Blocking style)
Title: Re: About SOUNDS, how to choose their blocking style and make them repeat.
Post by: Dan_N on Sat 07/04/2007 23:27:20
Search for PlayAmbientSound in the AGS Manual, you can use that.
Title: Re: Reapeat/Block parts of script (HELP!)
Post by: JD on Sat 07/04/2007 23:30:13
What exactly is in this bit of code you want to repeat and make blocking?
Title: Re: About SOUNDS, how to choose their blocking style and make them repeat.
Post by: Hans on Sat 07/04/2007 23:34:46
I'll do that. Thank you!
Title: Re: Reapeat/Block parts of script (HELP!)
Post by: Hans on Sat 07/04/2007 23:36:14
Whatever I want. It can be a character walking around all the time (repeat) without blocking the script (blocking style).
Title: Re: Reapeat/Block parts of script (HELP!)
Post by: JD on Sat 07/04/2007 23:45:21
For that particular example you could do something with the room's repeatedly execute (to make it repeating) and Character.Walk (set it's blocking mode to eNoBlock). And probably Character.Moving aswell.
Title: Re: About SOUNDS, how to choose their blocking style and make them repeat.
Post by: strazer on Sun 08/04/2007 00:01:39
As for blocking sounds, you can force the sound into a specific channel using PlaySoundEx and wait until that channel is free again:


  PlaySoundEx(1, 3); // play sound1 in channel 3
  while (IsChannelPlaying(3) == 1) Wait(1); // block until channel 3 is free
Title: Re: About SOUNDS, how to choose their blocking style and make them repeat.
Post by: Hans on Sun 08/04/2007 00:08:20
IT WORKS! YES! Finally! :D
Thank you all!
Title: Re: Reapeat/Block parts of script (HELP!)
Post by: Ashen on Sun 08/04/2007 11:36:43
Topics merged, since they deal with similar issues.

There's no single way to 'block' parts of the script, without them actaully being Blocking. However, using things like Character.Moving, or IsChannelPlaying, you can usually work around it.