Page 1 of 2
question about "If()"
Posted:
Wed Oct 26, 2011 8:29 am
by BogdansB
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.
Re: question about "If()"
Posted:
Wed Oct 26, 2011 8:53 am
by skydereign
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.
Re: question about "If()"
Posted:
Wed Oct 26, 2011 9:28 am
by BogdansB
Thanks very much. but how can i do that he can jump just once and not every time you press ?
Re: question about "If()"
Posted:
Wed Oct 26, 2011 9:36 am
by skydereign
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;
}
Re: question about "If()"
Posted:
Wed Oct 26, 2011 10:20 am
by BogdansB
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.
Re: question about "If()"
Posted:
Wed Oct 26, 2011 11:23 am
by foleyjo
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.
Re: question about "If()"
Posted:
Wed Oct 26, 2011 11:44 am
by BogdansB
my timers name is "spikes".
do i need to do
- Code: Select all
spikes--;
or
- Code: Select all
timer--;
Re: question about "If()"
Posted:
Wed Oct 26, 2011 12:15 pm
by foleyjo
it's the name of the timer so
spikes--;
Re: question about "If()"
Posted:
Wed Oct 26, 2011 12:44 pm
by BogdansB
then comes an error
Re: question about "If()"
Posted:
Wed Oct 26, 2011 12:50 pm
by Game A Gogo
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;
Re: question about "If()"
Posted:
Wed Oct 26, 2011 1:16 pm
by BogdansB
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)
{
}
Re: question about "If()"
Posted:
Wed Oct 26, 2011 3:40 pm
by Game A Gogo
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
Re: question about "If()"
Posted:
Wed Oct 26, 2011 4:38 pm
by BogdansB
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?
Re: question about "If()"
Posted:
Wed Oct 26, 2011 5:00 pm
by foleyjo
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.
Re: question about "If()"
Posted:
Wed Oct 26, 2011 5:09 pm
by BogdansB
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.