Hi Peeps.
I have a problem, anyone who knows me would agree.
This, however, is a Scripting problem.
In one room I have a number of creatures, on different levels, that walk from left to right and back again, repeatedly.
If any one of these creatures touches the 'Player Character' then a point is deducted from a 'Meter' until the meter is empty.
This is where the player runs away screaming, in theory.
I have created a 'Sanity Monitor' using a GUI and a 'Button'.
The buttons image is the meter and is set to 'Clip Image'
I have created a 'Global Variable' called 'number_of_hearts' an INT set to 218.
In 'Global Script ash' I have...
Code: ags
At the very top of 'Global Script asc' I have...
Code: ags
In my 'Room Script' I have...
Code: ags
This works just fine... However.
The audio files that I have within my room script play over and over again.
Obviously this is because they are within the 'Repeatedly Execute' section.
I don't know how to cure this.
I have tried many ways of getting the sound files to play outside of 'Repeatedly Execute'.
My game Compiles but no sound is played when the character collides with an NPC.
If anyone can see my error or even a better way to do what I am trying to do then please help.
I have been trying to do this for the past week now, without help, and have got nowhere.
Yours.
Jay.
I have a problem, anyone who knows me would agree.

This, however, is a Scripting problem.
In one room I have a number of creatures, on different levels, that walk from left to right and back again, repeatedly.
If any one of these creatures touches the 'Player Character' then a point is deducted from a 'Meter' until the meter is empty.
This is where the player runs away screaming, in theory.
I have created a 'Sanity Monitor' using a GUI and a 'Button'.
The buttons image is the meter and is set to 'Clip Image'
I have created a 'Global Variable' called 'number_of_hearts' an INT set to 218.
In 'Global Script ash' I have...
import function UpdateHeartGUI(int change);
At the very top of 'Global Script asc' I have...
function UpdateHeartGUI(int change) {
number_of_hearts += change;
if (number_of_hearts < 0) number_of_hearts = 0;
if (number_of_hearts > 218) number_of_hearts = 218;
btnHearts.Width = number_of_hearts * 1;
return number_of_hearts;
}
In my 'Room Script' I have...
// room script file
function room_FirstLoad() {
aWelcome.Play();
}
function room_Load() {
// This disables MOUSE controls.
//------------------------------
mouse.Visible = false;
cDan.FaceLocation(0, 360);
aMystery.Play();
}
function room_RepExec() {
// SCARE SCRIPT.
//---------------------------------------------------
// If the GHOSTS or other CREATURES collide with EGO,
// they SCARE him.
if (AreThingsOverlapping(ZOMB, DAN)) {
aScream2.Play();
if (UpdateHeartGUI(-2) == 0){
QuitGame(0);
}
}
if (AreThingsOverlapping(ZOMB2, DAN)) {
aScream2.Play();
if (UpdateHeartGUI(-2) == 0){
QuitGame(0);
}
}
if (AreThingsOverlapping(ZOMB3, DAN)) {
aScream2.Play();
if (UpdateHeartGUI(-2) == 0){
QuitGame(0);
}
}
if (AreThingsOverlapping(GHOST, DAN)) {
aGhostly1.Play();
if (UpdateHeartGUI(-1) == 0){
QuitGame(0);
}
}
if (AreThingsOverlapping(GHOST2, DAN)) {
aGhostly1.Play();
if (UpdateHeartGUI(-1) == 0){
QuitGame(0);
}
}
// END OF SCARE SCRIPT.
//---------------------
// This section makes GHOSTS and other CREATURES move.
//----------------------------------------------------
if (!cZomb.Moving) {
if (cZomb.x < 100) {
// If the Ghost is on the left hand side of the screen,
// start it moving towards the right.
cZomb.Walk(600, cZomb.y, eNoBlock, eAnywhere);
}
else {
// Otherwise, move it towards the left
cZomb.Walk(34, cZomb.y, eNoBlock, eAnywhere);
}
}
if (!cZomb2.Moving) {
if (cZomb2.x < 100) {
// If the Ghost is on the left hand side of the screen,
// start it moving towards the right.
cZomb2.Walk(605, cZomb2.y, eNoBlock, eAnywhere);
}
else {
// Otherwise, move it towards the left.
cZomb2.Walk(34, cZomb2.y, eNoBlock, eAnywhere);
}
}
if (!cZomb3.Moving) {
if (cZomb3.x < 100) {
// If the Ghost is on the left hand side of the screen,
// start it moving towards the right.
cZomb3.Walk(600, cZomb3.y, eNoBlock, eAnywhere);
}
else {
// Otherwise, move it towards the left.
cZomb3.Walk(34, cZomb3.y, eNoBlock, eAnywhere);
}
}
if (!cGhost.Moving) {
if (cGhost.x < 100) {
// If the Ghost is on the left hand side of the screen,
// start it moving towards the right.
cGhost.Walk(582, cGhost.y, eNoBlock, eAnywhere);
}
else {
// Otherwise, move it towards the left
cGhost.Walk(34, cGhost.y, eNoBlock, eAnywhere);
}
}
if (!cGhost2.Moving) {
if (cGhost2.x < 100) {
// If the Ghost is on the left hand side of the screen,
// start it moving towards the right.
cGhost2.Walk(600, cGhost2.y, eNoBlock, eAnywhere);
}
else {
// Otherwise, move it towards the left.
cGhost2.Walk(34, cGhost2.y, eNoBlock, eAnywhere);
}
}
}
// END OF GHOST AND CREATURE MOVEMENTS SCRIPT.
//--------------------------------------------
This works just fine... However.
The audio files that I have within my room script play over and over again.
Obviously this is because they are within the 'Repeatedly Execute' section.
I don't know how to cure this.
I have tried many ways of getting the sound files to play outside of 'Repeatedly Execute'.
My game Compiles but no sound is played when the character collides with an NPC.
If anyone can see my error or even a better way to do what I am trying to do then please help.
I have been trying to do this for the past week now, without help, and have got nowhere.
Yours.
Jay.