Code help needed.

Game Editor comments and discussion.

Code help needed.

Postby Qsmash » Sat Jul 25, 2009 5:27 pm

Code: Select all
xvelocity+=0.1;
if(xvelocity==0)
{
    xvelocity=0;
}


I'm trying to make it so that my character will slow down to a complete stop, but I did something wrong...
Image
User avatar
Qsmash
 
Posts: 23
Joined: Sun Sep 30, 2007 2:39 am
Score: 1 Give a positive score

Re: Code help needed.

Postby DST » Sat Jul 25, 2009 6:12 pm

Code: Select all
xvelocity*=0.99;
if(xvelocity<0.1){
xvelocity=0;}


will make a character slow to a stop.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Code help needed.

Postby Qsmash » Sun Jul 26, 2009 2:22 am

That didn't quite work. It just keeps going.

also, this for key up event.
Image
User avatar
Qsmash
 
Posts: 23
Joined: Sun Sep 30, 2007 2:39 am
Score: 1 Give a positive score

Re: Code help needed.

Postby Hblade » Sun Jul 26, 2009 4:06 am

you could try this
Code: Select all
if (xvelocity>0)
{
xvelocity = xvelocity - .99;
}
if (xvelocity<0.01)
{
xvelocity = 0;
}
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Code help needed.

Postby skydereign » Sun Jul 26, 2009 4:33 am

That wouldn't work either, as Qsmash is trying to put this code into the keyup event. This runs only on keyup, so it is not practical for slowing down. I would suggest using a variable to signify the keyup. This way you can put the script DST has in draw, with the variable as a condition.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Code help needed.

Postby Fuzzy » Sun Jul 26, 2009 7:14 am

Hblade wrote:you could try this
Code: Select all
if (xvelocity>0)
{
xvelocity = xvelocity - .99;
}
if (xvelocity<0.01)
{
xvelocity = 0;
}


Add zeros before decimals Hblade. 0.99 not .99. Please practice good coding, especially when giving examples to others.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Code help needed.

Postby DST » Sun Jul 26, 2009 1:47 pm

Cmon, fuzz, lighten up!

But seriously, the events are designed for you to change variables, not so much to actually enter code.

The main portion of your actor's events end up in DrawActor.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Code help needed.

Postby Qsmash » Sun Jul 26, 2009 4:49 pm

It slowed down a bit, but if leave the key down long enough it wont.

umm...here's something else I probably should've mentioned.
Code: Select all
xvelocity+=0.1;


If you haven't noticed....I don't really understand codes to well. :(
Image
User avatar
Qsmash
 
Posts: 23
Joined: Sun Sep 30, 2007 2:39 am
Score: 1 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest