Pretty much what I asked. I have this problem where the function happens over and over again, and so it acts funky. I only want it to send the message once every time it is true
if ( bool ) {
SendMessage
bool = false
}
or
var sent : boolean = false;
if ( bool !sent ) {
SendMessage
sent = true
} else if ( !bool sent ) sent = false;
I cant understand why it doesnt work, it only does it once, and it doesnt reset its self
Post your code, it’s probably just a minor logical oversight.
Did you use SendMessageOptions.DontRequireReceiver? Just a thought!
[code
Yep! you need to use this option in your send funtion: SendMessageOptions.DontRequireReceiver
why? what will that do?
that didnt work.
Well, on a second thought you really don’t need SendMessageOptions.DontRequireReceiver. I am wondering why are you sending these messages rather then calling these functions directly? Are you broadcast these messages to other game objects as well?
no, that is the only way i know how. i did not know that you could do that.
The SendMessageOptions.DontRequireReceiver just suppresses an error message if there’s no script to receive it.
Your usage of “boolean” is incorrect:
else if (bullets <= 0 boolean !reload) {
if (!boolean reload) {
those lines make no sense.
What do you want to do? Prevent a second call to reload until the first one completes? In that case:
else if (bullets <= 0 !reload) {
reload = true;
SendMessage("Reload");
SendMessage("InvokeReload");
}
function Reload () {
animation.Play("reload", PlayMode.StopAll);
yield WaitForSeconds(animation["reload"].length);
bullets = clipSize;
reload = false;
}
I would have directly called Reload, but maybe there’s some asynchronous processing going on there with the yields and the SendMessage. I’m not going to touch any of those with a 10 foot pole.
EDIT; [quote=JM Studios, post: 465141]
no, that is the only way i know how. i did not know that you could do that.
[/quote]
Reload();
InvokeReload();
thanks, it worked!!