Page 1 of 1

space Game

PostPosted: Sun Feb 19, 2012 5:35 pm
by praaab
well ive been trying to get my spaceship to destroy wen it hits the asteroids, my cod is this
hp=2;
if(hp = 0)
{
destroyactor
}
but y wont it work??

Re: space Game

PostPosted: Sun Feb 19, 2012 5:39 pm
by SuperSonic
it should be: hp-=2; :wink:

Re: space Game

PostPosted: Sun Feb 19, 2012 5:58 pm
by praaab
i know in my collision with asteroid its hp-=1;
and i set the hp to 2 in my create actor, in the collision also its the if(hp=0) then destroy actor
but it still wont work

Re: space Game

PostPosted: Sun Feb 19, 2012 8:09 pm
by SuperSonic
Oh I'm sorry. I was wrong :P

The correct code should be:if(hp == 0)

Notice the double equal marks. This is used to check if something is equal. Just a single mark will change something. For example:
Code: Select all
int i;
i = 5;//This will make i equal five
i == 5;//This checks to see if i is equal to five

I hope that made sense^^

Re: space Game

PostPosted: Mon Feb 20, 2012 11:30 pm
by praaab
nw see im proposing my lives system, how should i make so that if lives-- then destroy actor cause in my collision with asteroid it has lives--; and then it says if(lives--) then destroy actor, but all it does is take away 2 lifes and destroys the actor. (i set the lives to 3)

Re: space Game

PostPosted: Tue Feb 21, 2012 12:01 am
by skydereign
You need to be able to distinguish between setting and comparing variables.
Code: Select all
x++; // increases x by 1
x+=1; // increases x by 1
x=1; // sets x equal to 1
x==1; // checks if x is equal to 1

Notice the only comparison is when you use two equal signs. So putting lives-- into an if statement won't check if lives is a certain value, all it will do is reduce lives by 1. You can also use !=, >=, >=, >, and < to compare numbers. These do not change the value of the variable, instead they return a 1 or a 0 (1 meaning true and 0 meaning false). As SuperSonic mentions you need something that decreases your variable, and then checks if it is equal to 0.
Code: Select all
hp--;
if(hp<=0)
{
    DestroyActor("Event Actor");
}

If you don't use the format of reducing the variable and comparing, you'll come across the problems you have been facing.

Re: space Game

PostPosted: Tue Feb 21, 2012 1:15 am
by praaab
but how do i make it so that IF he loses a life then destroy actor but comes back after 1 second?

Re: space Game

PostPosted: Tue Feb 21, 2012 2:22 am
by skydereign
That's simple, put that code where he loses a life... right? To actually make the actor actually be destroyed you can either destroy it temporarily and recreate it after a second (using a timer) or you can change its visibility state and reset it after a timer event.

Re: space Game

PostPosted: Tue Feb 21, 2012 2:23 am
by praaab
heres the link to download my game http://www.filedropper.com/raadproductions

Re: space Game

PostPosted: Tue Feb 21, 2012 2:46 am
by skydereign
Now am I to assume that means you want me to fix the problem? Two things to note, one is that you have two collision events with the same actor (colliding with the asteroid). You should really combine these two, and in the second one you have an if statement followed by a semicolon. That semicolon makes the if act as if it were always true, which is why the particle effect happens when lives are still greater than zero. Now the second thing is you never recreate the player actor. I would recommend creating a timer for the view that lasts a second. In this timer event the view should recreate the player in the center of the screen.

Re: space Game

PostPosted: Tue Feb 21, 2012 3:32 am
by praaab
this is all very confusing to me is there any way that u could fix these problems with the view and respawning?

Re: space Game

PostPosted: Tue Feb 21, 2012 11:06 pm
by skydereign
You mean like this? I changed a few other things and I'm not sure what you meant by the problem with the view.

Re: space Game

PostPosted: Wed Feb 22, 2012 8:30 pm
by praaab
i have that done already i found out how to do it but thanks a lot for the effort heres +1, and i have a question i want my space ship to become faster wen he collides into an speedupgrade.

Re: space Game

PostPosted: Thu Feb 23, 2012 12:28 am
by skydereign
You'll notice in my edit I removed the draw actor events that only moved the actor (x+=1). So now it uses xvelocity which is set to 1 during the actor's create. So if you want to increase the speed just increase xvelocity when you collide with a speedup actor (you should probably also increase the view's xvelocity).