PDA

View Full Version : Shooter Whirlwind help



Archangel
04-14-2009, 11:01 AM
I've been trying for a hour now to make this simple script work. When all is said and done, it should cause it to fire every 60 frames.


import "std.zh"

ffc script ShooterWhirlwind {
voidrun(){
create eweapon(31);
waitframe();
}
}

Here is the compiling report as well.


Pass 1: Parsing
Line 4: Syntax error, unexpected identifier, on token voidrun
Fatal error P00, can't open or parse input file?

pkmnfrk
04-14-2009, 12:01 PM
1. Space between "void" and "run"
2. "Screen->CreateEWeapon"
3. EW_WIND is the whirlwind. If you want to use EW_SCRIPT1 as you are trying to do, you need to do more work.

It's not magic, you have to say things the way the computer understands.

Joe123
04-14-2009, 12:06 PM
So where is the part of your code that tells ZC to do something every 60 frames?
You can't just stick some code together and hope it'll work, you have to actually input the things that you want to happen.

Archangel
04-14-2009, 12:52 PM
import "std.zh"

ffc script ShooterWhirlwind {
void run(float d0){
Screen->CreateEWeapon(31);
if(d0 == 0) d0 = 60;
Waitframe(d0);
}
}


TMP Line 7: Error T21 Can't match type signature waitframe(float).

How close am I, now? And what errors do you foresee?

pkmnfrk
04-14-2009, 01:52 PM
I... I can't watch any more.


import "std.zh"

ffc script ShooterWhirlwind {
void run(){
while(true) {
Screen->CreateEWeapon(31);
Waitframes(60);
}
}
}

Note that this still doesn't create a whirlwind, and is not close to doing so. It will, however, shoot once every 60 frames.

Archangel
04-14-2009, 02:05 PM
Damn, I was so close... Is it really that simple... "Checks"

Holyshit, I added your fifth line and another brace and presto! SUCCESS!
Thanks Joe123 and pkmnfrk. I couldn't of done this with out you.

So the purpose of while(true) is allowing Line 8 to work correctly with T21 or what? :shrug:
Okay, so it's compiling, but I can't get it to function? I'm going to look at my code one more time and see if I'm missing something.

Okay, I'm at a lost. Just how the hell do I make something fire winds. It's firing, but no projectile?

Joe123
04-14-2009, 05:57 PM
Right.
I didn't have time for this earlier, hence the flippant reply.

First of all, let's think out our code.
Before we write anything down, it's best to get a good idea in our heads of how we're going to make our code work.

So.
What we want is 'A shooter whirlwind which fires every 60 frames'.
Let's have a think of what we're going to be able to do to make this work.

The most obvious thing we'll need is to create the whirlwind.
We'll also need a 60 frame time delay.

Those are perhaps the most obvious two.
There are, however, some other important things that we will definately need for our code to work.

Because we want it to happen every 60 frames, we need something to keep repeating iterations of our code.
We also need somewhere for our whirlwind to start from, and somewhere for it to be going to.
The final thing, which is perhaps the least obvious to someone who hasn't coded in ZScript before is something that will let the rest of the system run inbetween the functions of our script.
That's handled in the 60 frame time delay though, so we won't worry about it this time.


Now we have some pretty good ideas as to what we need in our code, so let's get those ideas down.
For the purpose of this explanation, we're going to have the whirlwind start where the ffc is, and fire off in a random direction.



start a loop
create a whirlwind
place the whirlwind in its starting position
pick a random direction for the whirlwind to go in
delay for 60 frames
go back to the start of the loop


Now we have a clear structure for our code to take, and all that's left for us to insert is the proper ZScript functions and syntax.

Off we go then:

ffc script Whirlwind{ //Firstly, declare a script
void run(){ //Every script's functions start in void run
while(true){ //This creates our loop. 'while' will continue to loop the code in the following braces - {} - while the condition in its brackets - () - is true. 'true' is always true (as you may have guessed), so 'while(true){' will continue to loop the following code while the script runs.
eweapon Whirlwind = Screen->CreateEWeapon(EW_WIND); //Here we create our whirlwind. Whirlwinds are an 'eweapon', so we create them like so
Whirlwind->X = this->X; //Now we place the whirlwind on top of our ffc.
Whirlwind->Y = this->Y; //We access the whirlwind's 'X' and 'Y' variables with the little '->' arrow operator, and we set them to the ffc's ('this' is a pre-declared ffc, refering to the ffc to which the script is attached) X and Y values.
Whirlwind->Dir = Rand(3); //We then access the whirlwind's 'Dir' (direction) variable. 'Rand' picks a random number for us, so now our whirlwind will head off in a random direction
Waitframes(60); //Now we wait for 60 frames
} //Tell our loop where to end. The code will now re-run from our while loop's left brace each time it gets to this point
} //End void run
}//End the script

Archangel
04-14-2009, 06:54 PM
How do I go about using the numbers from std.zh or do I need to use EW_weapon to use.

pkmnfrk
04-14-2009, 08:38 PM
How do I go about using the numbers from std.zh or do I need to use EW_weapon to use.

Like this:


EW_WIND

or


DIR_UP

I do not understand the second part of your almost-question.

Archangel
04-14-2009, 11:49 PM
Okay so if I import std.zh I can use the numbers. I figured it out on my own. Thanks everyone for your help. Take a break from scripting before I continue on with learning Eweapon manipulation and ffc.

Also quick question. Are data values ffc specific or do they effect all ffcs. Meaning we can only have 8 regardless.

pkmnfrk
04-14-2009, 11:52 PM
Which data values? Well, either way, the answer is "They're specific to the FFC".

And, I don't know where you pulled the number 8 from...

Archangel
04-15-2009, 12:11 AM
d0 d1 d2 d3 d4 d5 d6 d7 <-Zscript
a1 a2 <-Asm

I lied you have 10, technically speaking anyway. I can name them whatever I want though, correct? They just register in order from left to right to d0, d1, d2 and so on.
I can have 8 values max then right?

Also is it possible for a ffc to use variables that are independent from its own array of values.

pkmnfrk
04-15-2009, 01:20 AM
The D slots are simply used to pass values to your script. That way, you can have several FFCs that behave similarly, but with their own customizations. For example, shooting different projectiles, or showing different strings.

Other than those, you can use your own variables, both local (defined in the script, and temporary) and global (defined outside the script, and permanent). You define them as such:


int this_is_a_global;

ffc script Something {
void run (int foo, int bar) {
int this_is_a_local;
}
}

Note that in this example, foo and bar represent D0 and D1 -- the D variables will be passed along to your script. You can name them whatever you want, it doesn't matter.