Jump to content

Photo

um... Noobie need help!!


  • Please log in to reply
167 replies to this topic

#1 AgentLym

AgentLym

    • Zelda and Pokémon Master •

  • Members
  • Location:Skyloft

Posted 25 April 2008 - 03:06 PM

Well, as a one-day old scripter, I need help! I've looked at the scripting help stuff at the top of this forum, but it didn't help me too much. (well, not as much as I would've liked)

For my first script, I am trying to make a guard block Link. You know, have the guard move horizontally along the screen with Link...? I though I had it, but no.

As you look at this code, remember that I have ZERO experience with C, C++, ASM, or ZScript... icon_razz.gif
CODE
import "std.zh"
ffc script guarding_soldier
{
  void run()
  {
    int ffc->X = Link->X;
  }
}


Well, I'm sure that there is a mamillion things wrong with that, but... It's my first script EVER!

When I use it, it says there is a parse error or something. I know that the problem is the "ffc" pointer, but how else am I supposed to make the FFC follow Link??

Please help!

Edited by AgentLym, 25 April 2008 - 03:07 PM.


#2 Joe123

Joe123

    Retired

  • Members

Posted 25 April 2008 - 04:27 PM

Right.

Good start, it's nice to see people have a go for themselves.
You're quite a way off, but what you have got is quite promising.
Your scope is good, and you're using pointers which is quite often a basic error.

Let's have a look at your script though:
CODE
import "std.zh" //Good, we need this at the top of every script file. Remember to keep all scripts in the same file.

ffc script guarding_soldier{ //Declare the ffc script, and name it. So far, so good.
    void run(){ //Start by calling 'void run(){'. All scripts start like this, so that's good.
        //int ffc->X = Link->X; //Declare and integer called 'ffc->X' and set it's value to Link's X coordinate.
        //I've noted out that line; this is what you meant:
        this->X = Link->X; //Set the script's ffc's X coordinate to Link's X coordinate.
    } //End void run()
}//Close script


Right.
So, with my modifications, what your script will do is:
When the screen loads, check Link's X coordinate, and then set the script's ffc's X coordinate to the same value, moving the ffc so it's in line with Link, then end.

Obviously not what you want, but it's a start.
Quite an important concept for you is the 'while' loop.
Your script runs only once, and you want it to run every single frame while Link is on the screen.

You do that like this:
CODE
    while(true){//Do something
        Waitframe();
    }


The while loop will keep repeating until the conditions within the parenthesis are broken. While loops running 'true' are never broken, and so will run every frame (that Link is on the screen).
However, that's a really great way to crash the system if you don't declare the 'Waitframe();' function within the loop.
Waitframe(); makes the system stop for one frame before running what's in the loop again, therefore you won't get a system crash.

So, a script to do something more like what you want could be this:
CODE
ffc script guard{
    void run(){
        while(true){
            this->X = Link->X;
        Waitframe();
        }
    }
}


Although, that script will always run wherever Link is on the screen, so the soldier will do some rather unusual things, such as walk through solid combos and the like, and will 'warp' when Link first walks onto the screen to his X coordinate.

So maybe, with a few modifications, you might want to try something like this:
CODE
ffc script guard{
    void run(int left, int right){
        while(true){
            if(Link->X > left && Link->X < right){
                this->X = Link->X;
            }
        Waitframe();
        }
    }
}


So I'll just run you through what I've done...

CODE
    void run(int left, int right){

Here, I've declared two integers.
These integers, because they've been declared within void run(), will be D0 and D1 of the script's arguments.
Remember, if you're declaring argument integers or floats, they're seperated by a comma, not a semi-colon.

CODE

            if(Link->X > left && Link->X < right){
                this->X = Link->X;
            }

Now, what I've done is create an 'if(){}'.
'if(){}' says 'run the functions within '{}' only if the conditions within '()' are true'
So, the script will only make the guard move to Link's X position if Link's X co-ordinate is greater than (>) 'D0' and (&&) less than (<) 'D1' of the scripts arguments.

The soldier'll still warp to where Link is when he moves between D0 and D1, but that'd take a bit more thinking to code and I'm not in a thinking mood right now.

Anyway, hope that helps a little =)
It's nice to see new people learning.

#3 AgentLym

AgentLym

    • Zelda and Pokémon Master •

  • Members
  • Location:Skyloft

Posted 25 April 2008 - 04:41 PM

Wow! Thanks! That helps a LOT!

But, now I have a couple more questions...

I was wondering what you would put in the "void run()"... you declare integers there which can be edited by the D0, D1, D2, etc...? Handy!

So, the "this" pointer just stands for the FFC...? I think that's what it means... Right? icon_razz.gif

And, you don't need "int" before the expression, eh? I was wondering about that, also.

Does it matter where you stick the "waitframe()" function? (as long as it's in the script, of course)

And I'm pretty sure that && means "and" in code language.

Last question: So I would set the D0 and D1 arguments in my FFC editor to, say, 80 and 160, right? They are measured in pixels I'm pretty sure.

Also, if I just wanted the guard to block the way while Link only has the Wooden sword, I would make the code:
CODE
ffc script guard{
    void run(int left, int right){
        while(itemclass->swords < 2){     // I made an adjustment to your code, here
            if(Link->X > left && Link->X < right){
                this->X = Link->X;
            }
        Waitframe();
        }
    }
}

Edited by AgentLym, 25 April 2008 - 04:53 PM.


#4 Joe123

Joe123

    Retired

  • Members

Posted 25 April 2008 - 04:48 PM

Well.
When you want to reference an ffc, you must declare it first.
Say I want to use ffc number 22 int my script.

First of all, I have to say this:
CODE
ffc myffc = Screen->LoadFFC(22);

That line tells the script it's making an ffc, then it calls it 'myffc'.
It then checks on the screen, and loads ffc number 22 to be that ffc.
Then I can manipulate it however I like.

However, the script's ffc is always automaticaly declared as 'this', so you don't need any declaration.

Well, why would you put 'int' before it?
Putting 'int' means you're declaring an integer.
What you want is an ffc.
Integers just take on values, they don't do much else. FFC obviously do a lot more. (that's not to say integers aren't important though)

So long as the Waitframe(); function is within your while loop it doesn't really matter, although it's general practise to put it at the end (unless you have a reason to put it somewhere else). Make sure you don't put it within an if statement though, cause it might not run then, so you'd crash the system.

QUOTE
greater than (>) 'D0' and (&&) less than (<)

Yes, '&&' means 'logic and' in C++ coding.
Not to be confused with 'bitwise and', which is just '&'.

And yes, that'd be what you'd do.


EDIT:
Sorry, I've lost patience (don't worry, I'm not annoyed or anything, I just spent a while writing out a load of stuff already) to explain what you did wrong there, if you like I'll do it some other time.
What you want is this though:
CODE
ffc script guard{
    void run(int left, int right){
        while(true){
            if(Link->X > left && Link->X < right && Link->Item[5]){
                this->X = Link->X;
            }
        Waitframe();
        }
    }
}

Edited by Joe123, 25 April 2008 - 04:50 PM.


#5 AgentLym

AgentLym

    • Zelda and Pokémon Master •

  • Members
  • Location:Skyloft

Posted 25 April 2008 - 04:51 PM

Cool! Thanks! icon_biggrin.gif

EDIT: It seems I have found a problem. It says that the variable "itemclass" is undeclared...

How would I fix that? I am using build 780, in case that makes a difference.

Thanks for any help!

Edited by AgentLym, 25 April 2008 - 04:58 PM.


#6 Joe123

Joe123

    Retired

  • Members

Posted 25 April 2008 - 05:00 PM

Oh dear, I read what you wanted wrong.
That script will make the guard move if Link has the wooden sword, but it won't make any difference if he has a different one.
You want the guard to go away when Link gets the white sword, don't you.

CODE
ffc script guard{
    void run(int left, int right){
        while(true){
            if(Link->X > left && Link->X < right &&  !Link->Item[I_SWORD2]){
                this->X = Link->X;
            }
        Waitframe();
        }
    }
}


Sorry.


EDIT:
That's because you wrote your script wrong.
Read my edit in the previous post.

Also, you know that this guard won't actually stop Link's movement right?
Link will just walk over him, you can't have solid ffcs.

Edited by Joe123, 25 April 2008 - 05:01 PM.


#7 AgentLym

AgentLym

    • Zelda and Pokémon Master •

  • Members
  • Location:Skyloft

Posted 25 April 2008 - 05:18 PM

Thanks Joe123! You don't know how much you have helped! icon_biggrin.gif Sorry if I was a bother. icon_heh.gif

Well, everything works fine, and I understand (almost) all of this code! I'm glad!

But, is there a way to make the FFC have a solid combo underneath it maybe? Or just make it so that the guard cannot be walked through?

And, that's about it! Thanks again, Joe123! icon_biggrin.gif

If anyone else has some help he or she would like to give, please give it! icon_biggrin.gif

Thanks!



#8 Joe123

Joe123

    Retired

  • Members

Posted 25 April 2008 - 05:32 PM


CODE
ffc script guard{
    void run(int left, int right){
    int i;
        while(true){
            if(Link->X <= this->X+16 && Link->X > this->X){
                for(i=0;i<16;i++){
                    if(Link->Y == this->Y+i) Link->InputLeft = false;
                }
            }
            else if(Link->X >= this->X-16 && Link->X < this->X){
                for(i=0;i<16;i++){
                    if(Link->Y == this->Y+i) Link->InputRight = false;
                }
            }
            else if(Link->Y >= this->Y-16 && Link->Y < this->Y){
                for(i=0;i<16;i++){
                    if(Link->X == this->X+i) Link->InputDown = false;
                }
            }
            else if(Link->Y <= this->Y+16 && Link->Y > this->Y){
                for(i=0;i<16;i++){
                    if(Link->X == this->X+i) Link->InputUp = false;
                }
            }
            if(Link->X > left && Link->X < right &&  !Link->Item[I_SWORD2]) this->X = Link->X;
        Waitframe();
        }
    }
}


Could have a go with that.
I've been meaning to write a pseudo-solidity script for ffcs for ages, and I think that should be ok.
Have a go and let me know what happens; it might not work but I think it should do.

It is rather complicated, but I can try to explain it if you like.

#9 AgentLym

AgentLym

    • Zelda and Pokémon Master •

  • Members
  • Location:Skyloft

Posted 25 April 2008 - 05:38 PM

Hm... a little complicated, but if you want, you can explain it later. You don't have to, though.

And when I'm compiling, it says that variable "I_SWORD2" is undeclared... I wonder why.

#10 Joe123

Joe123

    Retired

  • Members

Posted 25 April 2008 - 05:39 PM

Well, that'd be because you haven't got
CODE
import "std.zh"

at the top of your script.

#11 AgentLym

AgentLym

    • Zelda and Pokémon Master •

  • Members
  • Location:Skyloft

Posted 25 April 2008 - 05:42 PM

Heh, heh. I knew that. icon_heh.gif

Well, it works ok, but if you walk against it while walking sideways at the same time (by holding down both up and sideways), you can inch your way past him. Then, once you obtain the White Sword, the guard stops moving, but blocks only like one pixel beside him. But if you walk right into him, you can walk right through him.

Edited by AgentLym, 25 April 2008 - 05:45 PM.


#12 Joe123

Joe123

    Retired

  • Members

Posted 25 April 2008 - 05:47 PM

Hrm.

Well, I'll have to have a look at the pseudo solidity some other time, it would be quite a useful function to have in general, so I'll see what I can do next time I have ZQuest handy.

I can't think why getting the white sword should affect the solidity though, those parts of the code are completely unrelated =S
I made sure of it.

Strange.


Anyway, I'm off to bed, and then on holiday until sunday, so you might have to enlist some other help between now and then I'm afraid icon_lol.gif

Edited by Joe123, 25 April 2008 - 05:48 PM.


#13 Twilight Knight

Twilight Knight

    Tell all with glee, Argon's on PureZC

  • Members
  • Real Name:Sven
  • Location:Rotterdam, NL

Posted 25 April 2008 - 05:49 PM

Hmm, you sure have some scripting potentials AgentLym, and thanks Joe for learning me a bit too.
Do you mind if I experiment with this script too? I don't think I'm going to use it in my quest, but just have a look at it.

#14 AgentLym

AgentLym

    • Zelda and Pokémon Master •

  • Members
  • Location:Skyloft

Posted 25 April 2008 - 05:52 PM

Thanks a bunches Joe123! You have been most helpful! Enjoy your holiday!

And I don't think the solidity properties change between the swords... I think the problem with the white sword is the reason why I can walk "diagonally" through the guard with the wooden sword. (well, I actually just switch directions quickly. Like I go up the guard while holding up and right. I hit the guard, go right for a split second, then go up "through" the guard for a split second, then go right for a split second, then go up right through the rest of the guard... Hm...)

If anyone has anything to add, I'd be grateful if you add it!

Thanks!

And no, TwilightKnight, I don't mind if you use the script! I don't know if Joe123 minds, though. But it's okay by me! icon_biggrin.gif

Edited by AgentLym, 25 April 2008 - 05:53 PM.


#15 AgentLym

AgentLym

    • Zelda and Pokémon Master •

  • Members
  • Location:Skyloft

Posted 26 April 2008 - 04:53 PM

Ok... It is still semi-working. The problem persists, though. If you don't know what the problem is, check above a few replies. icon_razz.gif

Here is the code again:
CODE
import "std.zh"

ffc script guard{
    void run(int left, int right){
    int i;
        while(true){
            if(Link->X <= this->X+16 && Link->X > this->X){                   \\Problem is here, I think...
                for(i=0;i<16;i++){
                    if(Link->Y == this->Y+i) Link->InputLeft = false;
                }
            }
            else if(Link->X >= this->X-16 && Link->X < this->X){             \\And if the problem's there, it's probably here, too...
                for(i=0;i<16;i++){
                    if(Link->Y == this->Y+i) Link->InputRight = false;
                }
            }
            else if(Link->Y >= this->Y-16 && Link->Y < this->Y){
                for(i=0;i<16;i++){
                    if(Link->X == this->X+i) Link->InputDown = false;
                }
            }
            else if(Link->Y <= this->Y+16 && Link->Y > this->Y){
                for(i=0;i<16;i++){
                    if(Link->X == this->X+i) Link->InputUp = false;
                }
            }
            if(Link->X > left && Link->X < right &&  !Link->Item[I_SWORD2]) this->X = Link->X;
        Waitframe();
        }
    }
}


Above, where I have stated the problems, if I change the ">" or "<" in the 7th and 12th line of the code to ">=" or "<=", respectively, Link can walk right through the guard. Is there any way to fix this problem? I know how the code works, and I understand it pretty well... I just can't find a solution to the problem. Can someone help me?

Edited by AgentLym, 26 April 2008 - 04:54 PM.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users