question about "If()"

Non-platform specific questions.

question about "If()"

Postby BogdansB » Wed Oct 26, 2011 8:29 am

Hello guys.
Im new at game editor and i want to make a cool game. i want to make a guy jump(i've done) and when he collides with a liane he can press [0] and then he jumps the second time. I send the following code to [KEY DOWN [0]] -> Script Editor nad the the code:

if(CollisionState("liane", ENABLE);)

{
yvelocity = -8
}


but when i want to add action then comes this out [ Error Line 1: Expected ) ]

where is my fault?

thanks Bogdan.
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: question about "If()"

Postby skydereign » Wed Oct 26, 2011 8:53 am

Okay, first of all, that isn't what CollisionState does. Second, if that were valid, you can't put the semicolon there. You could do it the way you are trying, using getAllActorsInCollision, but that isn't necessary. You can add a collision event with the liane actor.
player -> Collision with liane (repeat enabled) -> Script Editor
Code: Select all
char* key = GetKeyState();
if(key[KEY_0]==1)
{
    yvelocity=-8;
}


And so you know, CollisionState enables and disables colliding for the given actor. It'll return a 1 if it succeeds.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: question about "If()"

Postby BogdansB » Wed Oct 26, 2011 9:28 am

Thanks very much. but how can i do that he can jump just once and not every time you press ?
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: question about "If()"

Postby skydereign » Wed Oct 26, 2011 9:36 am

So, you'll be colliding constantly with the liane actor? From the code you posted, it sounded like whenever you press 0 (and are colliding with liane) you jump. But, if you want it to only allow you to jump once per collision with liane, then you can do this. Create a variable jump.
player -> Collision with liane (repeat disabled) -> Script Editor
Code: Select all
jump=1;

player -> Key Down 0 -> Script Editor
Code: Select all
if(jump==1)
{
    yvelocity=-8;
    jump=0;
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: question about "If()"

Postby BogdansB » Wed Oct 26, 2011 10:20 am

ok i thank you very much. i have a question but it isn't for this topic. how can a make an object who is 2sec there and 2sec not there? i mean i was to make spikes like in price of persia.
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: question about "If()"

Postby foleyjo » Wed Oct 26, 2011 11:23 am

On the create actor event of the spikes create a timer and give it a start value

In the draw event of the spikes actor use timer--; to count down to 0.

When it reaches 0 change the visibility
Then reset the timer.
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: question about "If()"

Postby BogdansB » Wed Oct 26, 2011 11:44 am

my timers name is "spikes".

do i need to do
Code: Select all
spikes--;

or
Code: Select all
timer--;
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: question about "If()"

Postby foleyjo » Wed Oct 26, 2011 12:15 pm

it's the name of the timer so

spikes--;
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: question about "If()"

Postby BogdansB » Wed Oct 26, 2011 12:44 pm

then comes an error
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: question about "If()"

Postby Game A Gogo » Wed Oct 26, 2011 12:50 pm

he said create a timer, but he meant to create a variable.

Although this could probably be done more easily with a timer and timer events.

You could create an infinite timer of 2000 milliseconds, have a script:
Code: Select all
transp=!transp;
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: question about "If()"

Postby BogdansB » Wed Oct 26, 2011 1:16 pm

ok thanks. now how to make this part?

"When it reaches 0 change the visibility .Then reset the timer."
DRAW ACTOR->
Code: Select all
transp--;
if(transp==0)
{

}

BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: question about "If()"

Postby Game A Gogo » Wed Oct 26, 2011 3:40 pm

with what I gave you, you don't need to reset the timer.
you don't need to do transp--; either because that would make it visible forever.

just create a timer of 2000 ms, and add a timer event script with what I gave you
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: question about "If()"

Postby BogdansB » Wed Oct 26, 2011 4:38 pm

ok. how to make an actor ,who destroys himself after 2sec and creates himself after 2sec he was destroyed?

[TIMER(spikes)]->[DESTROY ACTOR].
or do I need to write it in script?
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: question about "If()"

Postby foleyjo » Wed Oct 26, 2011 5:00 pm

You can't destroy an actor and then have him create himself.
The only way to do this would be to have a separate actor to control the destruction and recreation of the actor. However you would also need to record the location of the actor.
This can turn into a long hard method.

Your better option is to make the actor invisible to the player and then visible.

You could make it so that the spikes transparency level changes and then in the collision event do a check to see if the actor is visible before an event.
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: question about "If()"

Postby BogdansB » Wed Oct 26, 2011 5:09 pm

ok. i did that the actor is invisible after 2 sec.

Code: Select all
VisibilityState("Event Actor", DISABLE);


now i want him to be visible.

Code: Select all
if(VisibilityState("Event Actor", DISABLE);)
{
VisibilityState("Event Actor", ENABLE);
}


then comes an error.
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest