Jump to content

Photo

Learning Zscript


  • Please log in to reply
20 replies to this topic

#1 lucas92

lucas92

    Defender

  • Members

Posted 23 July 2008 - 06:17 PM

I've seen some amazing scripts out there and it made me wish to learn Zscript. But there's one question:

How did you learn Zscript? Did you start learning other high-level languages before learning it, (such as C++, Visual Basic.Net, C#, etc.) or you started learning it right away?

Right now, I'm learning the basics of programming languages with Visual Basic.Net since it seems to be easier than C++, even though Zscript looks a lot more like C++. icon_wacky.gif

Give your thoughts. icon_smile.gif

#2 Russ

Russ

    Caelan, the Encouraging

  • Administrators
  • Location:Washington

Posted 23 July 2008 - 07:07 PM

Zscript is basically C++, with some features taken in, and hard coded values added. I learned Zscript by first learning the C++ basics, and then looking at some other scripts to get the hang of it. Although there are some good tutorials out there.

#3 Beefster

Beefster

    Human Being

  • Members
  • Real Name:Justin
  • Location:Colorado

Posted 23 July 2008 - 09:50 PM

I knew the basics of Java, Euphoria, and TI-BASIC before I learned ZScript.

#4 Joe123

Joe123

    Retired

  • Members

Posted 24 July 2008 - 09:05 AM

The only language I know is ZScript (well, and HTML), I never learnt C++ or anything.
I just learnt from reading other people's scripts and asking lots of questions really.

#5 lucas92

lucas92

    Defender

  • Members

Posted 24 July 2008 - 06:37 PM

Talking of learning Zscript, I tried to make appear a block of 4 tiles on layer 3:

import "DRAWTILETEST.z"
ffc script Link_Portrait{
void DrawTile(int layer, int x, int y, int tile, int blockw, int blockh, int cset, int opacity){

int tile=12480; //ID of the desired top left corner tile
int blockw=4; //Width of the block of tiles
int blockh=4; //Height of the block of tiles
int cset=6; //cset of the tile duh
int opacity=128; //solid
int layer=3; //appears on layer 3
}
}

But it doesn't work? Why?

#6 Xiion

Xiion

    Senior

  • Members

Posted 24 July 2008 - 09:55 PM

I've picked up a fair amount of programming over the years... bit of machine, some C, some C++, Fortran, Matlab, Labview (in some lose sense, its not really a language, but it is programming) And over the course of learning those, I've picked up a few things. There are 3 things you need to know to be able to learn/use a [programming] language: You need to know the grammar(structure), you need to know a few basic words (commands), and you need to know where to look the rest of the words up (compendium). If you have those 3, you're pretty well off. Though, having 4: someone to ask questions, never hurts.


As for this...
QUOTE
Talking of learning Zscript, I tried to make appear a block of 4 tiles on layer 3:

import "DRAWTILETEST.z"
ffc script Link_Portrait{
void DrawTile(int layer, int x, int y, int tile, int blockw, int blockh, int cset, int opacity){

int tile=12480; //ID of the desired top left corner tile
int blockw=4; //Width of the block of tiles
int blockh=4; //Height of the block of tiles
int cset=6; //cset of the tile duh
int opacity=128; //solid
int layer=3; //appears on layer 3
}
}

But it doesn't work? Why?



Theres a couple other parts to the Drawtile function... see http://www.shardstor...creen_(ZScript)
The drawtile function should be set up something like this (the labels for each value are in brackets):

CODE
Screen->DrawTile([layer], [x position], [y position], [tile], [width], [height], [cset], 1,0,0,0,0,[transparency],[opacity]);


So your script should probably look something like this:
CODE
ffc script link_portrait
{
void run (int layer, int xpos, int ypos, int tile, int width, int height, int cset) //these values get defined in the ffc arguments
{  
int transparency;
in opacity=128;
Screen->Drawtile(layer, xpos, ypos, tile, width, height, cset, 1,0,0,0,0,transparency, opacity);
Waitframe(); //don't forget the waitframe!
}
}

This should work (I haven't debugged it, so it might not. I tend to make more than a few typos while coding) But theres one more catch to know about drawtile. It only lasts one frame. If you want it to last longer, you can put the Screen->Drawtile(...) and the Waitframe() within a while loop. You probably don't need to define all of the drawtile parameters as arguments either, it just means theres more arguments to input in the ffc setup. Values that are likely to be constant can be put directly into the drawtile function.

Hope that helps! If you want to look at a working script that uses drawtile, my lantern script uses them extensively, and can be found here: http://www.purezc.co...showtopic=36686 Granted, thats probably a bit complicated for an example, but still.

Edited by Xiion, 24 July 2008 - 10:22 PM.


#7 Joe123

Joe123

    Retired

  • Members

Posted 25 July 2008 - 07:36 AM

You don't need Waitframe if you don't have a while loop Xiion.

#8 lucas92

lucas92

    Defender

  • Members

Posted 25 July 2008 - 08:39 AM

Wow, thanks for the help! It was little dumb from my part to forget the screen->Drawtile instruction. icon_razz.gif

Oh, the Drawtile wasn't a void? icon_dead.gif



#9 Joe123

Joe123

    Retired

  • Members

Posted 25 July 2008 - 08:55 AM

Drawtile is a void.
It's a void, because it doesn't return anything, and it's in the 'Screen' section, so it uses the 'Screen->' pointer.

On a side note, all scripts must have 'void run(){' in them.

Edited by Joe123, 25 July 2008 - 08:56 AM.


#10 lucas92

lucas92

    Defender

  • Members

Posted 25 July 2008 - 09:45 AM

I've tried to do that script but with a loop function but didn't worked...

import "DRAWTILETEST.z"

ffc script link_portrait
{
void run (int layer, int opacity, int tansparency, int xpos, int ypos, int tile, int width, int height, int cset, int delay_frames) //these values get defined in the ffc arguments
{
int delay_frames=0;
int opacity=128;
int transparency=64;
while (delay_frames<60)
{
Screen->Drawtile(3, 0, 0, 12480, 4, 4, 6, 1,0,0,0,0,transparency, opacity);
int delay_frames=int delay_frames++;
Waitframe(); //don't forget the waitframe!
}
}
}


There is supposed to be an error on the highlighted one.

Edited by lucas92, 25 July 2008 - 09:47 AM.


#11 Joe123

Joe123

    Retired

  • Members

Posted 25 July 2008 - 10:13 AM

Right.
Let's have a look at this:

CODE
int delay_frames=int delay_frames++;

So you want to increase delay_frames by one, yes?

Well, your first problem is that you've already declared delay_fames, and now you're declaring it again.

CODE
int delay_frames = 0;

This line 'declares' delay_frames, so that you can then use it in your script.
CODE
delay_frames = 5;

This line now uses the already declared integer, 'delay_frames', and sets its value to 5.

So when you're declaring an integer, you put 'int' at the beginning. When you're using it, you don't.

Next problem is what you're doing.
Firstly, let's take your line and remove the 'int's from it...
CODE
delay_frames = delay_frames++;

Now, you have two assignment operators in one statement.
That's bad.
Don't do that.

'=' <- this means 'is set to'.
So 'x = 5;' means 'set the value of x to five'.

'++' <- this means 'increment'.
So 'x++;' means 'increase the value of x by one'.


As you can see, either of those statements can be used to achieve what you're trying to do, but not both at the same time.
There is also another, which is:

'+=' <- this is the 'additive assignment operator'.
So, 'x += 5;' means 'take the value of x, and add 5 to it. Then set x to the new number'.


Any of these following three lines could be used in place of what you have:
CODE
delay_frames = delay_frames + 1;
delay_frames += 1;
delay_frames++;


Obviously the last one is the shortest, so that'd be the one I'd use personally.


If you replace the line that won't compile with any of those three lines, your script will work as intended.
Firstly though, when you're writing scripts up on the forums, you should put '[ code ]' at the beginning and '[/ code ]' (without the spaces or quotation marks) at the end. That'll put your script into code tags, which means it'll be spaced out properly for other people to read, rather than flat out and hard to decipher like yours currently are.

Secondly, if I were writting your script, I wouldn't do it like that.
I'd use a 'for' loop.
'for' is a temporary loop, and this is the sort of thing it can be quite useful for.

CODE
ffc script link_portrait{
    void run (int layer, int xpos, int ypos, int tile, int width, int height, int cset){
    int transparency;
    int opacity = 128;
    int i;
        for(i=0;i<60;i++){
            Screen->Drawtile(layer, xpos, ypos, tile, width, height, cset, 1,0,0,0,0,transparency, opacity);
        Waitframe();
        }
    }
}


So I'd do it like that.
I'll let you try work that one out for yourself.


And finally, what is the purpose of this 'import "DRAWTILETEST.z"' line?


EDIT: Also, I'd like to commend you for starting off simple without being told to do so =P
There are so many people that think they can start off by trying to script custom bosses *sigh*

Edited by Joe123, 25 July 2008 - 10:22 AM.


#12 lucas92

lucas92

    Defender

  • Members

Posted 25 July 2008 - 10:43 AM

No purpose. icon_razz.gif

Anyway, I've tried your code, but here's what it give me:

IPB Image

I'm working with the build 846 on Windows...

Oh, and the code:

CODE
ffc script link_portrait{
    void run (int layer, int xpos, int ypos, int tile, int width, int height, int cset){
    int transparency;
    int opacity = 128;
    int i;
        for(i=0;i<60;i++){
            Screen->Drawtile(3, 0, 0, 12480, 4, 4, 3, 1,0,0,0,0,transparency, 128);
        Waitframe();
        }
    }
}


Hard to make work a simple script. lol
Oh, and you've made me understood that "for" loop, didn't caught it out before. icon_smile.gif

#13 Joe123

Joe123

    Retired

  • Members

Posted 25 July 2008 - 11:29 AM

Oh.
I just copied that function from Xiion's script =P

The function is specifically 'DrawTile', not 'Drawtile'.
The compiler is case sensitive.
It needs a capital T.

The for loop is a temporary loop.
What it does is:
Takes an integer (in this case, i), sets it to a starting value (in this case, 0), continues to loop what's in the curly braces after it until a certain condition is met (in this case, until i is greater than 60), and increases or decreases the integer by a certain amount each time (in this case, increasing i by one each time, using the increment function).

And in that way, it creates a loop which will last only 60 times.

#14 lucas92

lucas92

    Defender

  • Members

Posted 25 July 2008 - 12:21 PM

It works. icon_smile.gif

That's awesome! Thanks for this! Xiion, you also helped me a lot. Thanks for the quick and helpful help everyone. icon_smile.gif

#15 Xiion

Xiion

    Senior

  • Members

Posted 25 July 2008 - 03:25 PM

Heh, no problem...
I'm still learning zscript myself, and tend to make errors like that.

And you don't need Waitframe() for a while loop? I suppose... Hmm I'll have to try that out. Learn something new everyday.... Thanks Joe.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users