Reapeat/Block parts of script (HELP!)

Started by Hans, Sat 07/04/2007 15:16:31

Previous topic - Next topic

Hans

I would like to know if it is possible to repeat a whole part of the script or set its blocking style.

Gilbert

Make that part of codes a function and call it whenever needed.

Otherwise, you may need to elaborate more on what you actually need.

Hans

Is it possible to make a function like this:

myfunction (eRepeat);

???

If not, this won't help me.

Gilbert

Why not just call the function in repeatedly_execute[_always]() ?


Mr Flibble

Making a Function

Put this somewhere inbetween functions.
Code: ags

#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
Code: ags

import function MyFunction();


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

MyFunction();


Does that help? You can use functions to collect blocks of code you use a lot to make life easier.
Ah! There is no emoticon for what I'm feeling!

Hans

That's how to make a function. But I want to be able to make the code repeat and set the blocking style.

Hans

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)

Dan_N

Search for PlayAmbientSound in the AGS Manual, you can use that.

JD

What exactly is in this bit of code you want to repeat and make blocking?

Hans


Hans

Whatever I want. It can be a character walking around all the time (repeat) without blocking the script (blocking style).

JD

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.

strazer

As for blocking sounds, you can force the sound into a specific channel using PlaySoundEx and wait until that channel is free again:

Code: ags

  PlaySoundEx(1, 3); // play sound1 in channel 3
  while (IsChannelPlaying(3) == 1) Wait(1); // block until channel 3 is free

Hans


Ashen

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.
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk