Learning Zscript
#1
Posted 23 July 2008 - 06:17 PM
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++.
Give your thoughts.
#2
Posted 23 July 2008 - 07:07 PM
#3
Posted 23 July 2008 - 09:50 PM
#4
Posted 24 July 2008 - 09:05 AM
I just learnt from reading other people's scripts and asking lots of questions really.
#5
Posted 24 July 2008 - 06:37 PM
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
Posted 24 July 2008 - 09:55 PM
As for this...
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):
So your script should probably look something like this:
{
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
Posted 25 July 2008 - 07:36 AM
#8
Posted 25 July 2008 - 08:39 AM
Oh, the Drawtile wasn't a void?
#9
Posted 25 July 2008 - 08:55 AM
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
Posted 25 July 2008 - 09:45 AM
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
Posted 25 July 2008 - 10:13 AM
Let's have a look at this:
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.
This line 'declares' delay_frames, so that you can then use it in your script.
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...
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:
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.
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
Posted 25 July 2008 - 10:43 AM
Anyway, I've tried your code, but here's what it give me:
I'm working with the build 846 on Windows...
Oh, and the code:
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.
#13
Posted 25 July 2008 - 11:29 AM
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
Posted 25 July 2008 - 12:21 PM
That's awesome! Thanks for this! Xiion, you also helped me a lot. Thanks for the quick and helpful help everyone.
#15
Posted 25 July 2008 - 03:25 PM
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