Page 1 of 1

Question about script code

PostPosted: Sat Sep 26, 2009 12:27 pm
by Garfield501
Hello,
I have a question about script codes.

Is there a command in the script editor to set the xvelocity and Y-coördinate of all my enemies?
Because I have to set the xvelocity and Y-coördinate of my enemies manually for each one.

This is the code I am using at the moment.
Code: Select all
if(enemy_001.x < -120 && enemy_001.xvelocity < 0)
{enemy_001.xvelocity *= -1;
enemy_002.xvelocity *= -1;
enemy_003.xvelocity *= -1;
enemy_004.xvelocity *= -1;
enemy_005.xvelocity *= -1;
enemy_006.xvelocity *= -1;
enemy_007.xvelocity *= -1;
enemy_008.xvelocity *= -1;
enemy_009.xvelocity *= -1;
enemy_010.xvelocity *= -1;
enemy_011.xvelocity *= -1;
enemy_012.xvelocity *= -1;
enemy_013.xvelocity *= -1;
enemy_014.xvelocity *= -1;
enemy_015.xvelocity *= -1;
enemy_016.xvelocity *= -1;
enemy_017.xvelocity *= -1;
enemy_018.xvelocity *= -1;
enemy_019.xvelocity *= -1;
enemy_020.xvelocity *= -1;
enemy_021.xvelocity *= -1;
enemy_022.xvelocity *= -1;
enemy_023.xvelocity *= -1;
enemy_024.xvelocity *= -1;
enemy_001.y = enemy_001.y +15;
enemy_002.y = enemy_002.y +15;
enemy_003.y = enemy_003.y +15;
enemy_004.y = enemy_004.y +15;
enemy_005.y = enemy_005.y +15;
enemy_006.y = enemy_006.y +15;
enemy_007.y = enemy_007.y +15;
enemy_008.y = enemy_008.y +15;
enemy_009.y = enemy_009.y +15;
enemy_010.y = enemy_010.y +15;
enemy_011.y = enemy_011.y +15;
enemy_012.y = enemy_012.y +15;
enemy_013.y = enemy_013.y +15;
enemy_014.y = enemy_014.y +15;
enemy_015.y = enemy_015.y +15;
enemy_016.y = enemy_016.y +15;
enemy_017.y = enemy_017.y +15;
enemy_018.y = enemy_018.y +15;
enemy_019.y = enemy_019.y +15;
enemy_020.y = enemy_020.y +15;
enemy_021.y = enemy_021.y +15;
enemy_022.y = enemy_022.y +15;
enemy_023.y = enemy_023.y +15;
enemy_024.y = enemy_024.y +15;
}


So is there a command, so I can set the xvelocity and the Y-coördinate of all my enemies at once, because i want to make more enemies and this is gonna be a hell of a job, if I continue using this code.

Re: Question about script code

PostPosted: Sat Sep 26, 2009 1:18 pm
by Camper1995
Why dont you just clone enemies? If I understand you, you have for example 5 actor. And every actor have different name righT?

So you make them Add actor...enemy 1, enemy 2, enemy 3 etc...

But why you dont make only enemy 1 and then click on clone button and thats all.

CLONE.JPG

:D


Camper

Re: Question about script code

PostPosted: Sat Sep 26, 2009 1:41 pm
by Garfield501
Wow, that was easy.

Thanks mate.

Re: Question about script code

PostPosted: Sat Sep 26, 2009 2:05 pm
by Camper1995
Your welcome :D

Re: Question about script code

PostPosted: Sat Sep 26, 2009 2:45 pm
by Garfield501
Wait, i have another question about this:

I have a script in "Draw Actor" --> "Script Editor" of enemy_001
Code: Select all
if(x < -115 && xvelocity < 0)
{
enemy_001.0.xvelocity *= -1.1;
enemy_001.1.xvelocity *= -1.1;
enemy_001.0.y = enemy_001.0.y +15;
enemy_001.1.y = enemy_001.1.y +15;
}

if(x > 115 && xvelocity > 0)
{
enemy_001.0.xvelocity *= -1.1;
enemy_001.1.xvelocity *= -1.1;
enemy_001.0.y = enemy_001.0.y +15;
enemy_001.1.y = enemy_001.1.y +15;


I though t I could use this script and then I just clone my enemy and it should work.
But in this script I get an error. (see Attachment)

The problem is with the enemy_001.X part
It doesn't reconize the clone ID, wich is enemy_001.1

How can I solve this?

Re: Question about script code

PostPosted: Sat Sep 26, 2009 2:48 pm
by Camper1995
Well, I dont understand this too much because I dont know what you want to do.

Only wrong I see is this:
Code: Select all
enemy_001.0.xvelocity *= -1.1;


try to write withouse 0 so..
Code: Select all
enemy_001.xvelocity *= -1.1;


Dont know. Tell me more about this problem. Maybe we can solve it. ;)


Camper

Re: Question about script code

PostPosted: Sat Sep 26, 2009 2:59 pm
by Garfield501
Okay, here it comes.

I have one enemy named: enemy_001
Then I have a script in "Draw Actor" --> "Script Editor" of enemy_001. (see my previous postfor the script).

With this script I want to make it , that when enemy_001 reaches X = -155, that it's xvelocity is reversed.
Then I want that that happens to every enemy on the field.

So I cloned my enemy_001.
The other enemy is the CLONE of enemy_001, so the name of the second enemy is "enemy_001.1".

But the script doesn't reconize my clone named, enemy_001.1

Re: Question about script code

PostPosted: Sat Sep 26, 2009 4:06 pm
by Camper1995
Well, so you need: when player go closely to enemy than x=155, do any action.

OK, here is my demo of fighting game:
Fighting test.rar
(1.04 MiB) Downloaded 83 times


So look in Collision event with actor BOXING,..
Code: Select all
if(x<Enemy.x-155)
{
   do any action.
}


:D

Maybe I help you. ;)

Camper

Re: Question about script code

PostPosted: Sat Sep 26, 2009 4:10 pm
by Camper1995
Sorry for posting again.

I am not well in english so maybe I understand now your question..

So enemy is goiong to the one side for example right. And when he reach more that 155.x of screen?.. fly away?

:D
Oh man, I looked at your picture. Can you send me your DATA files and ged. file or your game? I will try to fix this.

I think I know what is problem. ;)

Re: Question about script code

PostPosted: Sat Sep 26, 2009 4:28 pm
by Garfield501
Okay, i added my game file.


What I want is the following:

When enemy_001 hits the left side of the screen at X-coördinate -115, then I just want that enemy_001 and his clones start to move to the right.

Re: Question about script code

PostPosted: Sat Sep 26, 2009 5:31 pm
by Camper1995
Ok, I fix this. Look man. When you programming, try to find the easiest way how to solve problem.

So don't go directly to the script editor. Try to figure out something else.

I solve this with sensors. Not in script editor. I make 2 sensor and then, when the enemies touch one sensor, change direction to another side and move down for 15pixels.
:D

I will explain you that: Put in create actor of enemy in script editor:
Code: Select all
xvelocity = 1;


So not xvelocity = -1; because when we put xvelocity = 1; then we can change directions.

Then on collision of sensor:
Code: Select all
 xvelocity=-xvelocity;

This will change direction of xvelocity... so + or -

And that's completly all. ;)

I hope this help.

Here is:
Game without error.rar
(256.21 KiB) Downloaded 77 times



Camper :P

Re: Question about script code

PostPosted: Sat Sep 26, 2009 5:41 pm
by Garfield501
Wow, thanks mate.

Really appreciate it.

Re: Question about script code

PostPosted: Sat Sep 26, 2009 5:48 pm
by Camper1995
:D No problem. ;)

Camper