Problems with an if statements in draw actor

Non-platform specific questions.

Problems with an if statements in draw actor

Postby happyjustbecause » Tue Jul 31, 2012 4:42 am

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?
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: Problems with an if statements in draw actor

Postby happyjustbecause » Tue Jul 31, 2012 5:31 am

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.
}
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: Problems with an if statements in draw actor

Postby AliceXIII » Tue Jul 31, 2012 1:39 pm

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" :)
Last edited by AliceXIII on Tue Jul 31, 2012 9:38 pm, edited 1 time in total.
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: Problems with an if statements in draw actor

Postby happyjustbecause » Tue Jul 31, 2012 4:37 pm

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)
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: Problems with an if statements in draw actor

Postby AliceXIII » Tue Jul 31, 2012 9:35 pm

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
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron