Page 1 of 1
Script problem again!
Posted: Tue Oct 13, 2009 12:33 am
by GMer
Here is a script I am using:
Code: Select all
{
INCREASETIMER [0]
TIMERAMOUT [0.5]
Spawn[ ()
{
Console(true);
LowLevel("Keycheck");
} ]
Keycheck[ ()
{
if(INCREASETIMER < self.time)
{
if (GetAttribute("health","Player") < 30)
{
PlaySound("healthlow.wav");
}
else
{
PlaySound("silent.wav");;
}
INCREASETIMER = self.time + StringCopy(TIMERAMOUT);
}
debug(GetAttribute("INCREASETIMER", "HC"));
} ]
}
When I start reality factory, it crashes. Basically this sucker is supposed to play "healthlow.wav" when the player's health is lower than 30.
Re: Script problem again!
Posted: Tue Oct 13, 2009 9:37 am
by Juutis
PlaySound("silent.wav");;
Re: Script problem again!
Posted: Tue Oct 13, 2009 1:01 pm
by metal_head
But than if the player's health goes bellow 30, the sound will be played every frame :X Is that what you wanted to have or you just wanna play it once?
Re: Script problem again!
Posted: Tue Oct 13, 2009 1:54 pm
by GMer
When the sound stops, I want it to play again (if the player's health is under 30), which is why there is the "INCREASETIMER" variable. I have gotten the script to play when I hold down space, but not with this script.
Now that was a stupid mistake on my part

. Thanks, Juutis!
Re: Script problem again!
Posted: Tue Oct 13, 2009 4:20 pm
by jonas
Don't you love that?

You look at it over and over, then someone else looks at it once and sees it. Always makes me feel like a genius.

Good thing we have our screens to hide behind.

Re: Script problem again!
Posted: Tue Oct 13, 2009 6:20 pm
by metal_head
jonas wrote:Don't you love that?

You look at it over and over, then someone else looks at it once and sees it. Always makes me feel like a genius.

Good thing we have our screens to hide behind.

I'll have to totally agree with you, it happens to me just all the time

Re: Script problem again!
Posted: Wed Oct 14, 2009 12:05 am
by GMer
Y'know what they say: two heads are better than one

Well, I've solved some problems scripting by myself (yay!), but I am stuck on this one.
Code: Select all
{
INCREASETIMER [0]
TIMERAMOUT [0.5]
SOUNDAMOUNT [1]
SOUND ["sound"]
SOUNDAMOUNT ["healthlow.wav"]
THRESHOLD [30]
VARIABLE [health]
Spawn[ ()
{
Console(true);
LowLevel("Keycheck");
} ]
Keycheck[ ()
{
if(INCREASETIMER < self.time)
{
if (GetAttribute(VARIABLE,"Player") > THRESHOLD)
{
ModifyAttribute(SOUND,0,"hc");
}
else
{
ModifyAttribute(SOUND,1,"hc");
}
INCREASETIMER = self.time + StringCopy(TIMERAMOUT);
}
debug(GetAttribute(SOUND,"hc"));
} ]
}
For a placeholder for the sound I have an attribute (which works great), and the script does recognize the player's health, just the "SOUND" attribute won't change when the player gets below THRESHOLD.
I think I may have the "if (GetAttribute(VARIABLE,"Player") > THRESHOLD)" wrong...
Re: Script problem again!
Posted: Wed Oct 14, 2009 9:10 am
by Juutis
So in the ModifyAttribute() command, are you trying to reference an attribute called "SOUND" or the variable SOUND (which contains the string "sound")?
Also, when initializing variables in the beginning, don't use the quotation marks for strings. Those quotation marks actually get included in the string so right now the script actually tries to modify an attribute called "
"sound"". So get rid of them:
SOUND [sound]
And I find this kinda funny:
Code: Select all
INCREASETIMER = self.time + StringCopy(TIMERAMOUT);
Simkin can be a real pain in the ass when it comes to the types of variables. And TBH, this doesn't help at all.

Turning a float into a string and then adding it to a float again is, well... not very clever. You're better off without the StringCopy() command there.

Re: Script problem again!
Posted: Wed Oct 14, 2009 2:00 pm
by GMer
Ok, so I need to:
A) remove the "StringCopy" command
B) remove the quotes on for the variable "sound" when defining it in the beginning (which is supposed to have a variable either 1-for on- and 2- for off)
Although it would probably just be easier to do the "PlaySound()" command instead of using the sound variable, a sound playing is a good enough diagnostic.