Jump to content

Photo

Basic scripting tutorial (WIP)


  • Please log in to reply
66 replies to this topic

#31 lucas92

lucas92

    Defender

  • Members

Posted 26 October 2008 - 01:07 PM

QUOTE(ShadowTiger @ Oct 25 2008, 10:28 AM) View Post

Even writing the most basic of scripts will get you on your path to success, because it'll give you the experience necessary to know what works and what doesn't.


Quoted. icon_razz.gif

#32 Fox

Fox

    Will the Hero rise again?

  • Members
  • Real Name:Scott
  • Location:Southern California

Posted 26 October 2008 - 02:26 PM

QUOTE(Saffith @ Oct 17 2008, 11:35 PM) View Post

You assign a variable the result of an arithmetic operation the same way as before.
CODE
Link->HP = Link->HP + 8; // Add 8 to Link's current HP
Link->MP = Link->MaxMP / 2; // Set Link's MP to 50% of the max
this->X = 16 * ((5 + 2) / 7); // Set the FFC's X position to 16 - there's no reason to do it this way, but you can
Link->HP + Link->MP = 16; // ERROR: The compiler can't figure this out - arithmetic has to go on the right side of the equals sign

// You can make both numbers and variables negative. To make a variable negative, put the minus before the pointer.
Link->X = Link->X + -16; // Reduce Link's HP by adding -16 HP
this->Vx = -this->Vx; // Reverse the FFC's X movement by negating its velocity

Small mistake in the second to last line of code: You're adjusting Link's position, but your comments say you're adjusting his HP. This is found under the "Arithmatic" section.
QUOTE(Saffith @ Oct 21 2008, 04:46 PM) View Post
In some cases, it's obvious what number to use for the index. In Game->LKeys[], for instance, the index corresponds to the level number. Other times, though, the index is arbitrary. Each element of this->Flags[] represents one of the FFC's flags, but you couldn't guess which index goes to which flag. Fortunately, std.zh defines lots of constants for exactly this reason. Just look at zscript.txt to see which set of constants to use for a given array.
CODE
Link->Item[I_SWORD2] = true; // Give Link the White Sword
this->Flags[FFCF_TRANS] = true; // Make the FFC transparent
Screen->Door[DIR_UP] = D_UNLOCK; // Unlock the door at the top of the screen
Game->Generic[GEN_HEARTPIECES] += 1; // Give Link an HPC

In the last line of code, the comment says you're giving Link an HPC. Shouldn't that be HCP?

Other than these tiny nitpicks, this is a very good tutorial. I suppose one thing you could add is scripting exercises. Some people might not be overflowing with ideas for what kinds of scripts they should start with. I have a feeling some people want to start off by scripting some crazy boss with different attack patterns based on what the player does. This is obviously way too complicated for a first script, but people might not be able to come up with anything small to work on. So maybe you could give some sample script suggestions at the end of each section for people to try to write themselves, then show how to write these scripts at the end of the tutorial. For example, people could try to write a script that gives Link an extra bomb for every heart they're missing from their maximum HP, or change the solidity of the combo to Link's immediate left to solid. More examples are always good, and when people can work on these examples, even if they have to think about them for a bit or look up information, they can learn a lot. So sample exercises can really encourage people to learn on their own.

#33 Saffith

Saffith

    IPv7 user

  • Members

Posted 26 October 2008 - 03:12 PM

QUOTE(Fox @ Oct 26 2008, 03:26 PM) View Post

Small mistake in the second to last line of code: You're adjusting Link's position, but your comments say you're adjusting his HP. This is found under the "Arithmatic" section.

In the last line of code, the comment says you're giving Link an HPC. Shouldn't that be HCP?
Both fixed, thanks.

QUOTE
I suppose one thing you could add is scripting exercises. Some people might not be overflowing with ideas for what kinds of scripts they should start with.

Definitely a good idea. I'll add some of those.

If anyone has more suggestions as to what would make good exercises (or examples, for that matter), then by all means, let me know.


#34 lucas92

lucas92

    Defender

  • Members

Posted 26 October 2008 - 03:36 PM

Making a growing circle, or making an ffc solid are good exercises...

#35 Saffith

Saffith

    IPv7 user

  • Members

Posted 08 November 2008 - 11:39 PM

Gah, sorry. Life got a bit hectic, and this sort of fell by the wayside. Anyway, I got some of those in. No answers yet, though.

QUOTE(lucas92 @ Oct 26 2008, 03:36 PM) View Post

Making a growing circle, or making an ffc solid are good exercises...

Those would require loops, which haven't been covered yet.

#36 Saffith

Saffith

    IPv7 user

  • Members

Posted 24 November 2008 - 06:38 PM

I do still intend to finish this... icon_razz.gif
Added in answers in spoiler tags and updated the list of std.zh functions. The character limit point moved up.

Any more suggestions? I think this should be almost finished now.

Still, I think I'll wait at least until these are all written to submit them. Might want to reorganize and add to them at the end.

Edited by Saffith, 30 November 2008 - 03:14 PM.


#37 Christian

Christian

    Summoner

  • Members
  • Real Name:Chris
  • Location:New Jersey

Posted 02 December 2008 - 02:42 PM

I just made this small ffc script
CODE
ffc script hotplace{ voidrun(int item){ if(Link->Item[item]){ Link->HP=HP;} else if(!Link->Item[item]){ Waitframes(120); Link->HP-=1 } } }
now. Havnt tested it yet. But will that work though? I dont need to explain what it does. Its obvious ^_^.

#38 lucas92

lucas92

    Defender

  • Members

Posted 02 December 2008 - 05:10 PM

Well, even if Link has the item, he can takes damage, right?

Instead of Link->HP=HP;, just Quit();. That should work. But you should make your scripts cleaner because it's hard to read them. Use the amount of white space you want, it doesn't matter. Just make it clear to the user. icon_smile.gif

#39 Saffith

Saffith

    IPv7 user

  • Members

Posted 02 December 2008 - 07:48 PM

QUOTE(drzchulo973 @ Dec 2 2008, 02:42 PM) View Post

I just made this small ffc script
CODE
ffc script hotplace{ voidrun(int item){ if(Link->Item[item]){ Link->HP=HP;} else if(!Link->Item[item]){ Waitframes(120); Link->HP-=1 } } }
now. Havnt tested it yet. But will that work though? I dont need to explain what it does. Its obvious ^_^.

There are three minor mistakes that'll keep it from compiling. There's no space between void and run. Link->HP=HP would need to be Link->HP=Link->HP, although Quit() would make more sense, as lucas92 mentioned. Also, you forgot the semicolon after Link->HP-=1.
The only logical error is that it needs a loop; otherwise, it'll just drain 1 HP and quit running.
I like the idea, though. Maybe I'll use that one for a practice exercise. icon_razz.gif

#40 lucas92

lucas92

    Defender

  • Members

Posted 02 December 2008 - 08:17 PM

How did I forget that! icon_razz.gif

Yeah, it needs a loop.

#41 Christian

Christian

    Summoner

  • Members
  • Real Name:Chris
  • Location:New Jersey

Posted 02 December 2008 - 09:33 PM

Oh yea! It needs the
CODE
while(true){
to run continuously for the entire screen right? And then add the
CODE
Waitframe();

to end the while loop in the script. icon_razz.gif i never knew scripting would be so simple. Oh and yeah it can be used as a exercise example icon_smile.gif

Here,I tried to clean it up
CODE

ffc script Hot_place{//script name
         void run(int item){//D0 item
              while(true){//loop started,iftrue
    if(Link->Item[item]){//if he has the item
              Link->HP = Link->HP;
       }
         else if(!Link->Item[item]){
                Waitframes(120);
              Link->HP-=1;
                   Waitframe();
           }
      }
}



Edited by drzchulo973, 03 December 2008 - 12:38 AM.


#42 lucas92

lucas92

    Defender

  • Members

Posted 02 December 2008 - 09:48 PM

Waitframe(); is not to end the loop. It's there to make it wait at least one frame before looping again. Unless it would loop so fast that it would freeze Zelda Classic.

#43 Christian

Christian

    Summoner

  • Members
  • Real Name:Chris
  • Location:New Jersey

Posted 03 December 2008 - 01:17 AM

Here is another script I made, its a scripted chest that requires to press A for it to open ,freezes the screen, and then plays the open chest sound, draws the item tile , plays the item fanfare sfx , plays a message, and then the drawtile disappears and so on...I think I made a couple mistakes with this one ,as I don't know if you can do this with chests using ComboD, maybe you can using ComboT.well here it goes, note that I tried to make it in the best of my knowledge.
CODE

//constants//
Const int SFX_OPENCHEST = 0;
Const int SFX_ITEMFANFARE = 0;
Const int T_ITEMTILE = 0;
Const int S_GETITEM = 0;

ffc script Chest{
    void run(int chestlock, int chestunlock, int item){  
     int chest = ComboAt(this->X,this->Y);
     int unloc = Screen->ComboD[chest];
     int x = 0;
     int y = 0;
   while(Screen->ComboD[chest] ==    chestlock){
      if(Link->Dir == 0 && Link->InputA)
        Waitframe();
      int freeze = Screen->ComboT[0];
    Screen->ComboT = CT_SCREENFREEZE;
   Game->PlaySound(SFX_OPENCHEST);
       Waitframes(2);
    Screen->ComboD[chest] == chestunlock;
    Screen->Drawtile(1,x,y,T_ITEMTILE,1,0,0,0,0,true,128);
     Game->PlaySound(SFX_ITEMFANFARE);
   Screen->ComboT[0] = freeze;
    Screen->Message(S_GETITEM);
    Screen->Drawtile(1,x,y,T_ITEMTILE,1,0,0,0,0,false,128);
        }
    }
}

There it is , yea I know I have errors and such, can someone be able to point it out or something? If so, I have a feeling it has something to do with the drawtiles , and freezing the combo type and the screen. Anyone is welcome to make this better.

And yea I know, its a bit advanced for the basic tutorial and such icon_razz.gif

Edited by drzchulo973, 03 December 2008 - 01:21 AM.


#44 Saffith

Saffith

    IPv7 user

  • Members

Posted 03 December 2008 - 10:28 PM

QUOTE(drzchulo973 @ Dec 3 2008, 01:17 AM) View Post
I think I made a couple mistakes with this one ,as I don't know if you can do this with chests using ComboD, maybe you can using ComboT.

Working with ComboT is risky. You can't just change one tile; it'll affect the same combo everywhere it appears in the quest. It may be only temporary, but if the player hits F6 while it's changed, it could cause trouble.

Only minor syntactical errors. Don't capitalize const, you wrote to ComboT instead of ComboT[0] once, and it should be DrawTile() instead of Drawtile(). Aside from that, it looks like it'll compile, assuming you're importing std.zh.
It won't quite work, though. You're not checking Link's position, and that if is only covering that one Waitframe(). You probably want something like this:
CODE
while(Screen->ComboD[chest]==chestlock)
{
    if(Link->X==this->X && Link->Y==this->Y+16 && Link->Dir==0 && Link->InputA)
    {
        // Open chest
    }
    Waitframe();
}

That's the simplest way of checking his position, though, which won't work if he's even half a pixel from the right spot.
Also, you never actually give Link the item.

You're doing well, though. Keep it up.

#45 Christian

Christian

    Summoner

  • Members
  • Real Name:Chris
  • Location:New Jersey

Posted 04 December 2008 - 08:14 AM

Hmmmm how would it work though do i need to put
CODE
Link->HeldItem[item] || Screen->CreateItem[item]
write that in? Oh and the logical or is replacing the word or foreal. There not connected icon_razz.gif


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users