Page 1 of 1

Problems with an if statements in draw actor

PostPosted: Tue Jul 31, 2012 4:42 am
by happyjustbecause
How can I have an if statement in draw actor that specifies a distance, which should play a sound if the statement is true. I want the sound to only play once, but I want the distance to still be the thing that causes the sound to play. This is the same thing for me wanting an if statement in draw actor which should change an animation, but I don't want the animation to constantly be changing. How can I have some code that is only run once by an if statement that is constantly checking in draw actor?

Re: Problems with an if statements in draw actor

PostPosted: Tue Jul 31, 2012 5:31 am
by happyjustbecause
Just for clarification, I want something like this code:

Script Editor: Actor -> Draw Actor:
Code: Select all
if(distance(x,y, player.x, player.y)
{
    PlaySound... // this sound shouldn't constantly be playing, it should only play through once, smoothly
}


and like this:

Script Editor: Actor -> Draw Actor:
Code: Select all
if(distance(x,y, player.x, player.y)
{
    ChangeAnimation("Event Actor")... // this should just change once, it shouldn't be trying to constantly change animations, I've tried just putting animindex=... but it didn't work for whatever reason.
}

Re: Problems with an if statements in draw actor

PostPosted: Tue Jul 31, 2012 1:39 pm
by AliceXIII
if your problem is calling this code when your a certain distance away then this will do it:
Code: Select all
int dist=distance(x,y, player.x, player.y);
if(dist<=10) //would activate when distance is within 10 pixels or less of player
{
    PlaySound... // this sound shouldn't constantly be playing, it should only play through once, smoothly
}

if's and switches would do what you want easy you just need to compare what value your checking to the desired value..
like if my distance is 32 pixels away
Code: Select all
if(disance(x,y,my.x,my.y)==32)
{
    //code here
}


if your using keyboard movement i'd recommend calling your distance code in the key down events so you won't have to call an if in your draw actor, you know call it only when you need it instead of all the time :D

*EDIT*: fixed the omitted "t" in the first code block so it would correctly say "int" :)

Re: Problems with an if statements in draw actor

PostPosted: Tue Jul 31, 2012 4:37 pm
by happyjustbecause
Oh yeah... I forgot that I can use switches in draw actor. Thanks for the help, by the way for this code you typed:

Code: Select all
in dist=distance(x,y, player.x, player.y);
if(dist<=10) //would activate when distance is within 10 pixels or less of player
{
    PlaySound... // this sound shouldn't constantly be playing, it should only play through once, smoothly
}


Is the first word supposed to be "int", not "in"?
Maybe I will add that variable, that'd be useful to use, rather than constantly typing "distance(x,y, player.x, player.y)

Re: Problems with an if statements in draw actor

PostPosted: Tue Jul 31, 2012 9:35 pm
by AliceXIII
you know i always have this weird thing where i re-read my previous posts before i read other peoples after they've made a post, anyways i noticed that i left out the "t" in "int" but it was on accident this laptop's "t" key doesn't always pick up i have to actually tap on it hard to type a t which sucks when programming :P