PDA

View Full Version : Trying to learn Zscript



Revfan9
12-12-2006, 01:35 AM
I have Zasm down, and I am trying to figure out Zscript so my scripts will be more professional, more flexible, etc. So as my first Zscript, I tried to convert my "Moonwalk (Link walks backwards)" script from Zasm to Zscript... Here is what I have.


ffc script Link_Moonwalks
{
void run()
{
while (true)
{
if (Link->InputUp)
Link->Y+=2;
if (Link->InputDown)
Link->Y-=2;
if (Link->InputRight)
Link->X-=2;
if (Link->InputLeft)
Link->X+=2;
void Waitframe()
}
}
}

By everything I have read up on Zscript, it should work fine. However, it doesn't compile. However, my Zasm version worked fine:


SETR d0,linkx
SETR d1,linky
WAIT WAITFRAME
COMPAREV INPUTUP,1
GOTOFALSE A
SETR linky,d1
ADDV linky,2
SETR d1,linky
A COMPAREV INPUTDOWN,1
GOTOFALSE B
SETR linky,d1
SUBV linky,2
SETR d1,linky
B COMPAREV INPUTLEFT,1
GOTOFALSE C
SETR linkx,d0
ADDV linkx,2
SETR d0,linkx
C COMPAREV INPUTRIGHT,1
GOTOFALSE WAIT
SETR linkx,d0
SUBV linkx,2
SETR d0,linkx
GOTO WAIT
QUIT

What did I do wrong? A theory of mine is that I used a different method in the Zasm script (cancel input, then go the other way) and in the Zscript version I just had Link move backwards right on the button press.

But what mystifies me most of all is that it gets an error on void Waitframe().

Saffith
12-12-2006, 02:06 AM
Change void Waitframe(); to just Waitframe();. It should work then.
You only need the "void" when you're defining the function, not when you're just calling it.

ShadowTiger
01-05-2007, 10:36 PM
... and while we're practicing, ..


ffc script increasehealth
{
void run()
{
While(True)
{
If(Link->InputR)
{
Link->HP += 16;
Waitframe();
}
}
Waitframe();
}
}This code, hopefully, should give Link an extra 16 HP whenever you press R. I'm not checking it for validity in terms of maximum health or anything, as that would come later. It's just not validating though. What am I doing wrong?

jman2050
01-05-2007, 11:06 PM
Move the first Waitframe from inside the Link->InputR loop to outside of it. It should work fine then.


ffc script increasehealth
{
void run()
{
While(True)
{
If(Link->InputR)
{
Link->HP += 16;
}
Waitframe();
}
Waitframe();
}
}

ShadowTiger
01-05-2007, 11:13 PM
Thanks, but copying/pasting this code doesn't mean it'll compile. It doesn't... ... The error is on line 6. Unexpected LBrace, expected semicolon.

Why? :odd:

jman2050
01-05-2007, 11:22 PM
True shouldn't be capitalized.